diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java index b667d9f6e..89bc45ff6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Cluster.java @@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.UUIDHandler; import com.plotsquared.general.commands.CommandDeclaration; - import java.util.ArrayList; import java.util.HashSet; import java.util.Set; @@ -87,6 +86,10 @@ public class Cluster extends SubCommand { MainUtil.sendMessage(player, C.COMMAND_SYNTAX, "/plot cluster create "); return false; } + int currentClusters = Settings.Limit.GLOBAL ? player.getClusterCount() : player.getPlotCount(player.getLocation().getWorld()); + if (currentClusters >= player.getAllowedPlots()) { + return sendMessage(player, C.CANT_CLAIM_MORE_CLUSTERS); + } // check pos1 / pos2 PlotId pos1 = PlotId.fromString(args[2]); PlotId pos2 = PlotId.fromString(args[3]); @@ -132,9 +135,9 @@ public class Cluster extends SubCommand { } else { current = player.getPlayerClusterCount(player.getLocation().getWorld()); } - int allowed = Permissions.hasPermissionRange(player, "plots.cluster", Settings.Limit.MAX_PLOTS); + int allowed = Permissions.hasPermissionRange(player, "plots.cluster.size", Settings.Limit.MAX_PLOTS); if (current + cluster.getArea() > allowed) { - MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster." + (current + cluster.getArea())); + MainUtil.sendMessage(player, C.NO_PERMISSION, "plots.cluster.size." + (current + cluster.getArea())); return false; } // create cluster diff --git a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java index 8682f5838..0f8919c47 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -332,6 +332,7 @@ public enum C { NO_PERMISSION_EVENT("$2You are lacking the permission node: $1%s", "Permission"), NO_PLOT_PERMS("$2You must be the plot owner to perform this action", "Permission"), CANT_CLAIM_MORE_PLOTS("$2You can't claim more plots.", "Permission"), + CANT_CLAIM_MORE_CLUSTERS("$2You can't claim more clusters.", "Permission"), CANT_TRANSFER_MORE_PLOTS("$2You can't send more plots to that user", "Permission"), CANT_CLAIM_MORE_PLOTS_NUM("$2You can't claim more than $1%s $2plots at once", "Permission"), YOU_BE_DENIED("$2You are not allowed to enter this plot", "Permission"), diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java index 12a937c58..e84b47f8d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotCluster.java @@ -63,6 +63,10 @@ public class PlotCluster { return this.region; } + public boolean isOwner(UUID uuid) { + return uuid.equals(owner); + } + public boolean isAdded(UUID uuid) { return this.owner.equals(uuid) || this.invited.contains(uuid) || this.invited.contains(DBFunc.everyone) || this.helpers.contains(uuid) || this.helpers diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java index 1e27c91a9..e0bced8e4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/PlotPlayer.java @@ -132,6 +132,14 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return Permissions.hasPermissionRange(this, "plots.plot", Settings.Limit.MAX_PLOTS); } + /** + * Get the total number of allowed clusters + * @return number of allowed clusters within the scope (globally, or in the player's current world as defined in the settings.yml) + */ + public int getAllowedClusters() { + return Permissions.hasPermissionRange(this, "plots.cluster", Settings.Limit.MAX_PLOTS); + } + /** * Get the number of plots this player owns. * @@ -163,6 +171,25 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return count.get(); } + public int getClusterCount() { + if (!Settings.Limit.GLOBAL) { + return getClusterCount(getLocation().getWorld()); + } + final AtomicInteger count = new AtomicInteger(0); + final UUID uuid = getUUID(); + PS.get().foreachPlotArea(new RunnableVal() { + @Override + public void run(PlotArea value) { + for (PlotCluster cluster : value.getClusters()) { + if (cluster.isOwner(getUUID())) { + count.incrementAndGet(); + } + } + } + }); + return count.get(); + } + /** * Get the number of plots this player owns in the world. * @param world the name of the plotworld to check. @@ -185,6 +212,19 @@ public abstract class PlotPlayer implements CommandCaller, OfflinePlotPlayer { return count; } + public int getClusterCount(String world) { + UUID uuid = getUUID(); + int count = 0; + for (PlotArea area : PS.get().getPlotAreas(world)) { + for (PlotCluster cluster : area.getClusters()) { + if (cluster.isOwner(getUUID())) { + count++; + } + } + } + return count; + } + /** * Get a {@code Set} of plots owned by this player. * @see PS for more searching functions