From 830a5111f4a969f79509ae48a3b74ca01378b1ff Mon Sep 17 00:00:00 2001 From: Sauilitired Date: Sat, 16 Jan 2016 17:48:49 +0100 Subject: [PATCH] Add plot grants for /plot auto --- .../plot/commands/Auto.java | 25 +++++++++++++++++-- .../plot/commands/Claim.java | 2 +- .../intellectualcrafters/plot/config/C.java | 2 +- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java index 0313f9fde..64695768f 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Auto.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Auto.java @@ -29,6 +29,7 @@ import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotWorld; +import com.intellectualcrafters.plot.util.ByteArrayUtilities; import com.intellectualcrafters.plot.util.EconHandler; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; @@ -122,15 +123,30 @@ public class Auto extends SubCommand { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, Settings.MAX_AUTO_SIZE + ""); return false; } + + int removeGrants = 0; + 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) { MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS_NUM, (-diff) + ""); } else { - MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + if (plr.hasPersistentMeta("grantedPlots")) { + int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); + if (grantedPlots < size_x * size_z) { + plr.removePersistentMeta("grantedPlots"); + return sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + } else { + removeGrants = size_x * size_z; + } + } else { + MainUtil.sendMessage(plr, C.CANT_CLAIM_MORE_PLOTS); + } + } + if (removeGrants == 0) { + return false; } - return false; } final PlotWorld pWorld = PS.get().getPlotWorld(world); if ((EconHandler.manager != null) && pWorld.USE_ECONOMY) { @@ -145,6 +161,11 @@ public class Auto extends SubCommand { sendMessage(plr, C.REMOVED_BALANCE, cost + ""); } } + if (removeGrants > 0) { + int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); + plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - removeGrants)); + sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + removeGrants, "" + (grantedPlots - removeGrants)); + } if (!schematic.equals("")) { // if (pWorld.SCHEMATIC_CLAIM_SPECIFY) { if (!pWorld.SCHEMATICS.contains(schematic.toLowerCase())) { diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 4b91241c2..921204b6b 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -133,7 +133,7 @@ public class Claim extends SubCommand { if (removeGrantedPlot) { int grantedPlots = ByteArrayUtilities.bytesToInteger(plr.getPersistentMeta("grantedPlots")); plr.setPersistentMeta("grantedPlots", ByteArrayUtilities.integerToBytes(grantedPlots - 1)); - sendMessage(plr, C.REMOVED_GRANTED_PLOT, "" + (grantedPlots - 1)); + sendMessage(plr, C.REMOVED_GRANTED_PLOT, "1", "" + (grantedPlots - 1)); } if (!schematic.equals("")) { if (world.SCHEMATIC_CLAIM_SPECIFY) { diff --git a/src/main/java/com/intellectualcrafters/plot/config/C.java b/src/main/java/com/intellectualcrafters/plot/config/C.java index 0fabce5e2..9d9ecd4cd 100644 --- a/src/main/java/com/intellectualcrafters/plot/config/C.java +++ b/src/main/java/com/intellectualcrafters/plot/config/C.java @@ -258,7 +258,7 @@ public enum C { CANNOT_AFFORD_MERGE("$2You cannot afford to merge the plots. It costs $1%s", "Economy"), ADDED_BALANCE("$1%s $2has been added to your balance", "Economy"), REMOVED_BALANCE("$1%s $2has been taken from your balance", "Economy"), - REMOVED_GRANTED_PLOT("$2You used a plot grant, you've got $1%s $2left", "Economy"), + REMOVED_GRANTED_PLOT("$2You used %s plot grant(s), you've got $1%s $2left", "Economy"), /* * Setup Stuff */