diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index 82ef3b78f..06f1010ec 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -27,6 +27,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.flag.Flag; import com.intellectualcrafters.plot.flag.FlagManager; @@ -142,12 +143,30 @@ public class Cluster extends SubCommand { Set plots = MainUtil.getPlotSelectionOwned(world, pos1, pos2); if (plots.size() > 0) { if (!Permissions.hasPermission(plr, "plots.cluster.create.other")) { - MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other"); - return false; + UUID uuid = plr.getUUID(); + for (Plot plot : plots) { + if (!plot.isOwner(uuid)) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster.create.other"); + return false; + } + } } } - // Set the generator (if applicable) + // Check allowed cluster size final PlotCluster cluster = new PlotCluster(world, pos1, pos2, UUIDHandler.getUUID(plr)); + int current; + if (Settings.GLOBAL_LIMIT) { + current = ClusterManager.getPlayerClusterCount(plr); + } + else { + current = ClusterManager.getPlayerClusterCount(world, plr); + } + int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); + if (current + cluster.getArea() > allowed) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea())); + return false; + } + // Set the generator (if applicable) PlotWorld plotworld = PS.get().getPlotWorld(world); if (plotworld == null) { PS.get().config.createSection("worlds." + world); @@ -316,6 +335,20 @@ public class Cluster extends SubCommand { return false; } } + // Check allowed cluster size + int current; + if (Settings.GLOBAL_LIMIT) { + current = ClusterManager.getPlayerClusterCount(plr); + } + else { + current = ClusterManager.getPlayerClusterCount(world, plr); + } + current -= cluster.getArea() + (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y); + int allowed = Permissions.hasPermissionRange(plr, "plots.cluster", Settings.MAX_PLOTS); + if (current + cluster.getArea() > allowed) { + MainUtil.sendMessage(plr, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea())); + return false; + } for (Plot plot : removed) { FlagManager.removePlotFlag(plot, "cluster"); } diff --git a/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java b/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java index 81a1a7539..657152225 100644 --- a/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java +++ b/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java @@ -49,6 +49,14 @@ public class PlotCluster { public String getName() { return this.settings.getAlias(); } + + /** + * Get the area (in plots) + * @return + */ + public int getArea() { + return (1 + pos2.x - pos1.x) * (1 + pos2.y - pos1.y); + } @Override public int hashCode() { diff --git a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java index be1e5ba66..a1532258f 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java +++ b/src/main/java/com/intellectualcrafters/plot/util/ClusterManager.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.HashSet; import java.util.Random; import java.util.Set; +import java.util.UUID; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -13,6 +14,7 @@ import org.bukkit.generator.BlockPopulator; import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.BlockLoc; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.Location; @@ -45,6 +47,25 @@ public class ClusterManager { return new HashSet<>(); } + public static int getPlayerClusterCount(String world, PlotPlayer player) { + final UUID uuid = player.getUUID(); + int count = 0; + for (PlotCluster cluster : ClusterManager.getClusters(world)) { + if (uuid.equals(cluster.owner)) { + count += cluster.getArea(); + } + } + return count; + } + + public static int getPlayerClusterCount(final PlotPlayer plr) { + int count = 0; + for (final String world : PS.get().getPlotWorldsString()) { + count += getPlayerClusterCount(world, plr); + } + return count; + } + public static Location getHome(final PlotCluster cluster) { final BlockLoc home = cluster.settings.getPosition(); Location toReturn; diff --git a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index 8f823c3bd..ea165d30b 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -449,6 +449,11 @@ public class MainUtil { return count; } + /** + * Get a player's total number of plots that count towards their limit + * @param plr + * @return + */ public static int getPlayerPlotCount(final PlotPlayer plr) { int count = 0; for (final String world : PS.get().getPlotWorldsString()) { diff --git a/target/PlotSquared-Bukkit.jar b/target/PlotSquared-Bukkit.jar index 6f22bac26..88dd50cd8 100644 Binary files a/target/PlotSquared-Bukkit.jar and b/target/PlotSquared-Bukkit.jar differ diff --git a/target/PlotSquared-Sponge.jar b/target/PlotSquared-Sponge.jar index 9e5f9d0bb..747a122be 100644 Binary files a/target/PlotSquared-Sponge.jar and b/target/PlotSquared-Sponge.jar differ