diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index f15138555..449419e53 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -31,8 +31,10 @@ import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.ClusterManager; import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; @@ -156,6 +158,17 @@ public class Auto extends SubCommand { } // } } + + PlotWorld plotworld = PlotMain.getWorldSettings(world); + if (plotworld.REQUIRE_CLUSTER) { + Location loc = plr.getLocation(); + Plot plot = PlotHelper.getCurrentPlot(loc); + if (plot == null) { + return sendMessage(plr, C.NOT_IN_PLOT); + } + PlotCluster cluster = ClusterManager.getCluster(loc); + } + boolean br = false; String worldname = world.getName(); if ((size_x == 1) && (size_z == 1)) { @@ -189,7 +202,7 @@ public class Auto extends SubCommand { Claim.claimPlot(plr, plot, teleport, true); } } - if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(world, start, end))) { + if (!PlotHelper.mergePlots(plr, world, PlayerFunctions.getPlotSelectionIds(start, end))) { return false; } br = true; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java index 180e0d056..74e2444c0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -90,7 +90,7 @@ public class Buy extends SubCommand { double price = initPrice; PlotId id = plot.id; PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; - int size = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); + int size = PlayerFunctions.getPlotSelectionIds(id, id2).size(); PlotWorld plotworld = PlotMain.getWorldSettings(world); if (plotworld.USE_ECONOMY) { price += plotworld.PLOT_PRICE * size; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java index 205639a31..2d759a3bb 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/DebugClaimTest.java @@ -104,7 +104,7 @@ public class DebugClaimTest extends SubCommand { final ArrayList plots = new ArrayList<>(); - for (final PlotId id : PlayerFunctions.getPlotSelectionIds(world, min, max)) { + for (final PlotId id : PlayerFunctions.getPlotSelectionIds(min, max)) { final Plot plot = PlotHelper.getPlot(world, id); final boolean contains = PlotMain.getPlots(world).containsKey(plot.id); if (contains) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java index ace537398..8a1021929 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Info.java @@ -168,7 +168,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; final PlotId id = plot.id; final PlotId id2 = PlayerFunctions.getTopPlot(world, plot).id; - final int num = PlayerFunctions.getPlotSelectionIds(world, id, id2).size(); + final int num = PlayerFunctions.getPlotSelectionIds(id, id2).size(); final String alias = plot.settings.getAlias().length() > 0 ? plot.settings.getAlias() : "none"; final String biome = getBiomeAt(plot).toString(); final String helpers = getPlayerList(plot.helpers); diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java index de8cf2b15..1ea2b55d8 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -36,7 +36,7 @@ import com.intellectualcrafters.plot.util.PlayerFunctions; import com.intellectualcrafters.plot.util.PlotHelper; import com.intellectualcrafters.plot.util.UUIDHandler; -@SuppressWarnings("deprecation") public class SetOwner extends SubCommand { +public class SetOwner extends SubCommand { public SetOwner() { super("setowner", "plots.admin.command.setowner", "Set the plot owner", "setowner {player}", "so", CommandCategory.ACTIONS, true); @@ -68,7 +68,7 @@ import com.intellectualcrafters.plot.util.UUIDHandler; final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; final PlotId top = PlayerFunctions.getTopPlot(world, plot).id; - final ArrayList plots = PlayerFunctions.getPlotSelectionIds(world, bot, top); + final ArrayList plots = PlayerFunctions.getPlotSelectionIds(bot, top); for (final PlotId id : plots) { final Plot current = PlotMain.getPlots(world).get(id); 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 69ad6f246..e8d88a897 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -209,6 +209,7 @@ public enum C { * No */ NOT_IN_PLOT("&cYou're not in a plot"), + NOT_IN_CLUSTER("&cYou're not in a plot cluster"), NOT_IN_PLOT_WORLD("&cYou're not in a plot world"), NOT_VALID_WORLD("&cThat is not a valid world (case sensitive)"), NOT_VALID_PLOT_WORLD("&cThat is not a valid plot world (case sensitive)"), diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java index f208bba2c..89e88afb9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/AugmentedPopulator.java @@ -49,8 +49,6 @@ public class AugmentedPopulator extends BlockPopulator { else { x = z_1 - (z << 4); } - - short id = result[i][j]; return new BlockWrapper(x, y, z, id, (byte) 0); } @@ -59,7 +57,7 @@ public class AugmentedPopulator extends BlockPopulator { this.generator = generator; this.plotworld = generator.getNewPlotWorld(world); this.manager = generator.getPlotManager(); - + World bukkitWorld = Bukkit.getWorld(world); Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()); @@ -77,9 +75,6 @@ public class AugmentedPopulator extends BlockPopulator { @Override public void populate(World world, Random rand, Chunk chunk) { - - // TODO check if chunk is in any clusters - int X = chunk.getX(); int Z = chunk.getZ(); int x = X << 4; 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 0b46d2364..87483c32c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotWorld.java @@ -33,6 +33,7 @@ import org.bukkit.configuration.ConfigurationSection; import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.config.Configuration; import com.intellectualcrafters.plot.config.ConfigurationNode; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; @@ -59,6 +60,12 @@ public abstract class PlotWorld { public final static boolean SPAWN_CUSTOM_DEFAULT = true; public final static boolean SPAWN_BREEDING_DEFAULT = false; public final static boolean WORLD_BORDER_DEFAULT = false; + public final static boolean REQUIRE_CLAIM_IN_CLUSTER_DEFAULT = false; + + // are plot clusters enabled + // require claim in cluster + + // TODO make this configurable // make non static and static_default_valu + add config option public static List BLOCKS; /* @@ -285,6 +292,7 @@ public abstract class PlotWorld { public boolean SPAWN_CUSTOM; public boolean SPAWN_BREEDING; public boolean WORLD_BORDER; + public boolean REQUIRE_CLUSTER = false; public PlotWorld(final String worldname) { this.worldname = worldname; @@ -296,6 +304,9 @@ public abstract class PlotWorld { * @param config Configuration Section */ public void loadDefaultConfiguration(final ConfigurationSection config) { + if (Settings.ENABLE_CLUSTERS) { + this.REQUIRE_CLUSTER = config.getBoolean("claim.require_cluster"); + } this.MOB_SPAWNING = config.getBoolean("natural_mob_spawning"); this.AUTO_MERGE = config.getBoolean("plot.auto_merge"); this.PLOT_BIOME = (Biome) Configuration.BIOME.parseString(config.getString("plot.biome")); @@ -359,6 +370,9 @@ public abstract class PlotWorld { 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); + if (Settings.ENABLE_CLUSTERS) { + options.put("claim.require_cluster", PlotWorld.REQUIRE_CLAIM_IN_CLUSTER_DEFAULT); + } final ConfigurationNode[] settings = getSettingNodes(); /* * Saving generator specific settings diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index 96dddda91..c4f8cced1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -3,10 +3,15 @@ package com.intellectualcrafters.plot.util; import java.util.HashMap; import java.util.HashSet; +import org.bukkit.Location; + +import com.intellectualcrafters.plot.PlotMain; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotClusterId; import com.intellectualcrafters.plot.object.PlotId; +import com.intellectualcrafters.plot.object.PlotManager; +import com.intellectualcrafters.plot.object.PlotWorld; public class ClusterManager { public static HashMap> clusters; @@ -19,20 +24,58 @@ public class ClusterManager { return false; } + public static boolean contains(PlotCluster cluster, Location loc) { + String world = loc.getWorld().getName(); + PlotManager manager = PlotMain.getPlotManager(world); + PlotWorld plotworld = PlotMain.getWorldSettings(world); + Location bot = manager.getPlotBottomLocAbs(plotworld, cluster.getP1()); + Location top = manager.getPlotTopLocAbs(plotworld, cluster.getP2()).add(1,0,1); + if (bot.getBlockX() < loc.getBlockX() && bot.getBlockZ() < loc.getBlockZ() && top.getBlockX() > loc.getBlockX() && top.getBlockZ() > loc.getBlockZ()) { + return true; + } + return false; + } + public static PlotCluster getCluster(Plot plot) { - if (last != null && last.world.equals(plot.world)) { - if (contains(last, plot.id)) { + return getCluster(plot.world, plot.id); + } + + public static PlotCluster getCluster(Location loc) { + String world = loc.getWorld().getName(); + if (last != null && last.world.equals(world)) { + if (contains(last, loc)) { return last; } } if (clusters == null) { return null; } - HashSet local = clusters.get(plot.world); + HashSet local = clusters.get(world); + if (local == null) { + return null; + } + for (PlotCluster cluster : local) { + if (contains(cluster, loc)) { + last = cluster; + return cluster; + } + } + return null; + } + + public static PlotCluster getCluster(String world, PlotId id) { + if (last != null && last.world.equals(world)) { + if (contains(last, id)) { + return last; + } + } + if (clusters == null) { + return null; + } + HashSet local = clusters.get(world); if (local == null) { return null; } - PlotId id = plot.id; for (PlotCluster cluster : local) { if (contains(cluster, id)) { last = cluster; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java index 6e26bf8fc..863a0e978 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlayerFunctions.java @@ -56,7 +56,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; return getCurrentPlot(player) != null; } - public static ArrayList getPlotSelectionIds(@SuppressWarnings("unused") final World world, final PlotId pos1, final PlotId pos2) { + public static ArrayList getPlotSelectionIds(PlotId pos1, final PlotId pos2) { final ArrayList myplots = new ArrayList<>(); for (int x = pos1.x; x <= pos2.x; x++) { for (int y = pos1.y; y <= pos2.y; y++) { @@ -147,7 +147,13 @@ import com.intellectualcrafters.plot.object.PlotWorld; return null; } final PlotWorld plotworld = PlotMain.getWorldSettings(world); - return manager.getPlotId(plotworld, loc); + PlotId id = manager.getPlotId(plotworld, loc); + if (plotworld.REQUIRE_CLUSTER) { + if (ClusterManager.getCluster(world, id) == null) { + return null; + } + } + return id; } /** @@ -225,7 +231,6 @@ import com.intellectualcrafters.plot.object.PlotWorld; * * @return */ - @SuppressWarnings("SuspiciousNameCombination") public static int getAllowedPlots(final Player p) { return PlotMain.hasPermissionRange(p, "plots.plot", Settings.MAX_PLOTS); } 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 236f6c435..a5b6de670 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/PlotHelper.java @@ -397,7 +397,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; count++; final PlotId bot = PlayerFunctions.getBottomPlot(world, plot).id; final PlotId top = PlayerFunctions.getTopPlot(world, plot).id; - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); + plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y - 1), new PlotId(top.x, top.y)); if (ownsPlots(world, plots, player, 0)) { final boolean result = mergePlots(world, plots); if (result) { @@ -405,7 +405,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; continue; } } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); + plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x + 1, top.y)); if (ownsPlots(world, plots, player, 1)) { final boolean result = mergePlots(world, plots); if (result) { @@ -413,7 +413,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; continue; } } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); + plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x, bot.y), new PlotId(top.x, top.y + 1)); if (ownsPlots(world, plots, player, 2)) { final boolean result = mergePlots(world, plots); if (result) { @@ -421,7 +421,7 @@ import com.intellectualcrafters.plot.object.PlotWorld; continue; } } - plots = PlayerFunctions.getPlotSelectionIds(world, new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); + plots = PlayerFunctions.getPlotSelectionIds(new PlotId(bot.x - 1, bot.y), new PlotId(top.x, top.y)); if (ownsPlots(world, plots, player, 3)) { final boolean result = mergePlots(world, plots); if (result) {