From 352423cf93278ccbf66b295fcb006f7f2b64d05f Mon Sep 17 00:00:00 2001 From: Byteflux Date: Tue, 14 Apr 2015 06:47:12 -0700 Subject: [PATCH] Allow global plot limit across all worlds. Closes #261 --- .../java/com/intellectualcrafters/plot/PlotSquared.java | 2 ++ .../java/com/intellectualcrafters/plot/commands/Auto.java | 2 +- .../java/com/intellectualcrafters/plot/commands/Buy.java | 3 ++- .../com/intellectualcrafters/plot/commands/Claim.java | 3 ++- .../com/intellectualcrafters/plot/commands/SetOwner.java | 3 ++- .../com/intellectualcrafters/plot/config/Settings.java | 4 ++++ .../java/com/intellectualcrafters/plot/util/MainUtil.java | 8 ++++++++ 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index 78296a479..c28951a04 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -828,6 +828,7 @@ public class PlotSquared { options.put("chunk-processor.max-blockstates", Settings.CHUNK_PROCESSOR_MAX_BLOCKSTATES); options.put("chunk-processor.max-entities", Settings.CHUNK_PROCESSOR_MAX_ENTITIES); options.put("comments.notifications.interval", Settings.COMMENT_NOTIFICATION_INTERVAL); + options.put("global_limit", Settings.GLOBAL_LIMIT); for (final Entry node : options.entrySet()) { if (!config.contains(node.getKey())) { config.set(node.getKey(), node.getValue()); @@ -874,6 +875,7 @@ public class PlotSquared { Settings.UUID_LOWERCASE = config.getBoolean("UUID.force-lowercase"); Settings.UUID_FROM_DISK = config.getBoolean("uuid.read-from-disk"); Settings.REQUIRE_SELECTION = config.getBoolean("worldedit.require-selection-in-mask"); + Settings.GLOBAL_LIMIT = config.getBoolean("global_limit"); } public static void setupConfigs() { 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 ffe3e2f68..c217057c1 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -119,7 +119,7 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } - final int currentPlots = MainUtil.getPlayerPlotCount(world, plr); + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); final int diff = currentPlots - MainUtil.getAllowedPlots(plr); if ((diff + (size_x * size_z)) > 0) { if (diff < 0) { 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 d9b4ff159..e1ef9ae5d 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Buy.java @@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; 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; @@ -68,7 +69,7 @@ public class Buy extends SubCommand { if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - final int currentPlots = MainUtil.getPlayerPlotCount(world, plr); + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(world, plr); if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index d13b7e63f..970ba937a 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -22,6 +22,7 @@ package com.intellectualcrafters.plot.commands; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotPlayer; @@ -89,7 +90,7 @@ public class Claim extends SubCommand { if (plot == null) { return sendMessage(plr, C.NOT_IN_PLOT); } - final int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), plr); + final int currentPlots = Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr); if (currentPlots >= MainUtil.getAllowedPlots(plr)) { return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); } 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 c3326e0cb..7c58b275f 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/SetOwner.java @@ -25,6 +25,7 @@ import java.util.UUID; import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.config.C; +import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.DBFunc; import com.intellectualcrafters.plot.object.Location; import com.intellectualcrafters.plot.object.Plot; @@ -75,7 +76,7 @@ public class SetOwner extends SubCommand { else { if (!Permissions.hasPermission(plr, "plots.admin.command.setowner")) { int size = plots.size(); - final int currentPlots = MainUtil.getPlayerPlotCount(loc.getWorld(), other) + size; + final int currentPlots = (Settings.GLOBAL_LIMIT ? MainUtil.getPlayerPlotCount(plr) : MainUtil.getPlayerPlotCount(loc.getWorld(), plr)) + size; if (currentPlots > MainUtil.getAllowedPlots(other)) { sendMessage(plr, C.CANT_TRANSFER_MORE_PLOTS); return false; diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java index 1d6067d44..baf6b6e09 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/config/Settings.java @@ -152,6 +152,10 @@ public class Settings { public static boolean CONFIRM_CLEAR = true; public static boolean CONFIRM_DELETE = true; public static boolean CONFIRM_UNLINK = true; + /** + * Use global plot limit? + */ + public static boolean GLOBAL_LIMIT = false; /** * Database settings diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java index dbd7c3390..ed8b3d62c 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/util/MainUtil.java @@ -97,6 +97,14 @@ public class MainUtil { } return count; } + + public static int getPlayerPlotCount(final PlotPlayer plr) { + int count = 0; + for (final String world : PlotSquared.getPlotWorldsString()) { + count += getPlayerPlotCount(world, plr); + } + return count; + } public static Location getDefaultHome(Plot plot) { PlotWorld plotworld = PlotSquared.getPlotWorld(plot.world);