after a big rewrite and tons of new features, rc1 for 0.3
This commit is contained in:
parent
b2dbf53fd1
commit
4f457764eb
2
.gitignore
vendored
2
.gitignore
vendored
@ -1 +1,3 @@
|
||||
target
|
||||
test-server
|
||||
bin
|
||||
|
137
pom.xml
137
pom.xml
@ -4,23 +4,46 @@
|
||||
<groupId>us.camin.regions</groupId>
|
||||
<artifactId>Regions</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>0.1</version>
|
||||
<name>bukkitplugin</name>
|
||||
<version>0.2.99-rc1</version>
|
||||
<name>regions</name>
|
||||
<url>http://maven.apache.org</url>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.6.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.gmail.filoghost.holographicdisplays</groupId>
|
||||
<artifactId>holographicdisplays-api</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc</groupId>
|
||||
<artifactId>paperlib</artifactId>
|
||||
<version>1.0.6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bukkit</groupId>
|
||||
<artifactId>bukkit</artifactId>
|
||||
<version>1.2.2-R0.1-SNAPSHOT</version>
|
||||
<groupId>com.destroystokyo.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.16.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.jdiemke.delaunay-triangulator</groupId>
|
||||
<artifactId>DelaunayTriangulator</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.dynmap</groupId>
|
||||
<artifactId>DynmapCoreAPI</artifactId>
|
||||
<version>0.38</version>
|
||||
<version>2.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
@ -35,6 +58,13 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<extensions>
|
||||
<extension>
|
||||
<groupId>org.apache.maven.wagon</groupId>
|
||||
<artifactId>wagon-ssh-external</artifactId>
|
||||
<version>1.0-beta-6</version>
|
||||
</extension>
|
||||
</extensions>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
@ -45,17 +75,104 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>1.6</source>
|
||||
<target>1.6</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.1.1</version>
|
||||
<configuration>
|
||||
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>io.papermc.lib</pattern>
|
||||
<shadedPattern>us.camin.regions.paperlib</shadedPattern> <!-- Replace this -->
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<versionRange>[1.0.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>compile</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<versionRange>[1.0.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<versionRange>[1.0.0,)</versionRange>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<execute />
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/repository/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-repo</id>
|
||||
<url>https://repo.codemc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>bukkit-repo</id>
|
||||
<url>http://repo.bukkit.org/service/local/repositories/snapshots/content/</url>
|
||||
<id>papermc</id>
|
||||
<url>http://papermc.io/repo/repository/maven-public/</url>
|
||||
</repository>
|
||||
<repository><id>dynmap-repo</id><url>http://repo.mikeprimm.com/</url></repository>
|
||||
<repository><id>imagej</id><url>http://maven.imagej.net/content/repositories/public/</url></repository>
|
||||
</repositories>
|
||||
</project>
|
||||
|
@ -1,69 +0,0 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class BukkitEventHandler implements Listener {
|
||||
RegionManager m_manager;
|
||||
public BukkitEventHandler(RegionManager manager) {
|
||||
m_manager = manager;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
m_manager.recalculatePlayerRegions();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
m_manager.recalculatePlayerRegions();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
m_manager.recalculatePlayerRegions();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
m_manager.recalculatePlayerRegions();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRegionChanged(PlayerRegionChangeEvent event) {
|
||||
if (event.oldRegion != null) {
|
||||
for (Player p : m_manager.playersInRegion(event.oldRegion)) {
|
||||
p.sendMessage(event.player.getName()+" has left the region.");
|
||||
}
|
||||
}
|
||||
for (Player p : m_manager.playersInRegion(event.newRegion)) {
|
||||
if (p != event.player) {
|
||||
p.sendMessage(event.player.getName()+" has entered the region.");
|
||||
}
|
||||
}
|
||||
event.player.sendMessage("Now entering region: "+event.newRegion.name());
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class CityRegionCommand implements CommandExecutor {
|
||||
|
||||
Plugin m_plugin;
|
||||
|
||||
public CityRegionCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Region command is only available to players.");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
Region city = m_plugin.regionManager().cityRegion(p.getLocation().getWorld().getName());
|
||||
Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (city != null) {
|
||||
if (p.getLocation().distance(nearest.teleportLocation()) <= 5) {
|
||||
p.teleport(city.teleportLocation(), TeleportCause.COMMAND);
|
||||
} else {
|
||||
sender.sendMessage("You must be within 5 blocks of a region center.");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("There is no city region defined.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -21,30 +21,123 @@ package us.camin.regions;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.dynmap.markers.MarkerSet;
|
||||
import org.dynmap.markers.MarkerIcon;
|
||||
import org.dynmap.markers.AreaMarker;
|
||||
import org.dynmap.markers.GenericMarker;
|
||||
import org.dynmap.markers.PolyLineMarker;
|
||||
import org.dynmap.markers.CircleMarker;
|
||||
import org.dynmap.markers.MarkerAPI;
|
||||
import org.dynmap.markers.Marker;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
||||
import us.camin.regions.events.RegionCreateEvent;
|
||||
import us.camin.regions.events.RegionRemoveEvent;
|
||||
import us.camin.regions.geometry.BorderMesh;
|
||||
import us.camin.regions.geometry.RegionSet;
|
||||
import us.camin.regions.ui.Colors;
|
||||
|
||||
public class DynmapEventRelay implements Listener {
|
||||
private MarkerSet m_set;
|
||||
Logger log = Logger.getLogger("Regions.DynmapEventRelay");
|
||||
private MarkerSet m_borderSet;
|
||||
private MarkerSet m_centerSet;
|
||||
private MarkerSet m_routesSet;
|
||||
private MarkerAPI m_api;
|
||||
private Map<World, List<GenericMarker>> m_borderMarkers;
|
||||
Plugin m_plugin;
|
||||
|
||||
public DynmapEventRelay(MarkerAPI markerAPI) {
|
||||
public DynmapEventRelay(Plugin plugin, MarkerAPI markerAPI) {
|
||||
m_plugin = plugin;
|
||||
m_api = markerAPI;
|
||||
m_set = m_api.createMarkerSet("Regions", "Regions", null, false);
|
||||
m_centerSet = m_api.createMarkerSet("region-centers", "Region Posts", null, false);
|
||||
m_borderSet = m_api.createMarkerSet("region-borders", "Region Borders", null, false);
|
||||
m_routesSet = m_api.createMarkerSet("region-routes", "Region Routes", null, false);
|
||||
m_borderSet.setHideByDefault(true);
|
||||
m_routesSet.setHideByDefault(true);
|
||||
m_borderMarkers = new HashMap<World, List<GenericMarker>>();
|
||||
|
||||
for(World world : plugin.getServer().getWorlds()) {
|
||||
Collection<Region> regions = m_plugin.regionManager().regionsForWorld(world);
|
||||
for (Region region : regions) {
|
||||
createMarkerForRegion(region);
|
||||
}
|
||||
updatePolygons(world);
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePolygons(World world) {
|
||||
List<GenericMarker> oldMarkers = m_borderMarkers.get(world);
|
||||
if (oldMarkers != null) {
|
||||
for(GenericMarker marker : oldMarkers) {
|
||||
marker.deleteMarker();
|
||||
}
|
||||
} else {
|
||||
m_borderMarkers.put(world, new ArrayList<GenericMarker>());
|
||||
}
|
||||
log.info("Triangulating mesh for world...");
|
||||
|
||||
RegionSet regions = m_plugin.regionManager().regionsForWorld(world);
|
||||
BorderMesh geom = regions.borders();
|
||||
|
||||
for(Region region : regions) {
|
||||
BorderMesh.Polygon polygon = geom.polygonForRegion(region);
|
||||
if (polygon == null) {
|
||||
log.info("Could not generate polygon for region " + region.name());
|
||||
continue;
|
||||
}
|
||||
boolean isFrontier = geom.isFrontier(region);
|
||||
if (!isFrontier) {
|
||||
AreaMarker marker = m_borderSet.createAreaMarker(null, region.name(), false, world.getName(), polygon.x, polygon.z, false);
|
||||
marker.setFillStyle(0.7, region.color().getColor().asRGB());
|
||||
marker.setLineStyle(2, 0.8, region.color().getColor().asRGB());
|
||||
m_borderMarkers.get(world).add(marker);
|
||||
} else {
|
||||
PolyLineMarker marker = m_borderSet.createPolyLineMarker(null, region.name(), false, world.getName(), polygon.x, polygon.y, polygon.z, false);
|
||||
marker.setLineStyle(2, 0.5, region.color().getColor().asRGB());
|
||||
m_borderMarkers.get(world).add(marker);
|
||||
}
|
||||
|
||||
// Add a line between each region, for teleportations
|
||||
double thickness = Math.max(1, Math.log(geom.neighbors(region).size()) * 2.75);
|
||||
for(Region neighbor : geom.neighbors(region)) {
|
||||
double x[] = { neighbor.location().getBlockX(), region.location().getBlockX() };
|
||||
double y[] = { 64, 64 };
|
||||
double z[] = { neighbor.location().getBlockZ(), region.location().getBlockZ() };
|
||||
PolyLineMarker marker = m_routesSet.createPolyLineMarker(null, null, false, world.getName(), x, y, z, false);
|
||||
marker.setLineStyle((int)Math.ceil(thickness), 0.5, region.color().getColor().asRGB());
|
||||
m_borderMarkers.get(world).add(marker);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createMarkerForRegion(Region region) {
|
||||
Location loc = region.location();
|
||||
MarkerIcon icon = m_api.getMarkerIcon("compass");
|
||||
CircleMarker circleMarker = m_routesSet.createCircleMarker(null, region.name(), false, loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), 60, 60, false);
|
||||
Marker marker = m_centerSet.createMarker(null, region.name(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), icon, false);
|
||||
circleMarker.setFillStyle(0.75, region.color().getColor().asRGB());
|
||||
circleMarker.setLineStyle(0, 0, 0);
|
||||
String desc = "<h2>" + region.name() + "</h2>";
|
||||
marker.setDescription(desc);
|
||||
circleMarker.setDescription(desc);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionEvent(RegionRemoveEvent event) {
|
||||
Marker marker = m_set.findMarkerByLabel(event.region.name());
|
||||
Marker marker = m_centerSet.findMarkerByLabel(event.region.name());
|
||||
marker.deleteMarker();
|
||||
updatePolygons(event.region.location().getWorld());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionEvent(RegionCreateEvent event) {
|
||||
Location loc = event.region.location();
|
||||
MarkerIcon icon = m_api.getMarkerIcon("default");
|
||||
m_set.createMarker(null, event.region.name(), loc.getWorld().getName(), loc.getX(), loc.getY(), loc.getZ(), icon, false);
|
||||
createMarkerForRegion(event.region);
|
||||
updatePolygons(event.region.location().getWorld());
|
||||
}
|
||||
}
|
||||
|
@ -1,55 +0,0 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
|
||||
public class HomeRegionCommand implements CommandExecutor {
|
||||
|
||||
Plugin m_plugin;
|
||||
|
||||
public HomeRegionCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Region command is only available to players.");
|
||||
return true;
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
Region home = m_plugin.regionManager().homeRegion(p.getName());
|
||||
Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
|
||||
if (home != null) {
|
||||
if (p.getLocation().distance(nearest.teleportLocation()) <= 5) {
|
||||
p.teleport(home.teleportLocation(), TeleportCause.COMMAND);
|
||||
} else {
|
||||
sender.sendMessage("You must be within 5 blocks of a region center.");
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("You have no home region.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
179
src/main/java/us/camin/regions/PlayerNotifier.java
Normal file
179
src/main/java/us/camin/regions/PlayerNotifier.java
Normal file
@ -0,0 +1,179 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.TitleAction;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
|
||||
import com.destroystokyo.paper.Title;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import us.camin.regions.events.PlayerMoveInEvent;
|
||||
import us.camin.regions.events.PlayerNearRegionPostEvent;
|
||||
import us.camin.regions.events.PlayerRegionChangeEvent;
|
||||
import us.camin.regions.events.PlayerAddRegionChargeEvent;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class PlayerNotifier implements Listener {
|
||||
Logger log = Logger.getLogger("Regions.PlayerNotifier");
|
||||
RegionManager m_manager;
|
||||
Plugin m_plugin;
|
||||
public PlayerNotifier(Plugin plugin, RegionManager manager) {
|
||||
m_manager = manager;
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerRegionChanged(PlayerRegionChangeEvent event) {
|
||||
if (event.oldRegion != null) {
|
||||
for (Player p : m_plugin.playerWatcher().playersInRegion(event.oldRegion)) {
|
||||
p.sendMessage(event.player.getName()+" has left the region.");
|
||||
}
|
||||
}
|
||||
for (Player p : m_plugin.playerWatcher().playersInRegion(event.newRegion)) {
|
||||
if (p != event.player) {
|
||||
p.sendMessage(event.player.getName()+" has entered the region.");
|
||||
}
|
||||
}
|
||||
event.newRegion.addVisit();
|
||||
event.player.sendMessage("Now entering region: "+event.newRegion.coloredName());
|
||||
int pop = m_plugin.playerWatcher().playersInRegion(event.newRegion).size();
|
||||
Location center = event.newRegion.location();
|
||||
int altitude = center.getBlockY();
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
if (protocolManager != null) {
|
||||
PacketContainer chatMessage = protocolManager.createPacket(PacketType.Play.Server.TITLE);
|
||||
String colorHex = "#" + String.format("%06X", event.newRegion.color().getColor().asRGB());
|
||||
chatMessage.getChatComponents().write(0, WrappedChatComponent.fromJson("{text:\"" + event.newRegion.name() + "\", color: \""+colorHex+"\"}"));
|
||||
try {
|
||||
protocolManager.sendServerPacket(event.player, chatMessage);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
chatMessage = protocolManager.createPacket(PacketType.Play.Server.TITLE);
|
||||
chatMessage.getChatComponents().write(0, WrappedChatComponent.fromJson("{text:\"Population: " + pop + " Altitude: "+ altitude + "\", color: \"#ffffff\"}"));
|
||||
chatMessage.getTitleActions().write(0, TitleAction.SUBTITLE);
|
||||
try {
|
||||
protocolManager.sendServerPacket(event.player, chatMessage);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
chatMessage = protocolManager.createPacket(PacketType.Play.Server.TITLE);
|
||||
chatMessage.getChatComponents().write(0, WrappedChatComponent.fromJson("{text:\"Now entering " + event.newRegion.name() + "\", color: \""+colorHex+"\"}"));
|
||||
chatMessage.getTitleActions().write(0, TitleAction.ACTIONBAR);
|
||||
try {
|
||||
protocolManager.sendServerPacket(event.player, chatMessage);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else {
|
||||
Title title = new Title.Builder().title(event.newRegion.name()).subtitle("Population: "+pop+" Altitude: " + altitude).build();
|
||||
event.player.sendTitle(title);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerNear(PlayerNearRegionPostEvent event) {
|
||||
Collection<Region> nearby = m_manager.neighborsForRegion(event.region);
|
||||
StringBuilder nearbyText = new StringBuilder();
|
||||
if (event.region.markSeenByPlayer(event.player)) {
|
||||
event.player.playSound(event.region.location(), Sound.UI_TOAST_CHALLENGE_COMPLETE, (float)1, (float)1);
|
||||
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
|
||||
if (protocolManager != null) {
|
||||
PacketContainer chatMessage = protocolManager.createPacket(PacketType.Play.Server.TITLE);
|
||||
String colorHex = "#" + String.format("%06X", event.region.color().getColor().asRGB());
|
||||
chatMessage.getChatComponents().write(0, WrappedChatComponent.fromJson("{text:\"Region discovered\", color: \""+colorHex+"\"}"));
|
||||
try {
|
||||
protocolManager.sendServerPacket(event.player, chatMessage);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
chatMessage = protocolManager.createPacket(PacketType.Play.Server.TITLE);
|
||||
chatMessage.getChatComponents().write(0, WrappedChatComponent.fromJson("{text:\"You discovered the region " + event.region.name() + "\", color: \""+colorHex+"\"}"));
|
||||
chatMessage.getTitleActions().write(0, TitleAction.SUBTITLE);
|
||||
try {
|
||||
protocolManager.sendServerPacket(event.player, chatMessage);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
} else {
|
||||
//FIXME: also show pop/alt subtitle
|
||||
Title title = new Title.Builder().title("Region Discovered").subtitle(event.region.name()).build();
|
||||
event.player.sendMessage("You discovered the region " + event.region.name());
|
||||
event.player.sendTitle(title);
|
||||
}
|
||||
}
|
||||
for(Region region : nearby) {
|
||||
nearbyText.append(" ");
|
||||
nearbyText.append(region.coloredName());
|
||||
}
|
||||
|
||||
event.player.playSound(event.region.location(), Sound.BLOCK_STONE_PRESSURE_PLATE_CLICK_ON, (float)0.5, (float)0.6);
|
||||
event.player.sendMessage("Nearby regions:" + nearbyText.toString());
|
||||
|
||||
|
||||
World w = event.player.getLocation().getWorld();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
BukkitTask puffGenerator = scheduler.runTaskTimer(m_plugin, () -> {
|
||||
w.spawnParticle(Particle.REDSTONE, event.region.teleportLocation().add(0, -0.5, 0), 15, 0.1, 0.1, 0.1, event.region.dustOptions());
|
||||
}, 0, 15);
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
puffGenerator.cancel();
|
||||
}, 20 * 7);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerAddCharge(PlayerAddRegionChargeEvent event) {
|
||||
if (event.region.charges() == 1) {
|
||||
for (Player p : m_plugin.playerWatcher().playersInRegion(event.region)) {
|
||||
if (p != event.player) {
|
||||
p.sendMessage(event.player.getName()+" re-charged the region post.");
|
||||
}
|
||||
}
|
||||
}
|
||||
event.player.playSound(event.region.location(), Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, (float)0.5, (float)0.6);
|
||||
event.player.sendMessage("You re-charged the region post. It has " + event.region.charges() + " charges remaining.");
|
||||
event.player.getWorld().spawnParticle(Particle.REDSTONE, event.region.teleportLocation(), 100, 1, 1, 1, event.region.dustOptions());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMoveIn(PlayerMoveInEvent event) {
|
||||
/*RegionPostBuilder builder = new RegionPostBuilder(event.region);
|
||||
builder.fireworks();
|
||||
for (Player p : m_plugin.playerWatcher().playersInRegion(event.region)) {
|
||||
if (p != event.player) {
|
||||
p.sendMessage(event.player.getName()+" has moved in to the region.");
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
@ -18,16 +18,195 @@ package us.camin.regions;
|
||||
*
|
||||
*/
|
||||
|
||||
import java.lang.Runnable;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
import org.bukkit.event.player.PlayerChangedWorldEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.server.ServerLoadEvent;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.CompassMeta;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class PlayerWatcher implements Runnable {
|
||||
import us.camin.regions.events.PlayerNearRegionPostEvent;
|
||||
import us.camin.regions.events.PlayerPostInteractEvent;
|
||||
import us.camin.regions.events.PlayerRegionChangeEvent;
|
||||
import us.camin.regions.events.PlayerAddRegionChargeEvent;
|
||||
import us.camin.regions.events.RegionCreateEvent;
|
||||
import us.camin.regions.events.RegionRemoveEvent;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PlayerWatcher implements Listener {
|
||||
Logger log = Logger.getLogger("Regions.PlayerWatcher");
|
||||
private RegionManager m_manager;
|
||||
private Plugin m_plugin;
|
||||
private BukkitTask m_recalculateTask = null;
|
||||
private PlayerTracker m_tracker;
|
||||
|
||||
public PlayerWatcher(RegionManager manager) {
|
||||
private static int WATCH_INTERVAL = 3 * 20; // Every 3 seconds
|
||||
|
||||
public PlayerWatcher(Plugin plugin, RegionManager manager) {
|
||||
m_manager = manager;
|
||||
m_plugin = plugin;
|
||||
m_tracker = new PlayerTracker();
|
||||
}
|
||||
|
||||
public void run() {
|
||||
m_manager.recalculatePlayerRegions();
|
||||
private void recalculateAndReschedule() {
|
||||
if (m_recalculateTask != null) {
|
||||
m_recalculateTask.cancel();
|
||||
}
|
||||
m_tracker.recalculatePlayerRegions();
|
||||
m_recalculateTask = m_plugin.getServer().getScheduler().runTaskLater(m_plugin, () -> recalculateAndReschedule(), WATCH_INTERVAL);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onReload(ServerLoadEvent event) {
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onTeleport(PlayerTeleportEvent event) {
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(PlayerJoinEvent event) {
|
||||
recalculateAndReschedule();
|
||||
Region homeRegion = m_manager.homeRegion(event.getPlayer().getName());
|
||||
if (homeRegion != null) {
|
||||
//event.getPlayer().setSubtitle(TextComponent.fromLegacyText(homeRegion.coloredName()));
|
||||
//event.getPlayer().setCompassTarget(homeRegion.location());
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRespawn(PlayerRespawnEvent event) {
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onWorldChange(PlayerChangedWorldEvent event) {
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionCreate(RegionCreateEvent event) {
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionCreate(RegionRemoveEvent event) {
|
||||
m_tracker.forgetRegion(event.region);
|
||||
recalculateAndReschedule();
|
||||
}
|
||||
|
||||
public Collection<Player> playersInRegion(Region r) {
|
||||
return m_tracker.playersInRegion(r);
|
||||
}
|
||||
|
||||
public void recalculatePlayerRegions(boolean b) {
|
||||
m_tracker.recalculatePlayerRegions(b);
|
||||
}
|
||||
|
||||
public void clear() {
|
||||
m_tracker.clear();
|
||||
}
|
||||
|
||||
private class PlayerTracker {
|
||||
private Map<Region, Collection<Player>> m_regionPlayerLists;
|
||||
private Map<Player, Region> m_lastKnownRegions;
|
||||
|
||||
public PlayerTracker() {
|
||||
m_lastKnownRegions = new HashMap<Player, Region>();
|
||||
m_regionPlayerLists = new HashMap<Region, Collection<Player>>();
|
||||
}
|
||||
|
||||
public synchronized Collection<Player> playersInRegion(Region r) {
|
||||
if (m_regionPlayerLists.get(r) == null) {
|
||||
return Collections.unmodifiableCollection(new ArrayList<Player>());
|
||||
}
|
||||
return Collections.unmodifiableCollection(m_regionPlayerLists.get(r));
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
m_lastKnownRegions = new HashMap<Player, Region>();
|
||||
m_regionPlayerLists = new HashMap<Region, Collection<Player>>();
|
||||
}
|
||||
|
||||
public synchronized void forgetRegion(Region r) {
|
||||
m_regionPlayerLists.remove(r);
|
||||
}
|
||||
|
||||
public synchronized void recalculatePlayerRegions() {
|
||||
recalculatePlayerRegions(false);
|
||||
}
|
||||
|
||||
private HashMap<Player, Boolean> m_playerIsNearby = new HashMap<>();
|
||||
|
||||
public boolean playerIsNearby(Player p) {
|
||||
if (!m_playerIsNearby.containsKey(p)) {
|
||||
m_playerIsNearby.put(p, false);
|
||||
}
|
||||
return m_playerIsNearby.get(p);
|
||||
}
|
||||
|
||||
public synchronized void recalculatePlayerRegions(boolean quiet) {
|
||||
ArrayList<Event> updateEvents = new ArrayList<Event>();
|
||||
Collection<? extends Player> allPlayers = m_plugin.getServer().getOnlinePlayers();
|
||||
for (Player p : allPlayers) {
|
||||
Location loc = p.getLocation();
|
||||
Region nearest = m_manager.nearestRegion(loc);
|
||||
if (nearest != null) {
|
||||
log.finest("Current region for "+p.getName()+": "+nearest.name());
|
||||
Region last = m_lastKnownRegions.get(p);
|
||||
if (nearest != last) {
|
||||
log.fine("Player "+p.getName()+" entered region "+nearest.name());
|
||||
if (m_regionPlayerLists.get(nearest) == null) {
|
||||
m_regionPlayerLists.put(nearest, new ArrayList<Player>());
|
||||
}
|
||||
m_regionPlayerLists.get(nearest).add(p);
|
||||
if (m_regionPlayerLists.get(last) != null) {
|
||||
m_regionPlayerLists.get(last).remove(p);
|
||||
}
|
||||
m_lastKnownRegions.put(p, nearest);
|
||||
m_playerIsNearby.put(p, false);
|
||||
if (!quiet) {
|
||||
updateEvents.add(new PlayerRegionChangeEvent(p, last, nearest));
|
||||
}
|
||||
}
|
||||
boolean isNearby = loc.distance(nearest.location()) <= 10;
|
||||
if (!m_playerIsNearby.containsKey(p)) {
|
||||
m_playerIsNearby.put(p, isNearby);
|
||||
}
|
||||
if (isNearby != m_playerIsNearby.get(p)) {
|
||||
m_playerIsNearby.put(p, isNearby);
|
||||
if (isNearby && !quiet) {
|
||||
updateEvents.add(new PlayerNearRegionPostEvent(p, nearest));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Event e : updateEvents) {
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> m_plugin.getServer().getPluginManager().callEvent(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -19,112 +19,109 @@ package us.camin.regions;
|
||||
*/
|
||||
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.plugin.ServicePriority;
|
||||
import org.bukkit.plugin.ServicesManager;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerialization;
|
||||
import org.dynmap.markers.MarkerAPI;
|
||||
|
||||
import us.camin.regions.commands.RegionCommand;
|
||||
import us.camin.regions.commands.RegionOpCommand;
|
||||
import us.camin.regions.commands.RegionsCommand;
|
||||
import us.camin.regions.config.RegionConfiguration;
|
||||
import us.camin.regions.config.WorldConfiguration;
|
||||
import us.camin.regions.ui.PlayerInventoryTeleporter;
|
||||
|
||||
import org.dynmap.DynmapCommonAPI;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import java.util.Random;
|
||||
import javax.security.auth.login.ConfigurationSpi;
|
||||
|
||||
public class Plugin extends JavaPlugin implements RegionAPI {
|
||||
public class Plugin extends JavaPlugin {
|
||||
Logger log = Logger.getLogger("Regions");
|
||||
RegionManager m_regions;
|
||||
PlayerWatcher m_playerWatcher;
|
||||
RegionPostManager m_regionPosts;
|
||||
|
||||
public RegionManager regionManager() {
|
||||
return m_regions;
|
||||
}
|
||||
|
||||
public PlayerWatcher playerWatcher() {
|
||||
return m_playerWatcher;
|
||||
}
|
||||
|
||||
public void onEnable() {
|
||||
log.info("[Regions] Enabling Regions");
|
||||
m_regions = new RegionManager(getServer());
|
||||
log.info("Enabling Regions");
|
||||
ConfigurationSerialization.registerClass(RegionConfiguration.class);
|
||||
m_regions = new RegionManager(this, getServer());
|
||||
m_playerWatcher = new PlayerWatcher(this, m_regions);
|
||||
|
||||
m_playerWatcher = new PlayerWatcher(m_regions);
|
||||
getCommand("region").setExecutor(new RegionCommand(this));
|
||||
getCommand("regions").setExecutor(new RegionsCommand(this));
|
||||
getCommand("regionop").setExecutor(new RegionOpCommand(this));
|
||||
|
||||
getServer().getScheduler().scheduleAsyncRepeatingTask(this, m_playerWatcher, 0, 5*20);
|
||||
|
||||
CommandExecutor regionCommand = new RegionCommand(this);
|
||||
getCommand("region").setExecutor(regionCommand);
|
||||
getCommand("cityregion").setExecutor(new CityRegionCommand(this));
|
||||
getCommand("homeregion").setExecutor(new HomeRegionCommand(this));
|
||||
getCommand("movein").setExecutor(new MoveinCommand(this));
|
||||
|
||||
getServer().getPluginManager().registerEvents(new BukkitEventHandler(m_regions), this);
|
||||
boolean useHolograms = getServer().getPluginManager().isPluginEnabled("HolographicDisplays");
|
||||
if (!useHolograms) {
|
||||
log.info("HolographicDisplays not enabled. Region posts will not have holograms.");
|
||||
}
|
||||
m_regionPosts = new RegionPostManager(m_regions, this, useHolograms);
|
||||
// TODO: Make holograms configurable. Disabled by default for now.
|
||||
//getServer().getPluginManager().registerEvents(m_regionPosts, this);
|
||||
|
||||
loadRegions();
|
||||
m_playerWatcher.recalculatePlayerRegions(true);
|
||||
org.bukkit.plugin.Plugin mapPlugin = getServer().getPluginManager().getPlugin("dynmap");
|
||||
if (mapPlugin instanceof DynmapCommonAPI) {
|
||||
if (mapPlugin instanceof DynmapCommonAPI && mapPlugin != null) {
|
||||
DynmapCommonAPI mapAPI = (DynmapCommonAPI)mapPlugin;
|
||||
MarkerAPI markerAPI = mapAPI.getMarkerAPI();
|
||||
if (markerAPI != null) {
|
||||
DynmapEventRelay regionHandler = new DynmapEventRelay (markerAPI);
|
||||
DynmapEventRelay regionHandler = new DynmapEventRelay (this, markerAPI);
|
||||
getServer().getPluginManager().registerEvents(regionHandler, this);
|
||||
} else {
|
||||
log.info("[Regions] Dynmap marker API not found. Disabling map support.");
|
||||
log.info("Dynmap marker API not found. Disabling map support.");
|
||||
}
|
||||
} else {
|
||||
log.info("[Regions] Dynmap not found. Disabling map support.");
|
||||
log.info("Dynmap not found. Disabling map support.");
|
||||
}
|
||||
|
||||
ServicesManager sm = getServer().getServicesManager();
|
||||
sm.register(RegionAPI.class, this, this, ServicePriority.Normal);
|
||||
|
||||
loadRegions();
|
||||
}
|
||||
|
||||
private void loadTestRegions() {
|
||||
log.info("[Regions] Loading test regions for development");
|
||||
String[] regionNames = {"Redstone", "Lapis", "Dwarf City"};
|
||||
Random rand = new Random();
|
||||
for(World w : getServer().getWorlds()) {
|
||||
for(String name : regionNames) {
|
||||
Location loc = new Location(w, rand.nextInt(30), 64, rand.nextInt(30));
|
||||
Region r = new Region(name, loc);
|
||||
m_regions.addRegion(r);
|
||||
}
|
||||
}
|
||||
// Install the event handler after things are loaded so players aren't spammed with text
|
||||
getServer().getPluginManager().registerEvents(m_playerWatcher, this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerNotifier(this, m_regions), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerInventoryTeleporter(this, m_regions), this);
|
||||
getServer().getPluginManager().registerEvents(new RegionPostItemWatcher(this, m_regions), this);
|
||||
getServer().getPluginManager().registerEvents(new RegionPostInteractionWatcher(this, m_regions), this);
|
||||
}
|
||||
|
||||
public void loadRegions() {
|
||||
reloadConfig();
|
||||
ConfigurationSection section = getConfig().getConfigurationSection("worlds");
|
||||
m_regions.clear();
|
||||
if (section != null)
|
||||
m_regions.loadRegions(section, getServer());
|
||||
m_regions.recalculatePlayerRegions();
|
||||
this.getDataFolder().mkdir();
|
||||
File regionConfigFile = new File(this.getDataFolder(), "regions.yml");
|
||||
Configuration regionConf = YamlConfiguration.loadConfiguration(regionConfigFile);
|
||||
m_regions.loadRegions(regionConf);
|
||||
}
|
||||
|
||||
public void saveRegions() {
|
||||
m_regions.saveRegions(getConfig().createSection("worlds"));
|
||||
this.getDataFolder().mkdir();
|
||||
File regionConfigFile = new File(this.getDataFolder(), "regions.yml");
|
||||
YamlConfiguration regionConf = YamlConfiguration.loadConfiguration(regionConfigFile);
|
||||
m_regions.saveRegions(regionConf);
|
||||
try {
|
||||
regionConf.save(regionConfigFile);
|
||||
} catch (IOException e) {
|
||||
log.log(Level.SEVERE, "Failed to write out regions.yml!!! Your data has not been saved!", e);
|
||||
}
|
||||
saveConfig();
|
||||
}
|
||||
|
||||
public void onDisable() {
|
||||
m_regionPosts.release();
|
||||
saveRegions();
|
||||
log.info("[Regions] Plugin disabled");
|
||||
}
|
||||
|
||||
public void regenRegionPost(Region r) {
|
||||
World world = r.location().getWorld();
|
||||
Location center = world.getHighestBlockAt(r.location()).getLocation();
|
||||
for(int x = center.getBlockX()-1;x <= center.getBlockX()+1;x++) {
|
||||
for(int z = center.getBlockZ()-1;z <= center.getBlockZ()+1;z++) {
|
||||
Block b = world.getBlockAt(x, center.getBlockY()-1, z);
|
||||
b.setType(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
|
||||
for(int y = center.getBlockY()-2;y < center.getBlockY()+2;y++) {
|
||||
Block b = world.getBlockAt(center.getBlockX(), y, center.getBlockZ());
|
||||
b.setType(Material.GLOWSTONE);
|
||||
}
|
||||
log.info("Plugin disabled");
|
||||
}
|
||||
}
|
||||
|
@ -19,14 +19,89 @@ package us.camin.regions;
|
||||
*/
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Particle.DustOptions;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import us.camin.regions.config.RegionConfiguration;
|
||||
import us.camin.regions.ui.Colors;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
|
||||
public class Region {
|
||||
private Location m_location;
|
||||
private String m_name;
|
||||
private List<Pattern> m_bannerPatterns = new ArrayList<Pattern>();
|
||||
private DyeColor m_color = null;
|
||||
private List<UUID> m_seenPlayers = new ArrayList<UUID>();
|
||||
private boolean m_isHub = false;
|
||||
|
||||
public Region(String name, Location location) {
|
||||
m_location = location;
|
||||
m_location = location.toBlockLocation();
|
||||
m_name = name;
|
||||
// Pick a random color
|
||||
m_color = DyeColor.values()[(int)(System.currentTimeMillis() % DyeColor.values().length)];
|
||||
}
|
||||
|
||||
public Region(String name, Location location, int visits, int charges, DyeColor color) {
|
||||
m_location = location.toBlockLocation();
|
||||
m_name = name;
|
||||
m_visits = visits;
|
||||
m_charges = charges;
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
public Region(String name, World world, RegionConfiguration conf) {
|
||||
if (conf.y == -1) {
|
||||
Location defaultLoc = new Location(world, conf.x, 64, conf.z);
|
||||
conf.y = world.getHighestBlockAt(defaultLoc).getY();
|
||||
}
|
||||
m_name = name;
|
||||
m_visits = conf.visits;
|
||||
m_charges = conf.charges;
|
||||
m_location = new Location(world, conf.x, conf.y, conf.z);
|
||||
m_bannerPatterns = conf.patterns;
|
||||
m_color = conf.color;
|
||||
m_seenPlayers = conf.seenBy;
|
||||
m_isHub = conf.isHub;
|
||||
}
|
||||
|
||||
public boolean isHub() {
|
||||
return m_isHub;
|
||||
}
|
||||
|
||||
public boolean seenByPlayer(OfflinePlayer p) {
|
||||
return m_seenPlayers.contains(p.getUniqueId());
|
||||
}
|
||||
|
||||
public boolean markSeenByPlayer(OfflinePlayer p) {
|
||||
if (!m_seenPlayers.contains(p.getUniqueId())) {
|
||||
m_seenPlayers.add(p.getUniqueId());
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public List<UUID> seenPlayers() {
|
||||
return m_seenPlayers;
|
||||
}
|
||||
|
||||
public List<Pattern> bannerPatterns() {
|
||||
return m_bannerPatterns;
|
||||
}
|
||||
|
||||
public void setBannerPatterns(List<Pattern> p) {
|
||||
m_bannerPatterns = p;
|
||||
}
|
||||
|
||||
public Location location() {
|
||||
@ -34,17 +109,188 @@ public class Region {
|
||||
}
|
||||
|
||||
public Location teleportLocation() {
|
||||
return m_location.getWorld().getHighestBlockAt(m_location).getLocation();
|
||||
return m_location.clone().add(0.5, 3, 0.5);
|
||||
}
|
||||
|
||||
public Location interactLocation() {
|
||||
return m_location.clone().add(0, 1, 0);
|
||||
}
|
||||
|
||||
public void addCharges(int charges) {
|
||||
m_charges += charges;
|
||||
}
|
||||
|
||||
int m_visits = 0;
|
||||
int m_charges = 0;
|
||||
|
||||
public boolean shouldKeepLoaded() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public int visits() {
|
||||
return m_visits;
|
||||
}
|
||||
|
||||
public int charges() {
|
||||
return m_charges;
|
||||
}
|
||||
|
||||
public void addVisit() {
|
||||
m_visits++;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return m_name;
|
||||
}
|
||||
|
||||
public DyeColor color() {
|
||||
return m_color;
|
||||
}
|
||||
|
||||
public void setColor(DyeColor color) {
|
||||
m_color = color;
|
||||
}
|
||||
|
||||
/**
|
||||
* An alternative to Location.distance() which doesn't use floating point math.
|
||||
*/
|
||||
public int distanceTo(Location loc) {
|
||||
return Math.abs((m_location.getBlockX()-loc.getBlockX())+Math.abs(m_location.getBlockZ()-loc.getBlockZ()));
|
||||
return (int)m_location.distance(loc);
|
||||
}
|
||||
|
||||
public String coloredName() {
|
||||
return Colors.chatColorForColor(m_color) + name() + ChatColor.RESET;
|
||||
}
|
||||
|
||||
public DustOptions dustOptions() {
|
||||
return new DustOptions(m_color.getColor(), 1);
|
||||
}
|
||||
|
||||
public Material bannerIconMaterial() {
|
||||
switch(m_color) {
|
||||
case BLACK:
|
||||
return Material.BLACK_BANNER;
|
||||
case BLUE:
|
||||
return Material.BLUE_BANNER;
|
||||
case BROWN:
|
||||
return Material.BROWN_BANNER;
|
||||
case CYAN:
|
||||
return Material.CYAN_BANNER;
|
||||
case GRAY:
|
||||
return Material.GRAY_BANNER;
|
||||
case GREEN:
|
||||
return Material.GREEN_BANNER;
|
||||
case LIGHT_BLUE:
|
||||
return Material.LIGHT_BLUE_BANNER;
|
||||
case LIGHT_GRAY:
|
||||
return Material.LIGHT_GRAY_BANNER;
|
||||
case LIME:
|
||||
return Material.LIME_BANNER;
|
||||
case MAGENTA:
|
||||
return Material.MAGENTA_BANNER;
|
||||
case ORANGE:
|
||||
return Material.ORANGE_BANNER;
|
||||
case PINK:
|
||||
return Material.PINK_BANNER;
|
||||
case PURPLE:
|
||||
return Material.PURPLE_BANNER;
|
||||
case RED:
|
||||
return Material.RED_BANNER;
|
||||
case WHITE:
|
||||
return Material.WHITE_BANNER;
|
||||
case YELLOW:
|
||||
return Material.YELLOW_BANNER;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Material.YELLOW_BANNER;
|
||||
}
|
||||
|
||||
public Material bannerBlockMaterial() {
|
||||
switch(m_color) {
|
||||
case BLACK:
|
||||
return Material.BLACK_WALL_BANNER;
|
||||
case BLUE:
|
||||
return Material.BLUE_WALL_BANNER;
|
||||
case BROWN:
|
||||
return Material.BROWN_WALL_BANNER;
|
||||
case CYAN:
|
||||
return Material.CYAN_WALL_BANNER;
|
||||
case GRAY:
|
||||
return Material.GRAY_WALL_BANNER;
|
||||
case GREEN:
|
||||
return Material.GREEN_WALL_BANNER;
|
||||
case LIGHT_BLUE:
|
||||
return Material.LIGHT_BLUE_WALL_BANNER;
|
||||
case LIGHT_GRAY:
|
||||
return Material.LIGHT_GRAY_WALL_BANNER;
|
||||
case LIME:
|
||||
return Material.LIME_WALL_BANNER;
|
||||
case MAGENTA:
|
||||
return Material.MAGENTA_WALL_BANNER;
|
||||
case ORANGE:
|
||||
return Material.ORANGE_WALL_BANNER;
|
||||
case PINK:
|
||||
return Material.PINK_WALL_BANNER;
|
||||
case PURPLE:
|
||||
return Material.PURPLE_WALL_BANNER;
|
||||
case RED:
|
||||
return Material.RED_WALL_BANNER;
|
||||
case WHITE:
|
||||
return Material.WHITE_WALL_BANNER;
|
||||
case YELLOW:
|
||||
return Material.YELLOW_WALL_BANNER;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Material.YELLOW_WALL_BANNER;
|
||||
}
|
||||
|
||||
public Material blockMaterial() {
|
||||
switch(m_color) {
|
||||
case BLACK:
|
||||
return Material.BLACK_WOOL;
|
||||
case BLUE:
|
||||
return Material.BLUE_WOOL;
|
||||
case BROWN:
|
||||
return Material.BROWN_WOOL;
|
||||
case CYAN:
|
||||
return Material.CYAN_WOOL;
|
||||
case GRAY:
|
||||
return Material.GRAY_WOOL;
|
||||
case GREEN:
|
||||
return Material.GREEN_WOOL;
|
||||
case LIGHT_BLUE:
|
||||
return Material.LIGHT_BLUE_WOOL;
|
||||
case LIGHT_GRAY:
|
||||
return Material.LIGHT_GRAY_WOOL;
|
||||
case LIME:
|
||||
return Material.LIME_WOOL;
|
||||
case MAGENTA:
|
||||
return Material.MAGENTA_WOOL;
|
||||
case ORANGE:
|
||||
return Material.ORANGE_WOOL;
|
||||
case PINK:
|
||||
return Material.PINK_WOOL;
|
||||
case PURPLE:
|
||||
return Material.PURPLE_WOOL;
|
||||
case RED:
|
||||
return Material.RED_WOOL;
|
||||
case WHITE:
|
||||
return Material.WHITE_WOOL;
|
||||
case YELLOW:
|
||||
return Material.YELLOW_WOOL;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return Material.YELLOW_WOOL;
|
||||
}
|
||||
|
||||
public ItemStack icon() {
|
||||
ItemStack item = new ItemStack(bannerIconMaterial());
|
||||
BannerMeta bannerMeta = (BannerMeta)item.getItemMeta();
|
||||
bannerMeta.setPatterns(bannerPatterns());
|
||||
item.setItemMeta(bannerMeta);
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
@ -21,96 +21,49 @@ package us.camin.regions;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Set;
|
||||
|
||||
public class RegionManager {
|
||||
Logger log = Logger.getLogger("Regions.RegionManager");
|
||||
private Map<String, Collection<Region>> m_regions;
|
||||
private Map<String, Region> m_cityRegions;
|
||||
private Map<String, Region> m_homeRegions;
|
||||
private Server m_server;
|
||||
private Map<Player, Region> m_lastKnownRegions;
|
||||
private Map<Region, Collection<Player>> m_regionPlayerLists;
|
||||
import us.camin.regions.config.RegionConfiguration;
|
||||
import us.camin.regions.config.WorldConfiguration;
|
||||
import us.camin.regions.events.RegionCreateEvent;
|
||||
import us.camin.regions.events.RegionRemoveEvent;
|
||||
import us.camin.regions.geometry.RegionSet;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public RegionManager(Server server) {
|
||||
public class RegionManager {
|
||||
|
||||
Logger log = Logger.getLogger("Regions.RegionManager");
|
||||
private Map<String, RegionSet> m_regions;
|
||||
private Server m_server;
|
||||
public RegionManager(Plugin plugin, Server server) {
|
||||
m_server = server;
|
||||
log.setLevel(Level.ALL);
|
||||
clear();
|
||||
}
|
||||
|
||||
public synchronized Collection<Player> playersInRegion(Region r) {
|
||||
if (m_regionPlayerLists.get(r) == null)
|
||||
return Collections.unmodifiableCollection(new ArrayList<Player>());
|
||||
return Collections.unmodifiableCollection(m_regionPlayerLists.get(r));
|
||||
}
|
||||
|
||||
public synchronized void recalculatePlayerRegions() {
|
||||
ArrayList<Event> updateEvents = new ArrayList<Event>();
|
||||
Player[] allPlayers = m_server.getOnlinePlayers();
|
||||
for (Player p : allPlayers) {
|
||||
Location loc = p.getLocation();
|
||||
Region nearest = nearestRegion(loc);
|
||||
if (nearest != null) {
|
||||
log.finest("Current region for "+p.getName()+": "+nearest.name());
|
||||
Region last = m_lastKnownRegions.get(p);
|
||||
if (nearest != last) {
|
||||
updateEvents.add(new PlayerRegionChangeEvent(p, last, nearest));
|
||||
log.fine("Player "+p.getName()+" entered region "+nearest.name());
|
||||
m_regionPlayerLists.get(nearest).add(p);
|
||||
if (m_regionPlayerLists.get(last) != null)
|
||||
m_regionPlayerLists.get(last).remove(p);
|
||||
m_lastKnownRegions.put(p, nearest);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Event e : updateEvents) {
|
||||
m_server.getPluginManager().callEvent(e);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void clear() {
|
||||
m_regions = new HashMap<String, Collection<Region>>();
|
||||
m_cityRegions = new HashMap<String, Region>();
|
||||
m_homeRegions = new HashMap<String, Region>();
|
||||
m_lastKnownRegions = new HashMap<Player, Region>();
|
||||
m_regionPlayerLists = new HashMap<Region, Collection<Player>>();
|
||||
m_regions = new HashMap<>();
|
||||
}
|
||||
|
||||
public synchronized void renameWorld(String oldName, String newName) {
|
||||
log.fine("Renaming "+oldName+" to "+newName);
|
||||
m_regions.put(newName, m_regions.remove(oldName));
|
||||
m_cityRegions.put(newName, m_cityRegions.remove(oldName));
|
||||
}
|
||||
|
||||
public synchronized Region cityRegion(String worldName) {
|
||||
return m_cityRegions.get(worldName);
|
||||
}
|
||||
|
||||
public synchronized void setCityRegion(String worldName, Region region) {
|
||||
m_cityRegions.put(worldName, region);
|
||||
}
|
||||
|
||||
public synchronized boolean addRegion(Region r) {
|
||||
String worldName = r.location().getWorld().getName();
|
||||
log.fine("Adding new region "+r.name()+" at "+r.location());
|
||||
if (!m_regions.containsKey(worldName))
|
||||
m_regions.put(worldName, new ArrayList<Region>());
|
||||
m_regions.put(worldName, new RegionSet());
|
||||
if (m_regions.get(worldName).add(r)) {
|
||||
m_regionPlayerLists.put(r, new ArrayList<Player>());
|
||||
m_server.getPluginManager().callEvent(new RegionCreateEvent(r));
|
||||
recalculatePlayerRegions();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -120,99 +73,79 @@ public class RegionManager {
|
||||
log.fine("Removing region "+r.name()+" from "+r.location());
|
||||
if (m_regions.containsKey(worldName)) {
|
||||
if (m_regions.get(worldName).remove(r)) {
|
||||
m_regionPlayerLists.remove(r);
|
||||
m_server.getPluginManager().callEvent(new RegionRemoveEvent(r));
|
||||
recalculatePlayerRegions();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Collection<Region> regionsForWorld(World world) {
|
||||
public RegionSet regionsForWorld(World world) {
|
||||
return regionsForWorld(world.getName());
|
||||
}
|
||||
|
||||
public synchronized Collection<Region> regionsForWorld(String worldName) {
|
||||
if (m_regions.containsKey(worldName))
|
||||
return Collections.unmodifiableCollection(m_regions.get(worldName));
|
||||
else
|
||||
return Collections.unmodifiableCollection(new ArrayList<Region>());
|
||||
public Collection<Region> neighborsForRegion(Region region) {
|
||||
return regionsForWorld(region.location().getWorld()).borders().neighbors(region);
|
||||
}
|
||||
|
||||
public Collection<Region> worldHubs(World world) {
|
||||
ArrayList<Region> regions = new ArrayList<Region>();
|
||||
for(Region r : regionsForWorld(world.getName())) {
|
||||
if (r.isHub()) {
|
||||
regions.add(r);
|
||||
}
|
||||
}
|
||||
return regions;
|
||||
}
|
||||
|
||||
public synchronized RegionSet regionsForWorld(String worldName) {
|
||||
if (m_regions.containsKey(worldName)) {
|
||||
return m_regions.get(worldName);
|
||||
} else {
|
||||
return new RegionSet();
|
||||
}
|
||||
}
|
||||
|
||||
public Region nearestRegion(Location loc) {
|
||||
Collection<Region> regions = regionsForWorld(loc.getWorld());
|
||||
Region nearest = null;
|
||||
int minDistance = -1;
|
||||
for(Region r : regions) {
|
||||
int check = r.distanceTo(loc);
|
||||
if (minDistance == -1 || check < minDistance) {
|
||||
nearest = r;
|
||||
minDistance = check;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
return regionsForWorld(loc.getWorld()).nearestRegion(loc);
|
||||
}
|
||||
|
||||
public synchronized void saveRegions(ConfigurationSection section) {
|
||||
for(String worldName : m_regions.keySet()) {
|
||||
ConfigurationSection worldSection = section.createSection(worldName);
|
||||
Region cityRegion = cityRegion(worldName);
|
||||
if (cityRegion != null)
|
||||
worldSection.set("city", cityRegion.name());
|
||||
ConfigurationSection worldRegionSection = worldSection.createSection("regions");
|
||||
ConfigurationSection worldRegionSection = section.createSection(worldName);
|
||||
for(Region r : regionsForWorld(worldName)) {
|
||||
ConfigurationSection regionSection = worldRegionSection.createSection(r.name());
|
||||
regionSection.set("x", r.location().getBlockX());
|
||||
regionSection.set("z", r.location().getBlockZ());
|
||||
ArrayList<String> homePlayers = new ArrayList<String>();
|
||||
for(String player : m_homeRegions.keySet()) {
|
||||
if (m_homeRegions.get(player) == r) {
|
||||
homePlayers.add(player);
|
||||
}
|
||||
}
|
||||
regionSection.set("players", homePlayers);
|
||||
RegionConfiguration conf = new RegionConfiguration(r);
|
||||
worldRegionSection.createSection(r.name(), conf.serialize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Region homeRegion(String playerName) {
|
||||
return m_homeRegions.get(playerName);
|
||||
return null;
|
||||
//return m_homeRegions.get(playerName);
|
||||
}
|
||||
|
||||
public synchronized void setHomeRegion(String player, Region r) {
|
||||
m_homeRegions.put(player, r);
|
||||
public synchronized void setHomeRegion(Player player, Region r) {
|
||||
/*Region old = m_homeRegions.get(player.getName());
|
||||
m_homeRegions.put(player.getName(), r);
|
||||
log.info("Player "+player.getName()+" moved in to "+r.name());
|
||||
PlayerMoveInEvent evt = new PlayerMoveInEvent(player, r, old);
|
||||
m_plugin.getServer().getPluginManager().callEvent(evt);*/
|
||||
}
|
||||
|
||||
public synchronized void loadRegions(ConfigurationSection section, Server server) {
|
||||
Set<String> worldNames = section.getKeys(false);
|
||||
for(String worldName : worldNames) {
|
||||
ConfigurationSection worldSection = section.getConfigurationSection(worldName);
|
||||
String cityName = worldSection.getString("city");
|
||||
ConfigurationSection worldRegionSection = worldSection.getConfigurationSection("regions");
|
||||
Set<String> regionNames = worldRegionSection.getKeys(false);
|
||||
World world = server.getWorld(worldName);
|
||||
if (world == null) {
|
||||
log.warning("Could not find world: "+worldName);
|
||||
continue;
|
||||
}
|
||||
for(String regionName : regionNames) {
|
||||
ConfigurationSection regionSection = worldRegionSection.getConfigurationSection(regionName);
|
||||
int x = regionSection.getInt("x");
|
||||
int z = regionSection.getInt("z");
|
||||
Location loc = new Location(world, x, 64, z);
|
||||
Region r = new Region(regionName, loc);
|
||||
addRegion(r);
|
||||
public synchronized void loadRegions(ConfigurationSection section) {
|
||||
for(World world : m_server.getWorlds()) {
|
||||
ConfigurationSection worldConfig = section.getConfigurationSection(world.getName());
|
||||
|
||||
if (regionName.equals(cityName)) {
|
||||
m_cityRegions.put(worldName, r);
|
||||
}
|
||||
if (worldConfig == null) {
|
||||
log.info("No regions configured for world " + world.getName());
|
||||
continue;
|
||||
}
|
||||
|
||||
List<String> regionPlayers = regionSection.getStringList("players");
|
||||
for(String player : regionPlayers) {
|
||||
m_homeRegions.put(player, r);
|
||||
}
|
||||
for(String regionName : worldConfig.getKeys(false)) {
|
||||
RegionConfiguration conf = new RegionConfiguration(worldConfig.getConfigurationSection(regionName).getValues(false));
|
||||
addRegion(new Region(regionName, world, conf));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
134
src/main/java/us/camin/regions/RegionPostInteractionWatcher.java
Normal file
134
src/main/java/us/camin/regions/RegionPostInteractionWatcher.java
Normal file
@ -0,0 +1,134 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.material.Banner;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.DyeColor;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
import us.camin.regions.events.PlayerPostInteractEvent;
|
||||
import us.camin.regions.events.PlayerAddRegionChargeEvent;
|
||||
|
||||
public class RegionPostInteractionWatcher implements Listener {
|
||||
private RegionManager m_manager;
|
||||
private Plugin m_plugin;
|
||||
Logger log = Logger.getLogger("Regions.RegionPostBuilder");
|
||||
|
||||
public RegionPostInteractionWatcher(Plugin plugin, RegionManager manager) {
|
||||
m_manager = manager;
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
private final Material[] bannerTypes = {
|
||||
Material.WHITE_BANNER,
|
||||
Material.YELLOW_BANNER,
|
||||
Material.BLUE_BANNER,
|
||||
Material.BLACK_BANNER,
|
||||
Material.BROWN_BANNER,
|
||||
Material.CYAN_BANNER,
|
||||
Material.GREEN_BANNER,
|
||||
Material.LIGHT_BLUE_BANNER,
|
||||
Material.GRAY_BANNER,
|
||||
Material.LIGHT_GRAY_BANNER,
|
||||
Material.LIME_BANNER,
|
||||
Material.MAGENTA_BANNER,
|
||||
Material.ORANGE_BANNER,
|
||||
Material.PINK_BANNER,
|
||||
Material.PURPLE_BANNER,
|
||||
Material.RED_BANNER,
|
||||
};
|
||||
|
||||
private boolean isBannerItem(ItemStack item) {
|
||||
for(Material mat : bannerTypes) {
|
||||
if (item.getType() == mat) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack handStack = player.getItemInHand();
|
||||
ItemMeta meta = handStack.getItemMeta();
|
||||
Region nearest = m_manager.nearestRegion(player.getLocation());
|
||||
if (nearest == null) {
|
||||
return;
|
||||
}
|
||||
Block clickedBlock = event.getClickedBlock();
|
||||
Location interactRegion = nearest.interactLocation();
|
||||
Location lanternRegion = nearest.interactLocation().add(0, 1, 0);
|
||||
boolean isInteracted = false;
|
||||
if (clickedBlock != null) {
|
||||
isInteracted |= clickedBlock.getBlockKey() == interactRegion.toBlockKey();
|
||||
isInteracted |= clickedBlock.getBlockKey() == lanternRegion.toBlockKey();
|
||||
isInteracted |= nearest.interactLocation().add(1, 0, 0).toBlockKey() == clickedBlock.getBlockKey();
|
||||
isInteracted |= nearest.interactLocation().add(-1, 0, 0).toBlockKey() == clickedBlock.getBlockKey();
|
||||
isInteracted |= nearest.interactLocation().add(0, 0, 1).toBlockKey() == clickedBlock.getBlockKey();
|
||||
isInteracted |= nearest.interactLocation().add(0, 0, -1).toBlockKey() == clickedBlock.getBlockKey();
|
||||
}
|
||||
if (isInteracted) {
|
||||
event.setCancelled(true);
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
if (!player.hasPermission("regions.use")) {
|
||||
player.sendMessage("You cannot use region posts at this time.");
|
||||
return;
|
||||
}
|
||||
if (RegionPostItemWatcher.isChargeItem(handStack)) {
|
||||
nearest.addCharges(1);
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(nearest, m_plugin);
|
||||
builder.updateLantern();
|
||||
});
|
||||
m_plugin.saveRegions();
|
||||
player.setItemInHand(handStack.subtract());
|
||||
m_plugin.getServer().getPluginManager().callEvent(new PlayerAddRegionChargeEvent(player, nearest));
|
||||
} else if (isBannerItem(handStack)) {
|
||||
DyeColor bannerColor = DyeColor.getByDyeData(handStack.getData().getData());
|
||||
BannerMeta bannerMeta = (BannerMeta)meta;
|
||||
log.info("Setting banner color to " + bannerColor);
|
||||
nearest.setBannerPatterns(bannerMeta.getPatterns());
|
||||
nearest.setColor(bannerColor);
|
||||
m_plugin.saveRegions();
|
||||
player.sendMessage("You've updated the region post banner");
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(nearest, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
} else if (nearest.charges() > 0 || player.hasPermission("regions.bypass.charges")) {
|
||||
m_plugin.getServer().getPluginManager().callEvent(new PlayerPostInteractEvent(player, nearest));
|
||||
} else {
|
||||
player.sendMessage("This region post is not charged. Right click on it while holding cobblestone.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
179
src/main/java/us/camin/regions/RegionPostItemWatcher.java
Normal file
179
src/main/java/us/camin/regions/RegionPostItemWatcher.java
Normal file
@ -0,0 +1,179 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.CompassMeta;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.event.block.Action;
|
||||
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RegionPostItemWatcher implements Listener {
|
||||
private RegionManager m_manager;
|
||||
private Plugin m_plugin;
|
||||
|
||||
public RegionPostItemWatcher(Plugin plugin, RegionManager manager) {
|
||||
m_manager = manager;
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
static public ItemStack createCompass() {
|
||||
ItemStack stack = new ItemStack(Material.COMPASS);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("Right click to locate the nearest Region Post");
|
||||
meta.setLore(lore);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
static public ItemStack createChargeItem() {
|
||||
ItemStack stack = new ItemStack(Material.GLOWSTONE_DUST);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("Charges or repairs a region post");
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
meta.setDisplayName("Region Post Charge");
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
static public ItemStack createCreateItem() {
|
||||
ItemStack stack = new ItemStack(Material.LANTERN);
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
List<String> lore = new ArrayList<String>();
|
||||
lore.add("Place to create a new region post");
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
meta.setLore(lore);
|
||||
stack.setItemMeta(meta);
|
||||
return stack;
|
||||
}
|
||||
|
||||
private ItemStack m_theCompass = createCompass();
|
||||
private ItemStack m_theItem = createCreateItem();
|
||||
private static ItemStack m_theChargeItem = createChargeItem();
|
||||
|
||||
public static boolean isChargeItem(ItemStack stack) {
|
||||
return stack.isSimilar(m_theChargeItem);
|
||||
}
|
||||
|
||||
public boolean isRegionCompass(ItemStack stack) {
|
||||
if (stack.isSimilar(m_theCompass)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stack.getType() == m_theItem.getType()) {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
ItemMeta theItemMeta = m_theItem.getItemMeta();
|
||||
if (meta.getItemFlags() == theItemMeta.getItemFlags()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isRegionCreateItem(ItemStack stack, Player p) {
|
||||
if (stack.isSimilar(m_theItem)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (stack.getType() == m_theItem.getType()) {
|
||||
ItemMeta meta = stack.getItemMeta();
|
||||
ItemMeta theItemMeta = m_theItem.getItemMeta();
|
||||
if (meta.getLore().equals(theItemMeta.getLore())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInteract(PlayerInteractEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
ItemStack handStack = event.getItem();
|
||||
if (handStack == null) {
|
||||
return;
|
||||
}
|
||||
ItemMeta meta = handStack.getItemMeta();
|
||||
|
||||
if (isRegionCompass(handStack) && event.getAction() == Action.RIGHT_CLICK_AIR) {
|
||||
event.setCancelled(true);
|
||||
ItemStack compassItem = new ItemStack(Material.COMPASS);
|
||||
Region nearest = m_manager.nearestRegion(player.getLocation());
|
||||
if (nearest == null) {
|
||||
player.sendMessage("There are no regions in this world!");
|
||||
return;
|
||||
}
|
||||
CompassMeta compassMeta = (CompassMeta)compassItem.getItemMeta();
|
||||
compassMeta.setDisplayName(nearest.name());
|
||||
compassMeta.setLodestone(nearest.location());
|
||||
compassMeta.setLodestoneTracked(false);
|
||||
ArrayList<String> newLore = new ArrayList<String>();
|
||||
newLore.add("Right click to locate the nearest Region Post");
|
||||
newLore.add("Tracking: " + nearest.name());
|
||||
compassMeta.setLore(newLore);
|
||||
compassItem.setItemMeta(compassMeta);
|
||||
player.setItemInHand(compassItem);
|
||||
player.sendMessage("Now tracking " + nearest.name());
|
||||
} else if (!event.isCancelled() && isRegionCreateItem(handStack, player) && event.getAction() == Action.RIGHT_CLICK_BLOCK && !event.getClickedBlock().getType().isInteractable()) {
|
||||
event.setUseItemInHand(Event.Result.DENY);
|
||||
event.setCancelled(true);
|
||||
if (meta.getDisplayName().equals("")) {
|
||||
player.sendMessage("You must first give this item a name!");
|
||||
} else {
|
||||
Region nearest = m_manager.nearestRegion(player.getLocation());
|
||||
if (nearest != null && player.getLocation().distance(nearest.interactLocation()) <= 500) {
|
||||
player.sendMessage("You are too close to the region post for " + nearest.name());
|
||||
} else {
|
||||
Region r = new Region(meta.getDisplayName(), event.getClickedBlock().getRelative(event.getBlockFace()).getLocation());
|
||||
//player.teleport(r.teleportLocation());
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
player.setItemInHand(handStack.subtract());
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.saveRegions();
|
||||
player.sendMessage("You established the region "+r.coloredName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
141
src/main/java/us/camin/regions/RegionPostManager.java
Normal file
141
src/main/java/us/camin/regions/RegionPostManager.java
Normal file
@ -0,0 +1,141 @@
|
||||
package us.camin.regions;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.Location;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.HologramsAPI;
|
||||
|
||||
import us.camin.regions.events.PlayerNearRegionPostEvent;
|
||||
import us.camin.regions.events.RegionCreateEvent;
|
||||
import us.camin.regions.events.RegionRemoveEvent;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
import com.gmail.filoghost.holographicdisplays.api.Hologram;
|
||||
|
||||
public class RegionPostManager implements Listener {
|
||||
Logger log = Logger.getLogger("Regions.RegionPostManager");
|
||||
|
||||
Plugin m_plugin;
|
||||
RegionManager m_regions;
|
||||
boolean m_useHolograms;
|
||||
HashMap<Region, Hologram> m_regionHolograms;
|
||||
//HashMap<Region, ArmorStand> m_armorStands;
|
||||
|
||||
public RegionPostManager(RegionManager regions, Plugin plugin, boolean useHolograms) {
|
||||
//m_armorStands = new HashMap<Region, ArmorStand>();
|
||||
m_regions = regions;
|
||||
m_plugin = plugin;
|
||||
m_useHolograms = useHolograms;
|
||||
m_regionHolograms = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionCreate(RegionCreateEvent event) {
|
||||
Location loc = event.region.location();
|
||||
if (loc.getWorld().isChunkLoaded((int)loc.getX(), (int)loc.getY())) {
|
||||
createHologram(event.region);
|
||||
queueRebuild(event.region);
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerNearRegionPost(PlayerNearRegionPostEvent event) {
|
||||
createHologram(event.region);
|
||||
}
|
||||
|
||||
private void queueRebuild(Region region) {
|
||||
if (region != null) {
|
||||
log.info("Rebuilding region post for " + region.name());
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(region, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRegionDestroy(RegionRemoveEvent event) {
|
||||
destroyHologram(event.region);
|
||||
}
|
||||
|
||||
public void release() {
|
||||
for(Region r : new ArrayList<>(m_regionHolograms.keySet())) {
|
||||
destroyHologram(r);
|
||||
}
|
||||
/*for(Region r : new ArrayList<>(m_armorStands.keySet())) {
|
||||
destroyHologram(r);
|
||||
}*/
|
||||
}
|
||||
|
||||
private void createHologram(Region r) {
|
||||
if (!m_useHolograms) {
|
||||
return;
|
||||
}
|
||||
Hologram hologram = m_regionHolograms.get(r);
|
||||
if (hologram == null) {
|
||||
hologram = HologramsAPI.createHologram(m_plugin, r.teleportLocation().clone().add(0.5, 0, 0.5));
|
||||
hologram.appendTextLine(r.coloredName());
|
||||
m_regionHolograms.put(r, hologram);
|
||||
}
|
||||
/*boolean needsRegen = false;
|
||||
if (m_armorStands.containsKey(r)) {
|
||||
// If we have an armor stand, but it isn't valid, regen
|
||||
needsRegen = !m_armorStands.get(r).isValid();
|
||||
} else {
|
||||
// If we don't have an armor stand at all, regen
|
||||
needsRegen = true;
|
||||
}
|
||||
if (needsRegen) {
|
||||
log.info("Creating hologram for " + r.name());
|
||||
Location markerLocation = r.teleportLocation().clone().add(0.5, 0, 0.5);
|
||||
ArmorStand stand = (ArmorStand) r.location().getWorld().spawnEntity(markerLocation, EntityType.ARMOR_STAND);
|
||||
stand.setVisible(false);
|
||||
stand.setCustomName(r.coloredName());
|
||||
stand.setMarker(true);
|
||||
stand.setSmall(true);
|
||||
stand.setRemoveWhenFarAway(true);
|
||||
stand.setCustomNameVisible(true);
|
||||
stand.setInvulnerable(true);
|
||||
stand.setSilent(true);
|
||||
m_armorStands.put(r, stand);
|
||||
}*/
|
||||
}
|
||||
|
||||
private void destroyHologram(Region r) {
|
||||
if (!m_useHolograms) {
|
||||
return;
|
||||
}
|
||||
Hologram hologram = m_regionHolograms.get(r);
|
||||
if (hologram != null) {
|
||||
hologram.delete();
|
||||
}
|
||||
/*log.info("Destroying hologram for " + r.name());
|
||||
ArmorStand stand = m_armorStands.get(r);
|
||||
if (stand != null && stand.isValid()) {
|
||||
stand.remove();
|
||||
}
|
||||
m_armorStands.remove(r);*/
|
||||
}
|
||||
}
|
29
src/main/java/us/camin/regions/TestRegionGenerator.java
Normal file
29
src/main/java/us/camin/regions/TestRegionGenerator.java
Normal file
@ -0,0 +1,29 @@
|
||||
package us.camin.regions;
|
||||
|
||||
import java.util.Random;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Location;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
public class TestRegionGenerator {
|
||||
Plugin m_plugin;
|
||||
public TestRegionGenerator(Plugin plugin) {
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
public void generate() {
|
||||
String[] regionNames = {"Redstone", "Lapis", "Dwarf City", "Birchshire", "Channelside", "Coldwood", "Vincente", "East Redstone City", "Westernly", "Capital City"};
|
||||
Random rand = new Random();
|
||||
for(World w : m_plugin.getServer().getWorlds()) {
|
||||
for(String name : regionNames) {
|
||||
Location loc = new Location(w, rand.nextInt(800), 64, rand.nextInt(800));
|
||||
Region r = new Region(name, loc);
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
//builder.build();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -22,7 +22,8 @@ import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class MoveinCommand implements CommandExecutor {
|
||||
|
||||
@ -40,7 +41,7 @@ public class MoveinCommand implements CommandExecutor {
|
||||
Player p = (Player)sender;
|
||||
Region nearest = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (nearest != null) {
|
||||
m_plugin.regionManager().setHomeRegion(p.getName(), nearest);
|
||||
m_plugin.regionManager().setHomeRegion(p, nearest);
|
||||
sender.sendMessage("Your home region has been set to "+nearest.name());
|
||||
} else {
|
||||
sender.sendMessage("There are no regions in this world.");
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -21,9 +21,17 @@ package us.camin.regions;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class RegionCommand implements CommandExecutor {
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.ui.RegionPostBuilder;
|
||||
|
||||
public class RegionCommand implements CommandExecutor, TabCompleter {
|
||||
|
||||
Plugin m_plugin;
|
||||
|
||||
@ -31,6 +39,17 @@ public class RegionCommand implements CommandExecutor {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
if (args.length <= 1) {
|
||||
ret.add("create");
|
||||
ret.add("remove");
|
||||
ret.add("regen");
|
||||
ret.add("regenall");
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
if (!(sender instanceof Player)) {
|
||||
sender.sendMessage("Region command is only available to players.");
|
||||
@ -43,11 +62,19 @@ public class RegionCommand implements CommandExecutor {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
return true;
|
||||
}
|
||||
p.sendMessage("Current region: "+r.name());
|
||||
p.sendMessage("Current region: "+r.coloredName());
|
||||
p.sendMessage("Players in region:");
|
||||
for(Player neighbor : m_plugin.playerWatcher().playersInRegion(r)) {
|
||||
p.sendMessage(neighbor.getName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
String subCommand = split[0];
|
||||
if (subCommand.equals("create") && p.hasPermission("regions.create")) {
|
||||
if (split.length <= 1) {
|
||||
p.sendMessage("Must specify a region name");
|
||||
return true;
|
||||
}
|
||||
StringBuilder regionName = new StringBuilder();
|
||||
for(int i = 1;i<split.length-1;i++) {
|
||||
regionName.append(split[i]);
|
||||
@ -55,9 +82,9 @@ public class RegionCommand implements CommandExecutor {
|
||||
}
|
||||
regionName.append(split[split.length-1]);
|
||||
Region r = new Region(regionName.toString(), p.getLocation());
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.regenRegionPost(r);
|
||||
p.teleport(r.teleportLocation());
|
||||
m_plugin.regionManager().addRegion(r);
|
||||
m_plugin.saveRegions();
|
||||
} else if (subCommand.equals("remove") && p.hasPermission("regions.remove")) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
@ -65,30 +92,30 @@ public class RegionCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
m_plugin.regionManager().removeRegion(r);
|
||||
} else if (subCommand.equals("city") && p.hasPermission("regions.setCity")) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
return true;
|
||||
}
|
||||
m_plugin.regionManager().setCityRegion(p.getLocation().getWorld().getName(), r);
|
||||
p.sendMessage("City region set to "+r.name());
|
||||
} else if (subCommand.equals("regen") && p.hasPermission("regions.create")) {
|
||||
p.sendMessage("Deleted region " + r.coloredName());
|
||||
m_plugin.saveRegions();
|
||||
} else if (subCommand.equals("regen") && p.hasPermission("regions.regen")) {
|
||||
Region r = m_plugin.regionManager().nearestRegion(p.getLocation());
|
||||
if (r == null) {
|
||||
p.sendMessage("There are no regions in this world.");
|
||||
} else {
|
||||
m_plugin.regenRegionPost(r);
|
||||
p.sendMessage("Region post regenerated.");
|
||||
p.sendMessage("Regenerating region post...");
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
p.sendMessage("Region post regenerated.");
|
||||
});
|
||||
}
|
||||
} else if (subCommand.equals("save") && p.hasPermission("regions.create")) {
|
||||
m_plugin.saveRegions();
|
||||
p.sendMessage("Regions saved.");
|
||||
} else if (subCommand.equals("load") && p.hasPermission("regions.create")) {
|
||||
m_plugin.loadRegions();
|
||||
p.sendMessage("Regions loaded.");
|
||||
} else if (subCommand.equals("regenall") && p.hasPermission("regions.regen.all")) {
|
||||
for(Region r : m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld())) {
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(r, m_plugin);
|
||||
builder.build();
|
||||
});
|
||||
}
|
||||
p.sendMessage("Region posts will be regenerated");
|
||||
} else {
|
||||
p.sendMessage("Unknown operation. Options are create, remove, city.");
|
||||
p.sendMessage("Unknown operation. Options are: create, remove, regen.");
|
||||
}
|
||||
return true;
|
||||
}
|
99
src/main/java/us/camin/regions/commands/RegionOpCommand.java
Normal file
99
src/main/java/us/camin/regions/commands/RegionOpCommand.java
Normal file
@ -0,0 +1,99 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.RegionPostItemWatcher;
|
||||
|
||||
public class RegionOpCommand implements CommandExecutor, TabCompleter {
|
||||
Plugin m_plugin;
|
||||
|
||||
public RegionOpCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
ret.add("save");
|
||||
ret.add("load");
|
||||
ret.add("item");
|
||||
ret.add("compass");
|
||||
ret.add("chargeitem");
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
String subCommand = split[0];
|
||||
if (subCommand.equals("save") && sender.hasPermission("regions.create")) {
|
||||
m_plugin.saveRegions();
|
||||
sender.sendMessage("Regions saved.");
|
||||
} else if (subCommand.equals("load") && sender.hasPermission("regions.create")) {
|
||||
sender.sendMessage("Reloading regions...");
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
m_plugin.loadRegions();
|
||||
sender.sendMessage("Regions loaded.");
|
||||
});
|
||||
} else if (subCommand.equals("compass") && sender.hasPermission("regions.give-items.compass")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack compassItem = RegionPostItemWatcher.createCreateItem();
|
||||
if (split.length > 1) {
|
||||
compassItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(compassItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else if (subCommand.equals("item") && sender.hasPermission("regions.give-items.creator")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack createItem = RegionPostItemWatcher.createCreateItem();
|
||||
if (split.length > 1) {
|
||||
createItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(createItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else if (subCommand.equals("chargeitem") && sender.hasPermission("regions.give-items.charge")) {
|
||||
Player player = (Player)sender;
|
||||
ItemStack chargeItem = RegionPostItemWatcher.createChargeItem();
|
||||
if (split.length > 1) {
|
||||
chargeItem.setAmount(Integer.parseInt(split[1]));
|
||||
}
|
||||
HashMap<Integer, ItemStack> rejected = player.getInventory().addItem(chargeItem);
|
||||
for(ItemStack item : rejected.values()) {
|
||||
player.getLocation().getWorld().dropItem(player.getLocation(), item);
|
||||
}
|
||||
} else {
|
||||
sender.sendMessage("Unknown operation. Options are save, load, item, compass.");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionTabComplete implements TabCompleter {
|
||||
private Plugin m_plugin;
|
||||
|
||||
public RegionTabComplete(Plugin plugin) {
|
||||
m_plugin = plugin;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
if (!(sender instanceof Player)) {
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
Player p = (Player)sender;
|
||||
String fullName = String.join(" ", args);
|
||||
|
||||
ArrayList<String> ret = new ArrayList<String>();
|
||||
Collection<Region> regions = m_plugin.regionManager().regionsForWorld(p.getLocation().getWorld());
|
||||
for (Region r : regions) {
|
||||
if (r.name().startsWith(fullName)) {
|
||||
ret.add(r.name());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
70
src/main/java/us/camin/regions/commands/RegionsCommand.java
Normal file
70
src/main/java/us/camin/regions/commands/RegionsCommand.java
Normal file
@ -0,0 +1,70 @@
|
||||
package us.camin.regions.commands;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.command.TabCompleter;
|
||||
import org.bukkit.World;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionsCommand implements CommandExecutor, TabCompleter {
|
||||
Plugin m_plugin;
|
||||
|
||||
public RegionsCommand(Plugin p) {
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> ret = new ArrayList<String>();
|
||||
for(World w : m_plugin.getServer().getWorlds()) {
|
||||
ret.add(w.getName());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] split) {
|
||||
World world = null;
|
||||
if (sender instanceof Player) {
|
||||
Player p = (Player)sender;
|
||||
world = p.getLocation().getWorld();
|
||||
}
|
||||
if (split.length >= 0) {
|
||||
world = m_plugin.getServer().getWorld(String.join(" ", split));
|
||||
}
|
||||
|
||||
if (world == null) {
|
||||
sender.sendMessage("Please specify a world.");
|
||||
return true;
|
||||
}
|
||||
|
||||
sender.sendMessage("Regions in this world:");
|
||||
for (Region r : m_plugin.regionManager().regionsForWorld(world)) {
|
||||
sender.sendMessage(r.coloredName());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,75 @@
|
||||
package us.camin.regions.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.List;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
import java.util.UUID;
|
||||
|
||||
public class RegionConfiguration implements ConfigurationSerializable {
|
||||
public int x;
|
||||
public int y;
|
||||
public int z;
|
||||
public int visits;
|
||||
public int charges;
|
||||
public boolean isHub;
|
||||
public List<Pattern> patterns;
|
||||
public List<UUID> seenBy;
|
||||
public DyeColor color = DyeColor.YELLOW;
|
||||
|
||||
public RegionConfiguration(Region region) {
|
||||
Location loc = region.location();
|
||||
x = loc.getBlockX();
|
||||
y = loc.getBlockY();
|
||||
z = loc.getBlockZ();
|
||||
charges = region.charges();
|
||||
isHub = region.isHub();
|
||||
visits = region.visits();
|
||||
patterns = region.bannerPatterns();
|
||||
color = region.color();
|
||||
seenBy = region.seenPlayers();
|
||||
}
|
||||
|
||||
public RegionConfiguration(Map<String, Object> confSection) {
|
||||
x = (Integer)confSection.get("x");
|
||||
y = (Integer)confSection.getOrDefault("y", -1);
|
||||
z = (Integer)confSection.get("z");
|
||||
isHub = (Boolean)confSection.getOrDefault("isHub", false);
|
||||
visits = (Integer)confSection.getOrDefault("visits", 0);
|
||||
charges = (Integer)confSection.getOrDefault("charges", 0);
|
||||
patterns = (List<Pattern>)confSection.getOrDefault("banner", new ArrayList<Pattern>());
|
||||
color = DyeColor.valueOf((String)confSection.getOrDefault("color", "YELLOW"));
|
||||
seenBy = new ArrayList<UUID>();
|
||||
List<String> strList = (List<String>)confSection.getOrDefault("seenBy", new ArrayList<String>());
|
||||
for(String s : strList) {
|
||||
seenBy.add(UUID.fromString(s));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
ret.put("x", x);
|
||||
ret.put("y", y);
|
||||
ret.put("z", z);
|
||||
ret.put("visits", visits);
|
||||
ret.put("charges", charges);
|
||||
ret.put("banner", patterns);
|
||||
List<String> strList = new ArrayList<String>();
|
||||
for(UUID uuid : seenBy) {
|
||||
strList.add(uuid.toString());
|
||||
}
|
||||
ret.put("seenBy", strList);
|
||||
ret.put("color", color.toString());
|
||||
ret.put("isHub", isHub);
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package us.camin.regions.config;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||
|
||||
public class WorldConfiguration implements ConfigurationSerializable {
|
||||
public Map<String, RegionConfiguration> regions = new HashMap<>();
|
||||
|
||||
public WorldConfiguration(Map<String, Object> confSection) {
|
||||
Map<String, Object> regionConfigs = (Map<String, Object>)confSection.get("regions");
|
||||
for(String regionName : regionConfigs.keySet()) {
|
||||
regions.put(regionName, new RegionConfiguration((Map<String, Object>)regionConfigs.get(regionName)));
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Object> serialize() {
|
||||
Map<String, Object> ret = new HashMap<>();
|
||||
Map<String, Object> regionConfigs = new HashMap<>();
|
||||
for(String regionName : regions.keySet()) {
|
||||
regionConfigs.put(regionName, regions.get(regionName).serialize());
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerAddRegionChargeEvent extends Event {
|
||||
private static final HandlerList s_handlers = new HandlerList();
|
||||
public final Region region;
|
||||
public final Player player;
|
||||
|
||||
public PlayerAddRegionChargeEvent(Player p, Region region ) {
|
||||
this.region = region;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return s_handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return s_handlers;
|
||||
}
|
||||
}
|
49
src/main/java/us/camin/regions/events/PlayerMoveInEvent.java
Normal file
49
src/main/java/us/camin/regions/events/PlayerMoveInEvent.java
Normal file
@ -0,0 +1,49 @@
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerMoveInEvent extends Event {
|
||||
|
||||
private static final HandlerList s_handlers = new HandlerList();
|
||||
public final Region region;
|
||||
public final Region oldRegion;
|
||||
public final Player player;
|
||||
|
||||
public PlayerMoveInEvent(Player p, Region region, Region oldRegion) {
|
||||
this.region = region;
|
||||
this.oldRegion = oldRegion;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return s_handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return s_handlers;
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerNearRegionPostEvent extends Event {
|
||||
private static final HandlerList s_handlers = new HandlerList();
|
||||
public final Region region;
|
||||
public final Player player;
|
||||
|
||||
public PlayerNearRegionPostEvent(Player p, Region region) {
|
||||
this.region = region;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return s_handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return s_handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -18,6 +18,31 @@ package us.camin.regions;
|
||||
*
|
||||
*/
|
||||
|
||||
public interface RegionAPI {
|
||||
public RegionManager regionManager();
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerPostInteractEvent extends Event {
|
||||
|
||||
private static final HandlerList s_handlers = new HandlerList();
|
||||
public final Region region;
|
||||
public final Player player;
|
||||
|
||||
public PlayerPostInteractEvent(Player p, Region region) {
|
||||
this.region = region;
|
||||
this.player = p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return s_handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return s_handlers;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -20,6 +20,9 @@ package us.camin.regions;
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PlayerRegionChangeEvent extends Event {
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -18,9 +18,10 @@ package us.camin.regions;
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionCreateEvent extends RegionEvent {
|
||||
public static final HandlerList s_handlers = new HandlerList();
|
||||
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -21,6 +21,8 @@ package us.camin.regions;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public abstract class RegionEvent extends Event {
|
||||
private static final HandlerList s_handlers = new HandlerList();
|
||||
public final Region region;
|
@ -1,4 +1,4 @@
|
||||
package us.camin.regions;
|
||||
package us.camin.regions.events;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
@ -18,9 +18,10 @@ package us.camin.regions;
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class RegionRemoveEvent extends RegionEvent {
|
||||
public static final HandlerList s_handlers = new HandlerList();
|
||||
|
248
src/main/java/us/camin/regions/geometry/BorderMesh.java
Normal file
248
src/main/java/us/camin/regions/geometry/BorderMesh.java
Normal file
@ -0,0 +1,248 @@
|
||||
package us.camin.regions.geometry;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import io.github.jdiemke.triangulation.DelaunayTriangulator;
|
||||
import io.github.jdiemke.triangulation.NotEnoughPointsException;
|
||||
import io.github.jdiemke.triangulation.Vector2D;
|
||||
import io.github.jdiemke.triangulation.Triangle2D;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
public class BorderMesh {
|
||||
Logger log = Logger.getLogger("Regions.Geometry.BorderMesh");
|
||||
Collection<Region> m_regions;
|
||||
Map<Region, Polygon> m_polygons;
|
||||
Map<Region, Set<Region>> m_neighbors;
|
||||
|
||||
public Collection<Region> neighbors(Region region) {
|
||||
Collection<Region> ret = new ArrayList<Region>();
|
||||
if (m_neighbors.containsKey(region)) {
|
||||
Collection<Region> allNeighbors = m_neighbors.get(region);
|
||||
if (false /*isFrontier(region)*/) {
|
||||
//log.trace("Region " + region.name() + " is a frontier");
|
||||
for(Region neighbor : allNeighbors) {
|
||||
if (!isFrontier(neighbor)) {
|
||||
ret.add(neighbor);
|
||||
} else {
|
||||
//log.trace("Not linking " + region.name() + " to " + neighbor.name() + " as it is also a frontier");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//log.trace("Region " + region.name() + " is not a frontier");
|
||||
for(Region neighbor : allNeighbors) {
|
||||
ret.add(neighbor);
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public BorderMesh(Collection<Region> regions) {
|
||||
m_regions = regions;
|
||||
m_polygons = new HashMap<Region, Polygon>();
|
||||
m_neighbors = new HashMap<Region, Set<Region>>();
|
||||
}
|
||||
|
||||
public class Polygon {
|
||||
public double x[];
|
||||
public double y[];
|
||||
public double z[];
|
||||
|
||||
public Polygon(List<Vector2D> points) {
|
||||
x = new double[points.size()];
|
||||
y = new double[points.size()];
|
||||
z = new double[points.size()];
|
||||
|
||||
for(int i = 0; i < points.size(); i++) {
|
||||
Vector2D borderPoint = points.get(i);
|
||||
if (Double.isNaN(borderPoint.x) || Double.isNaN(borderPoint.y)) {
|
||||
continue;
|
||||
}
|
||||
//log.info("Coords " + borderPoint.x + ", " + borderPoint.y);
|
||||
x[i] = borderPoint.x;
|
||||
y[i] = 64;
|
||||
z[i] = borderPoint.y;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean contains(double testx, double testy) {
|
||||
return crossings(testx, testy) % 2 == 0;
|
||||
}
|
||||
|
||||
public int crossings(double testx, double testy) {
|
||||
// winding rule algorithm
|
||||
int nvert = x.length;
|
||||
int i, j;
|
||||
int crossings = 0;
|
||||
for (i = 0, j = nvert-1; i < nvert; j = i++) {
|
||||
if ( ((z[i]>testy) != (z[j]>testy)) &&
|
||||
(testx < (x[j]-x[i]) * (testy-z[i]) / (z[j]-z[i]) + x[i]) )
|
||||
crossings++;
|
||||
}
|
||||
return crossings;
|
||||
}
|
||||
}
|
||||
|
||||
public Polygon polygonForRegion(Region r) {
|
||||
return m_polygons.get(r);
|
||||
}
|
||||
|
||||
public boolean triangulate() {
|
||||
// Create a list of points that we'll then use Delaunay on to form a mesh
|
||||
List<Vector2D> regionPoints = new ArrayList<Vector2D>();
|
||||
for (Region r : m_regions) {
|
||||
Location loc = r.location();
|
||||
Vector2D vec = new Vector2D(loc.getBlockX(), loc.getBlockZ());
|
||||
regionPoints.add(vec);
|
||||
}
|
||||
DelaunayTriangulator mesh = new DelaunayTriangulator(regionPoints);
|
||||
try {
|
||||
mesh.triangulate();
|
||||
log.info("Mesh triangulated!");
|
||||
} catch (NullPointerException e) {
|
||||
log.warning("Got a null pointer when triangulating, skipping world.");
|
||||
return false;
|
||||
} catch (NotEnoughPointsException e) {
|
||||
log.info("Not enough points to triangulate mesh. Add more regions!");
|
||||
return false;
|
||||
}
|
||||
|
||||
ArrayList<Triangle> triangleSoup = new ArrayList<Triangle>();
|
||||
|
||||
for(Region region : m_regions) {
|
||||
log.info("Creating region mesh for " + region.name());
|
||||
Location loc = region.location();
|
||||
Vector2D regionCenter = new Vector2D(loc.getBlockX(), loc.getBlockZ());
|
||||
|
||||
for(Triangle2D tri : mesh.getTriangles()) {
|
||||
if (vecEquals(tri.a, regionCenter)) {
|
||||
triangleSoup.add(new Triangle(tri, region));
|
||||
} else if (vecEquals(tri.b, regionCenter)) {
|
||||
triangleSoup.add(new Triangle(tri, region));
|
||||
} else if (vecEquals(tri.c, regionCenter)) {
|
||||
triangleSoup.add(new Triangle(tri, region));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now we go back through our region mesh to generate vornoi points
|
||||
for(Region region : m_regions) {
|
||||
ArrayList<Vector2D> points = new ArrayList<Vector2D>();
|
||||
HashSet<Region> neighbors = new HashSet<Region>();
|
||||
log.info("Executing voronoi transform...");
|
||||
for(Triangle tri : triangleSoup) {
|
||||
if (tri.region == region) {
|
||||
for (Region neighbor : m_regions) {
|
||||
if (neighbor == region) {
|
||||
continue;
|
||||
}
|
||||
Location neighborLoc = neighbor.location();
|
||||
Vector2D neighborCenter = new Vector2D(neighborLoc.getBlockX(), neighborLoc.getBlockZ());
|
||||
if (vecEquals(tri.a, neighborCenter) || vecEquals(tri.b, neighborCenter) || vecEquals(tri.c, neighborCenter)) {
|
||||
neighbors.add(neighbor);
|
||||
}
|
||||
}
|
||||
points.add(tri.circumcenter());
|
||||
}
|
||||
}
|
||||
|
||||
// Sort points into a renderable polygon based on direction to center
|
||||
Location loc = region.location();
|
||||
Vector2D regionCenter = new Vector2D(loc.getBlockX(), loc.getBlockZ());
|
||||
points.sort((Vector2D a, Vector2D b) -> Double.compare(direction(a, regionCenter), direction(b, regionCenter)));
|
||||
log.info("Border for " + region.name() + " is defined by " + points.size() + " points");
|
||||
Polygon polygon = new Polygon(points);
|
||||
m_polygons.put(region, polygon);
|
||||
m_neighbors.put(region, neighbors);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*public boolean validNeighbors(Region regionA, Region regionB) {
|
||||
Polygon polyA = polygonForRegion(regionA);
|
||||
Polygon polyB = polygonForRegion(regionA);
|
||||
Location center = region.location();
|
||||
if (poly.contains(center.getBlockX(), center.getBlockZ())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}*/
|
||||
|
||||
public boolean isFrontier(Region region) {
|
||||
Polygon poly = polygonForRegion(region);
|
||||
Location center = region.location();
|
||||
if (poly.contains(center.getBlockX(), center.getBlockZ())) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean vecEquals(Vector2D a, Vector2D b) {
|
||||
return a.x == b.x && a.y == b.y;
|
||||
}
|
||||
|
||||
class Triangle {
|
||||
Vector2D a;
|
||||
Vector2D b;
|
||||
Vector2D c;
|
||||
Region region;
|
||||
|
||||
public Triangle(Vector2D a, Vector2D b, Vector2D c, Region region) {
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public Triangle(Triangle2D tri, Region region) {
|
||||
this.a = tri.a;
|
||||
this.b = tri.b;
|
||||
this.c = tri.c;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public boolean equals(Triangle o) {
|
||||
return vecEquals(o.a, a) && vecEquals(o.b, b) && vecEquals(o.c, c);
|
||||
}
|
||||
|
||||
private Vector2D midpoint(Vector2D a, Vector2D b) {
|
||||
return new Vector2D((a.x + b.x) / 2, (a.y + b.y) / 2);
|
||||
}
|
||||
|
||||
private double slope(Vector2D from, Vector2D to) {
|
||||
return (to.y - from.y) / (to.x - from.x);
|
||||
}
|
||||
|
||||
public Vector2D circumcenter() {
|
||||
Vector2D midAB = midpoint(a, b);
|
||||
Vector2D midBC = midpoint(b, c);
|
||||
|
||||
double slopeAB = -1 / slope(a, b);
|
||||
double slopeBC = -1 / slope(b, c);
|
||||
|
||||
double bAB = midAB.y - slopeAB * midAB.x;
|
||||
double bBC = midBC.y - slopeBC * midBC.x;
|
||||
|
||||
double x = (bAB - bBC) / (slopeBC - slopeAB);
|
||||
|
||||
return new Vector2D(x, (slopeAB * x) + bAB);
|
||||
}
|
||||
}
|
||||
|
||||
private double direction(Vector2D a, Vector2D b) {
|
||||
double dir = Math.atan2(a.y - b.y, a.x - b.x);
|
||||
return dir;
|
||||
}
|
||||
}
|
59
src/main/java/us/camin/regions/geometry/RegionSet.java
Normal file
59
src/main/java/us/camin/regions/geometry/RegionSet.java
Normal file
@ -0,0 +1,59 @@
|
||||
package us.camin.regions.geometry;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
|
||||
import org.bukkit.Location;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.AbstractSet;
|
||||
import java.util.Set;
|
||||
import java.util.Iterator;
|
||||
|
||||
public class RegionSet extends AbstractSet<Region> {
|
||||
private Set<Region> m_regions = new HashSet<Region>();
|
||||
|
||||
public Iterator<Region> iterator() {
|
||||
return m_regions.iterator();
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return m_regions.size();
|
||||
}
|
||||
|
||||
public Region nearestRegion(Location loc) {
|
||||
Region nearest = null;
|
||||
int minDistance = -1;
|
||||
for(Region r : m_regions) {
|
||||
int check = r.distanceTo(loc);
|
||||
if (minDistance == -1 || check < minDistance) {
|
||||
nearest = r;
|
||||
minDistance = check;
|
||||
}
|
||||
}
|
||||
return nearest;
|
||||
}
|
||||
|
||||
public boolean add(Region r) {
|
||||
boolean ret = m_regions.add(r);
|
||||
if (ret) {
|
||||
m_mesh = new BorderMesh(m_regions);
|
||||
m_mesh.triangulate();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public boolean remove(Region r) {
|
||||
boolean ret = m_regions.remove(r);
|
||||
if (ret) {
|
||||
m_mesh = new BorderMesh(m_regions);
|
||||
m_mesh.triangulate();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public BorderMesh borders() {
|
||||
return m_mesh;
|
||||
}
|
||||
|
||||
BorderMesh m_mesh = null;
|
||||
}
|
72
src/main/java/us/camin/regions/ui/Colors.java
Normal file
72
src/main/java/us/camin/regions/ui/Colors.java
Normal file
@ -0,0 +1,72 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.DyeColor;
|
||||
|
||||
public class Colors {
|
||||
public static ChatColor[] regionColors = {
|
||||
ChatColor.AQUA,
|
||||
ChatColor.BLACK,
|
||||
ChatColor.BLUE,
|
||||
ChatColor.BOLD,
|
||||
ChatColor.DARK_AQUA,
|
||||
ChatColor.DARK_BLUE,
|
||||
ChatColor.DARK_GRAY,
|
||||
ChatColor.DARK_GREEN,
|
||||
ChatColor.DARK_PURPLE,
|
||||
ChatColor.DARK_RED,
|
||||
ChatColor.GOLD,
|
||||
ChatColor.GRAY,
|
||||
ChatColor.GREEN,
|
||||
ChatColor.LIGHT_PURPLE,
|
||||
ChatColor.RED,
|
||||
ChatColor.WHITE,
|
||||
ChatColor.YELLOW,
|
||||
};
|
||||
|
||||
public static ChatColor chatColorForName(String name) {
|
||||
int colorCount = regionColors.length;
|
||||
int hashed = Math.abs(name.hashCode());
|
||||
return regionColors[hashed % (colorCount - 1)];
|
||||
}
|
||||
|
||||
public static ChatColor chatColorForColor(DyeColor color) {
|
||||
switch (color) {
|
||||
case BLACK:
|
||||
return ChatColor.BLACK;
|
||||
case BLUE:
|
||||
return ChatColor.BLUE;
|
||||
case BROWN:
|
||||
return ChatColor.DARK_RED;
|
||||
case CYAN:
|
||||
return ChatColor.AQUA;
|
||||
case GRAY:
|
||||
return ChatColor.GRAY;
|
||||
case GREEN:
|
||||
return ChatColor.GREEN;
|
||||
case LIGHT_BLUE:
|
||||
return ChatColor.BLUE;
|
||||
case LIGHT_GRAY:
|
||||
return ChatColor.GRAY;
|
||||
case LIME:
|
||||
return ChatColor.GREEN;
|
||||
case MAGENTA:
|
||||
return ChatColor.LIGHT_PURPLE;
|
||||
case ORANGE:
|
||||
return ChatColor.GOLD;
|
||||
case PINK:
|
||||
return ChatColor.RED;
|
||||
case PURPLE:
|
||||
return ChatColor.DARK_PURPLE;
|
||||
case RED:
|
||||
return ChatColor.RED;
|
||||
case WHITE:
|
||||
return ChatColor.WHITE;
|
||||
case YELLOW:
|
||||
return ChatColor.YELLOW;
|
||||
}
|
||||
return ChatColor.WHITE;
|
||||
}
|
||||
}
|
210
src/main/java/us/camin/regions/ui/PlayerInventoryTeleporter.java
Normal file
210
src/main/java/us/camin/regions/ui/PlayerInventoryTeleporter.java
Normal file
@ -0,0 +1,210 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.Event.Result;
|
||||
import org.bukkit.DyeColor;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.CompassMeta;
|
||||
import org.bukkit.inventory.meta.BannerMeta;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.material.MaterialData;
|
||||
|
||||
import us.camin.regions.Plugin;
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.RegionManager;
|
||||
import us.camin.regions.events.PlayerPostInteractEvent;
|
||||
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.lang.Math;
|
||||
|
||||
public class PlayerInventoryTeleporter implements Listener {
|
||||
Map<Player, Inventory> m_playerInventories;
|
||||
Plugin m_plugin;
|
||||
RegionManager m_manager;
|
||||
|
||||
public PlayerInventoryTeleporter(Plugin plugin, RegionManager manager) {
|
||||
m_plugin = plugin;
|
||||
m_manager = manager;
|
||||
m_playerInventories = new HashMap<>();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onInventory(InventoryClickEvent event) {
|
||||
if (event.getCurrentItem() == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
HumanEntity clicker = event.getWhoClicked();
|
||||
|
||||
if (clicker instanceof Player) {
|
||||
Player player = (Player)clicker;
|
||||
Inventory neighborInv = m_playerInventories.get(player);
|
||||
if (neighborInv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.getView().getTopInventory() == neighborInv) {
|
||||
event.setResult(Result.DENY);
|
||||
event.setCancelled(true);
|
||||
}
|
||||
|
||||
if (event.getClickedInventory() == neighborInv) {
|
||||
ItemMeta meta = event.getCurrentItem().getItemMeta();
|
||||
Material mat = event.getCurrentItem().getType();
|
||||
if (mat == Material.BEDROCK || mat == Material.COMPASS || mat == Material.LANTERN) {
|
||||
return;
|
||||
}
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> event.getView().close());
|
||||
Region nearest = m_manager.nearestRegion(player.getLocation());
|
||||
|
||||
final String selectedName = meta.getDisplayName();
|
||||
final Optional<Region> destination = m_plugin.regionManager().regionsForWorld(player.getLocation().getWorld())
|
||||
.stream()
|
||||
.filter((r) -> r.name().equals(selectedName))
|
||||
.findFirst();
|
||||
if (destination.isPresent()) {
|
||||
player.sendMessage("Teleporting you there now...");
|
||||
nearest.addCharges(-1);
|
||||
destination.get().addCharges(1);
|
||||
m_plugin.getServer().getScheduler().runTask(m_plugin, () -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(nearest, m_plugin);
|
||||
builder.updateLantern();
|
||||
});
|
||||
m_plugin.saveRegions();
|
||||
new PlayerTeleporter(player, nearest.teleportLocation(), destination.get().teleportLocation(), m_plugin).teleport().thenRun(() -> {
|
||||
RegionPostBuilder builder = new RegionPostBuilder(destination.get(), m_plugin);
|
||||
builder.updateLantern();
|
||||
});
|
||||
if (nearest.charges() == 0) {
|
||||
nearest.location().getWorld().playSound(player.getLocation(), Sound.ENTITY_ITEM_BREAK, (float)1.0, (float)1.0);
|
||||
//player.sendMessage("You've consumed this region post's last charge! You won't be able to return without recharging it.");
|
||||
}
|
||||
} else {
|
||||
player.sendMessage("There is no region with that name. This is a bug.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerInteract(PlayerPostInteractEvent event) {
|
||||
Collection<Region> nearby = m_manager.neighborsForRegion(event.region);
|
||||
Collection<Region> hubs = m_manager.worldHubs(event.region.location().getWorld());
|
||||
if (!m_playerInventories.containsKey(event.player)) {
|
||||
m_playerInventories.put(event.player, Bukkit.createInventory(null, InventoryType.CHEST, "Nearby Regions"));
|
||||
}
|
||||
Inventory neighborInventory = m_playerInventories.get(event.player);
|
||||
neighborInventory.clear();
|
||||
|
||||
ArrayList<Region> sorted = new ArrayList<Region>();
|
||||
ArrayList<String> foundNames = new ArrayList<String>();
|
||||
Region nearest = m_manager.nearestRegion(event.player.getLocation());
|
||||
for(Region r : nearby) {
|
||||
if (!r.name().equals(nearest.name())) {
|
||||
foundNames.add(r.name());
|
||||
sorted.add(r);
|
||||
}
|
||||
}
|
||||
for(Region r : hubs) {
|
||||
if (!foundNames.contains(r.name()) && !r.name().equals(nearest.name())) {
|
||||
foundNames.add(r.name());
|
||||
sorted.add(r);
|
||||
}
|
||||
}
|
||||
sorted.sort((Region a, Region b) -> Integer.compare(b.visits(), a.visits()));
|
||||
|
||||
for(Region region : sorted) {
|
||||
boolean isHub = hubs.contains(region);
|
||||
boolean visible = isHub || region.seenByPlayer(event.player) || event.player.hasPermission("regions.bypass.discovery");
|
||||
ItemStack item;
|
||||
if (visible) {
|
||||
item = region.icon();
|
||||
} else {
|
||||
item = new ItemStack(Material.BEDROCK);
|
||||
}
|
||||
ItemMeta meta = item.getItemMeta();
|
||||
meta.setDisplayName(region.name());
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
Location center = region.location();
|
||||
int altitude = center.getBlockY();
|
||||
if (visible) {
|
||||
if (isHub) {
|
||||
lore.add("" + ChatColor.GOLD + ChatColor.BOLD + "World hub" + ChatColor.GOLD + " - Accessable from anywhere");
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
}
|
||||
lore.add(ChatColor.WHITE + "Distance: " + ChatColor.YELLOW + Math.round(region.location().distance(event.region.location())));
|
||||
lore.add(ChatColor.WHITE + "Population: " + ChatColor.YELLOW + m_plugin.playerWatcher().playersInRegion(region).size());
|
||||
lore.add(ChatColor.WHITE + "Altitude: " + ChatColor.YELLOW + altitude);
|
||||
Collection<Region> neighborNeighbors = m_manager.neighborsForRegion(region);
|
||||
ArrayList<String> neighborNames = new ArrayList<String>();
|
||||
for(Region r : neighborNeighbors) {
|
||||
if (!foundNames.contains(r.name())) {
|
||||
neighborNames.add(r.coloredName());
|
||||
}
|
||||
}
|
||||
lore.add("Nearby connections: " + String.join(", ", neighborNames));
|
||||
} else {
|
||||
lore.add("" + ChatColor.BOLD + ChatColor.GOLD + "You haven't discovered this location yet!");
|
||||
lore.add(ChatColor.WHITE + "Distance: " + ChatColor.YELLOW + ChatColor.MAGIC + Math.round(region.location().distance(event.region.location())));
|
||||
lore.add(ChatColor.WHITE + "Population: " + ChatColor.YELLOW + ChatColor.MAGIC + m_plugin.playerWatcher().playersInRegion(region).size());
|
||||
lore.add(ChatColor.WHITE + "Altitude: " + ChatColor.YELLOW + ChatColor.MAGIC + altitude);
|
||||
lore.add(ChatColor.GOLD + "Coordinates: " + ChatColor.YELLOW + region.location().getX() + ", "+ region.location().getZ());
|
||||
}
|
||||
meta.setLore(lore);
|
||||
item.setItemMeta(meta);
|
||||
neighborInventory.addItem(item);
|
||||
}
|
||||
ItemStack chargesItem = new ItemStack(event.region.charges() == 0 ? Material.SOUL_LANTERN : Material.LANTERN);
|
||||
ItemMeta meta = chargesItem.getItemMeta();
|
||||
meta.setDisplayName(ChatColor.BOLD + "Region Post Configuration");
|
||||
ArrayList<String> lore = new ArrayList<String>();
|
||||
lore.add(ChatColor.WHITE + "Name: "+event.region.coloredName());
|
||||
lore.add(ChatColor.WHITE + "Visits: " + ChatColor.YELLOW + event.region.visits());
|
||||
lore.add(ChatColor.WHITE + "Charges remaining: " + (event.region.charges() == 0 ? ChatColor.RED : ChatColor.GREEN) + event.region.charges());
|
||||
meta.setLore(lore);
|
||||
meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
|
||||
meta.addEnchant(Enchantment.SOUL_SPEED, 1, true);
|
||||
chargesItem.setItemMeta(meta);
|
||||
// 22 Is the middle of the bottom row
|
||||
neighborInventory.setItem(22, chargesItem);
|
||||
|
||||
event.player.openInventory(neighborInventory);
|
||||
}
|
||||
}
|
88
src/main/java/us/camin/regions/ui/PlayerTeleporter.java
Normal file
88
src/main/java/us/camin/regions/ui/PlayerTeleporter.java
Normal file
@ -0,0 +1,88 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Sound;
|
||||
import io.papermc.lib.PaperLib;
|
||||
import us.camin.regions.Plugin;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.potion.PotionEffectType;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class PlayerTeleporter {
|
||||
Logger log = Logger.getLogger("Regions.PlayerTeleporter");
|
||||
|
||||
private Player m_player;
|
||||
private Location m_src;
|
||||
private Location m_dest;
|
||||
private Plugin m_plugin;
|
||||
|
||||
public PlayerTeleporter(Player p, Location src, Location dest, Plugin plugin) {
|
||||
this.m_player = p;
|
||||
this.m_src = src;
|
||||
this.m_dest = dest;
|
||||
this.m_plugin = plugin;
|
||||
}
|
||||
|
||||
public CompletableFuture<Void> teleport() {
|
||||
CompletableFuture<Void> ret = new CompletableFuture<Void>();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
|
||||
BukkitTask hoverGenerator = scheduler.runTaskTimer(m_plugin, () -> applyHoverEffect(), 0, 10);
|
||||
BukkitTask particleGenerator = scheduler.runTaskTimer(m_plugin, () -> spawnHoverParticles(), 0, 1);
|
||||
playTeleportSound();
|
||||
|
||||
m_plugin.getServer().getScheduler().runTaskLater(m_plugin, () -> {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, 20 * 3 + 120, 1, false, false, false));
|
||||
}, 20 * 3);
|
||||
|
||||
m_plugin.getServer().getScheduler().runTaskLater(m_plugin, () -> {
|
||||
spawnTeleportStartParticles();
|
||||
PaperLib.teleportAsync(m_player, m_dest, TeleportCause.COMMAND).thenAccept(res -> {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 60, 1, false, false, false));
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, 40, 1, false, false, false));
|
||||
spawnEndParticles();
|
||||
particleGenerator.cancel();
|
||||
hoverGenerator.cancel();
|
||||
ret.complete(null);
|
||||
});
|
||||
}, 20 * 6);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void spawnTeleportStartParticles() {
|
||||
World world = m_dest.getWorld();
|
||||
world.spawnParticle(Particle.CLOUD, m_dest, 70, 1, 1, 1);
|
||||
}
|
||||
|
||||
void spawnEndParticles() {
|
||||
World world = m_player.getLocation().getWorld();
|
||||
world.playSound(m_dest, Sound.BLOCK_PORTAL_TRAVEL, (float)0.5, (float)1.0);
|
||||
world.spawnParticle(Particle.CLOUD, m_dest, 70, 1, 1, 1);
|
||||
world.spawnParticle(Particle.SPELL_MOB, m_dest, 5, 2, 2, 2);
|
||||
world.spawnParticle(Particle.PORTAL, m_player.getLocation(), 70, 1, 1, 1);
|
||||
}
|
||||
|
||||
void applyHoverEffect() {
|
||||
m_player.addPotionEffect(new PotionEffect(PotionEffectType.LEVITATION, 10, 1, false, false, false));
|
||||
}
|
||||
|
||||
void spawnHoverParticles() {
|
||||
World w = m_player.getLocation().getWorld();
|
||||
w.spawnParticle(Particle.SPELL_MOB, m_dest, 5, 1, 1, 1);
|
||||
w.spawnParticle(Particle.SPELL_MOB, m_src, 5, 2, 2, 2);
|
||||
}
|
||||
|
||||
void playTeleportSound() {
|
||||
m_src.getWorld().playSound(m_src, Sound.BLOCK_PORTAL_TRIGGER, (float)0.5, (float)0.6);
|
||||
m_src.getWorld().playSound(m_src, Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, (float)0.5, (float)1.0);
|
||||
m_src.getWorld().playSound(m_dest, Sound.BLOCK_RESPAWN_ANCHOR_CHARGE, (float)0.5, (float)1.0);
|
||||
}
|
||||
}
|
231
src/main/java/us/camin/regions/ui/RegionPostBuilder.java
Normal file
231
src/main/java/us/camin/regions/ui/RegionPostBuilder.java
Normal file
@ -0,0 +1,231 @@
|
||||
package us.camin.regions.ui;
|
||||
|
||||
/**
|
||||
* This file is part of Regions
|
||||
*
|
||||
* Regions is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Regions is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Regions. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.block.data.Directional;
|
||||
import org.bukkit.block.Banner;
|
||||
import org.bukkit.block.data.type.Lantern;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import java.util.logging.Logger;
|
||||
import java.lang.Runnable;
|
||||
|
||||
import us.camin.regions.Region;
|
||||
import us.camin.regions.Plugin;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Color;
|
||||
|
||||
public class RegionPostBuilder {
|
||||
Logger log = Logger.getLogger("Regions.RegionPostBuilder");
|
||||
Plugin m_plugin;
|
||||
Region m_region;
|
||||
public RegionPostBuilder(Region r, Plugin p) {
|
||||
m_region = r;
|
||||
m_plugin = p;
|
||||
}
|
||||
|
||||
private final Material[] bannerTypes = {
|
||||
Material.WHITE_WALL_BANNER,
|
||||
Material.YELLOW_WALL_BANNER,
|
||||
Material.BLUE_WALL_BANNER,
|
||||
Material.BLACK_WALL_BANNER,
|
||||
Material.BROWN_WALL_BANNER,
|
||||
Material.CYAN_WALL_BANNER,
|
||||
Material.GREEN_WALL_BANNER,
|
||||
Material.LIGHT_BLUE_WALL_BANNER,
|
||||
Material.GRAY_WALL_BANNER,
|
||||
Material.LIGHT_GRAY_WALL_BANNER,
|
||||
Material.LIME_WALL_BANNER,
|
||||
Material.MAGENTA_WALL_BANNER,
|
||||
Material.ORANGE_WALL_BANNER,
|
||||
Material.PINK_WALL_BANNER,
|
||||
Material.PURPLE_WALL_BANNER,
|
||||
Material.RED_WALL_BANNER,
|
||||
};
|
||||
|
||||
boolean isBannerBlock(Block block) {
|
||||
return Tag.BANNERS.isTagged(block.getType());
|
||||
}
|
||||
|
||||
/*void buildPad(Location center) {
|
||||
World world = m_region.location().getWorld();
|
||||
// Fill in the cobblestone pad
|
||||
for(int x = -1;x <= 1;x++) {
|
||||
for(int z = -1;z <= 1;z++) {
|
||||
Block b = world.getBlockAt(center.getBlockX() + x, center.getBlockY(), center.getBlockZ() + z);
|
||||
if (b.getType() != Material.COBBLESTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_STONE_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, center, 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
|
||||
void buildPost(Location center) {
|
||||
World world = m_region.location().getWorld();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
|
||||
// Draw the glowstone base of the tower
|
||||
Block b = world.getBlockAt(center.getBlockX(), center.getBlockY() + 1, center.getBlockZ());
|
||||
if (b.getType() != Material.GLOWSTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.GLOWSTONE);
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_GLASS_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, b.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
if (markerBlock.getType() != m_region.blockMaterial()) {
|
||||
markerBlock.breakNaturally();
|
||||
markerBlock.setType(m_region.blockMaterial());
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, markerBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}, 15);
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
Block lanternBlock = markerBlock.getRelative(BlockFace.UP);
|
||||
Material lanternType = (m_region.charges() > 0) ? Material.LANTERN : Material.SOUL_LANTERN;
|
||||
if (lanternBlock.getType() != Material.LANTERN && lanternBlock.getType() != Material.SOUL_LANTERN) {
|
||||
lanternBlock.breakNaturally();
|
||||
world.playSound(center, Sound.BLOCK_LANTERN_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, lanternBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
lanternBlock.setType(lanternType);
|
||||
Lantern lanternData = (Lantern)lanternBlock.getBlockData();
|
||||
lanternData.setHanging(false);
|
||||
lanternBlock.setBlockData(lanternData);
|
||||
}, 30);
|
||||
}*/
|
||||
|
||||
public void build() {
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
scheduler.runTask(m_plugin, new PadBuilder());
|
||||
scheduler.runTaskLater(m_plugin, new PostBuilder(), 20);
|
||||
scheduler.runTaskLater(m_plugin, new BannerBuilder(), 20 * 2);
|
||||
scheduler.runTaskLater(m_plugin, new LanternBuilder(), 20 * 3);
|
||||
}
|
||||
|
||||
public void updateLantern() {
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
scheduler.runTask(m_plugin, new LanternBuilder());
|
||||
}
|
||||
|
||||
public class PadBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
// Fill in the cobblestone pad
|
||||
for(int x = -1;x <= 1;x++) {
|
||||
for(int z = -1;z <= 1;z++) {
|
||||
Block b = world.getBlockAt(center.getBlockX() + x, center.getBlockY(), center.getBlockZ() + z);
|
||||
if (b.getType() != Material.COBBLESTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.COBBLESTONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_STONE_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, center, 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}
|
||||
|
||||
public class PostBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
BukkitScheduler scheduler = m_plugin.getServer().getScheduler();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
|
||||
// Draw the glowstone base of the tower
|
||||
Block b = world.getBlockAt(center.getBlockX(), center.getBlockY() + 1, center.getBlockZ());
|
||||
if (b.getType() != Material.GLOWSTONE) {
|
||||
b.breakNaturally();
|
||||
b.setType(Material.GLOWSTONE);
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_GLASS_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, b.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
|
||||
scheduler.runTaskLater(m_plugin, () -> {
|
||||
if (markerBlock.getType() != m_region.blockMaterial()) {
|
||||
markerBlock.breakNaturally();
|
||||
markerBlock.setType(m_region.blockMaterial());
|
||||
world.playSound(b.getLocation(), Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, markerBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
}, 15);
|
||||
}
|
||||
}
|
||||
|
||||
public class BannerBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
// Place the banners
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
BlockFace[] directions = {BlockFace.NORTH, BlockFace.SOUTH, BlockFace.WEST, BlockFace.EAST};
|
||||
log.info("Rebuilding banners...");
|
||||
for(BlockFace face : directions) {
|
||||
Block b = markerBlock.getRelative(face);
|
||||
if (!isBannerBlock(b)) {
|
||||
b.breakNaturally();
|
||||
}
|
||||
b.setType(m_region.bannerBlockMaterial());
|
||||
Directional bannerDir = (Directional)b.getBlockData();
|
||||
bannerDir.setFacing(face);
|
||||
b.setBlockData(bannerDir);
|
||||
Banner bannerState = (Banner)b.getState();
|
||||
bannerState.setPatterns(m_region.bannerPatterns());
|
||||
bannerState.update();
|
||||
world.spawnParticle(Particle.CLOUD, markerBlock.getLocation().add(0.5, 0.5, 0.5), 10, 1, 1, 1);
|
||||
}
|
||||
world.playSound(center, Sound.BLOCK_WOOL_PLACE, (float)1.0, (float)1.0);
|
||||
}
|
||||
}
|
||||
|
||||
public class LanternBuilder implements Runnable {
|
||||
public void run() {
|
||||
World world = m_region.location().getWorld();
|
||||
Location center = m_region.location().clone().add(0, -1, 0);
|
||||
Block markerBlock = world.getBlockAt(center.getBlockX(), center.getBlockY() + 2, center.getBlockZ());
|
||||
Block lanternBlock = markerBlock.getRelative(BlockFace.UP);
|
||||
Material lanternType = (m_region.charges() > 0) ? Material.LANTERN : Material.SOUL_LANTERN;
|
||||
if (lanternBlock.getType() != Material.LANTERN && lanternBlock.getType() != Material.SOUL_LANTERN) {
|
||||
lanternBlock.breakNaturally();
|
||||
world.playSound(center, Sound.BLOCK_LANTERN_PLACE, (float)1.0, (float)1.0);
|
||||
world.spawnParticle(Particle.REDSTONE, lanternBlock.getLocation().add(0.5, 0.5, 0.5), 1000, 1, 1, 1, m_region.dustOptions());
|
||||
}
|
||||
lanternBlock.setType(lanternType);
|
||||
Lantern lanternData = (Lantern)lanternBlock.getBlockData();
|
||||
lanternData.setHanging(false);
|
||||
lanternBlock.setBlockData(lanternData);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +1,20 @@
|
||||
name: Regions
|
||||
main: us.camin.regions.Plugin
|
||||
author: Trever Fischer <wm161@wm161.net>
|
||||
website: http://camin.us/
|
||||
author: Torrie Fischer <tdfischer@hackerbots.net>
|
||||
website: http://hackerbots.net/
|
||||
version: ${version}
|
||||
softdepend: [dynmap]
|
||||
api-version: 1.16
|
||||
softdepend: [dynmap, HolographicDisplays, ProtocolLib]
|
||||
commands:
|
||||
regions:
|
||||
description: "List available regions."
|
||||
usage: /<command>
|
||||
regionop:
|
||||
description: "Region admin tools"
|
||||
usage: /<command> [args...]
|
||||
region:
|
||||
description: Interface to the region system
|
||||
usage: /<command> [args...]
|
||||
movein:
|
||||
description: "Sets your home region."
|
||||
usage: /<command>
|
||||
cityregion:
|
||||
description: "Teleports you to the world's city region."
|
||||
usage: /<command>
|
||||
homeregion:
|
||||
description: "Teleports you to your home region."
|
||||
usage: /<command>
|
||||
permissions:
|
||||
regions.*:
|
||||
default: op
|
||||
@ -24,13 +22,51 @@ permissions:
|
||||
children:
|
||||
regions.create: true
|
||||
regions.remove: true
|
||||
regions.city: true
|
||||
regions.regen.*: true
|
||||
regions.bypass.*: true
|
||||
regions.give-items.*: true
|
||||
regions.regen.*:
|
||||
default: op
|
||||
description: Allows regeneration of all regions
|
||||
children:
|
||||
regions.regen: true
|
||||
regions.regen.all: true
|
||||
regions.use:
|
||||
default: true
|
||||
description: Use region posts
|
||||
regions.create:
|
||||
default: op
|
||||
description: Create a region
|
||||
regions.remove:
|
||||
default: op
|
||||
description: Remove a region
|
||||
regions.city:
|
||||
regions.regen:
|
||||
default: op
|
||||
description: Regenerates a region post
|
||||
regions.regen.all:
|
||||
default: op
|
||||
description: Regenerates all region posts, including in unloaded chunks
|
||||
regions.bypass.*:
|
||||
default: op
|
||||
description: Bypasses all region post travel requirements
|
||||
children:
|
||||
regions.bypass.charges: true
|
||||
regions.bypass.discovery: true
|
||||
regions.bypass.charges:
|
||||
default: op
|
||||
description: Allows you to bypass post charge requirements
|
||||
regions.bypass.discovery:
|
||||
default: op
|
||||
description: Allows you to bypass discovery requirements
|
||||
regions.give-items.*:
|
||||
default: op
|
||||
children:
|
||||
regions.give-items.compass: true
|
||||
regions.give-items.charge: true
|
||||
regions.give-items.creator: true
|
||||
regions.give-items.compass:
|
||||
default: op
|
||||
regions.give-items.charge:
|
||||
default: op
|
||||
regions.give-items.creator:
|
||||
default: op
|
||||
description: Defines the city region
|
||||
|
Loading…
Reference in New Issue
Block a user