From a29484a825015cd8b06b5a28a2f1b0668d369f80 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Thu, 15 Jan 2015 00:47:03 +1100 Subject: [PATCH] World border --- .../intellectualcrafters/plot/PlotMain.java | 5 +-- .../intellectualcrafters/plot/config/C.java | 4 ++ .../plot/listeners/PlayerEvents.java | 20 ++++++++- .../plot/object/PlotWorld.java | 4 ++ .../plot/util/PlotHelper.java | 41 ++++++++++++++++++- 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java index d5ef44f40..3fe2dda28 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotMain.java @@ -928,22 +928,19 @@ import com.sk89q.worldguard.bukkit.WorldGuardPlugin; sendConsoleSenderMessage(C.PREFIX.s() + "&3 - plotworld: &7" + plotWorld.getClass().getName()); sendConsoleSenderMessage(C.PREFIX.s() + "&3 - manager: &7" + plotManager.getClass().getName()); } - if (!config.contains(path)) { config.createSection(path); } - plotWorld.saveConfiguration(config.getConfigurationSection(path)); plotWorld.loadDefaultConfiguration(config.getConfigurationSection(path)); - try { config.save(configFile); } catch (final IOException e) { e.printStackTrace(); } - // Now add it addPlotWorld(world, plotWorld, plotManager); + PlotHelper.setupBorder(world); } else { if (worlds.contains(world)) { sendConsoleSenderMessage("&cWorld '" + world + "' in settings.yml is not using PlotSquared generator!"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java index f2f903f7b..03d7e35f2 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -37,6 +37,10 @@ import com.intellectualsites.translation.bukkit.BukkitTranslation; * @author Citymonstret */ public enum C { + /* + * Border + */ + BORDER("&cYou are outside the current map border"), /* * Unclaim */ diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 698942527..52819307e 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -93,7 +93,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; * @author Citymonstret * @author Empire92 */ -@SuppressWarnings("unused") public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener { +public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener { @EventHandler public static void onWorldLoad(final WorldLoadEvent event) { @@ -136,6 +136,24 @@ import com.intellectualcrafters.plot.util.UUIDHandler; if (!isPlotWorld(player.getWorld())) { return; } + String worldname = q.getWorld().getName(); + if (PlotHelper.worldBorder.containsKey(worldname)) { + int border = PlotHelper.worldBorder.get(worldname); + boolean passed = false; + if (t.getBlockX() >= border) { + q.setX(border); + passed = true; + } + if (t.getBlockZ() >= border) { + q.setZ(border); + passed = true; + } + if (passed) { + event.setTo(q); + PlayerFunctions.sendMessage(player, C.BORDER); + return; + } + } if (enteredPlot(f, q)) { final Plot plot = getCurrentPlot(q); final boolean admin = PlotMain.hasPermission(player, "plots.admin.entry.denied"); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java index 04cb9c7e6..8e4914c43 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -58,6 +58,7 @@ public abstract class PlotWorld { public final static boolean SPAWN_EGGS_DEFAULT = false; public final static boolean SPAWN_CUSTOM_DEFAULT = true; public final static boolean SPAWN_BREEDING_DEFAULT = false; + public final static boolean WORLD_BORDER_DEFAULT = false; // TODO make this configurable // make non static and static_default_valu + add config option @SuppressWarnings("deprecation") @@ -285,6 +286,7 @@ public abstract class PlotWorld { public boolean SPAWN_EGGS; public boolean SPAWN_CUSTOM; public boolean SPAWN_BREEDING; + public boolean WORLD_BORDER; public PlotWorld(final String worldname) { this.worldname = worldname; @@ -308,6 +310,7 @@ public abstract class PlotWorld { this.MERGE_PRICE = config.getDouble("economy.prices.merge"); this.SELL_PRICE = config.getDouble("economy.prices.sell"); this.PLOT_CHAT = config.getBoolean("chat.enabled"); + this.WORLD_BORDER = config.getBoolean("world.border"); List flags = config.getStringList("flags.default"); if (flags == null) { this.DEFAULT_FLAGS = new Flag[] {}; @@ -357,6 +360,7 @@ public abstract class PlotWorld { options.put("event.spawn.egg", PlotWorld.SPAWN_EGGS_DEFAULT); options.put("event.spawn.custom", PlotWorld.SPAWN_CUSTOM_DEFAULT); options.put("event.spawn.breeding", PlotWorld.SPAWN_BREEDING_DEFAULT); + options.put("world.border", PlotWorld.WORLD_BORDER_DEFAULT); final ConfigurationNode[] settings = getSettingNodes(); /* * Saving generator specific settings diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java index 9608e907e..6e5217646 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -64,9 +64,27 @@ import com.intellectualcrafters.plot.object.PlotWorld; public static boolean canSendChunk = false; public static ArrayList runners_p = new ArrayList<>(); static long state = 1; - public static HashMap lastPlot; - public static HashMap worldBorder; + public static HashMap lastPlot = new HashMap<>(); + public static HashMap worldBorder = new HashMap<>(); + public static int getBorder(World world) { + String worldname = world.getName(); + if (worldBorder.containsKey(worldname)) { + return worldBorder.get(worldname); + } + return Integer.MAX_VALUE; + } + + public static void setupBorder(String world) { + PlotWorld plotworld = PlotMain.getWorldSettings(world); + if (!plotworld.WORLD_BORDER) { + return; + } + for (Plot plot : PlotMain.getPlots(world).values()) { + updateWorldBorder(plot); + } + } + /** * direction 0 = north, 1 = south, etc: * @@ -434,8 +452,27 @@ import com.intellectualcrafters.plot.object.PlotWorld; } return true; } + + public static void updateWorldBorder(Plot plot) { + String world = plot.world; + PlotManager manager = PlotMain.getPlotManager(world); + PlotWorld plotworld = PlotMain.getWorldSettings(world); + Location bot = manager.getPlotBottomLocAbs(plotworld, plot.id); + Location top = manager.getPlotTopLocAbs(plotworld, plot.id); + int border = worldBorder.get(plot.world); + int botmax = Math.max(Math.abs(bot.getBlockX()), Math.abs(bot.getBlockZ())); + int topmax = Math.max(Math.abs(top.getBlockX()), Math.abs(top.getBlockZ())); + int max = Math.max(botmax, topmax); + if (max > border ) { + worldBorder.put(plot.world, max); + } + } public static boolean createPlot(final Player player, final Plot plot) { + + if (PlotHelper.worldBorder.containsKey(plot.world)) { + updateWorldBorder(plot); + } final World w = plot.getWorld(); final Plot p = new Plot(plot.id, UUIDHandler.getUUID(player), plot.settings.getBiome(), new ArrayList(), new ArrayList(), w.getName()); PlotMain.updatePlot(p);