From 7b1c4a504273d45131a568a30727e280c5487dab Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Sat, 10 Dec 2016 01:09:07 +1100 Subject: [PATCH] Check border when claiming a plot Also fixes #1467 --- .../plot/commands/Claim.java | 30 +++++++++++-------- .../plot/object/Plot.java | 13 ++++---- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java index 37c3b3108..ea6f39a02 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Claim.java @@ -47,9 +47,23 @@ public class Claim extends SubCommand { if (!plot.canClaim(player)) { return sendMessage(player, C.PLOT_IS_CLAIMED); } - PlotArea world = plot.getArea(); - if ((EconHandler.manager != null) && world.USE_ECONOMY) { - Expression costExr = world.PRICES.get("claim"); + PlotArea area = plot.getArea(); + if (!schematic.isEmpty()) { + if (area.SCHEMATIC_CLAIM_SPECIFY) { + if (!area.SCHEMATICS.contains(schematic.toLowerCase())) { + return sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic); + } + if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { + return sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic); + } + } + } + int border = area.getBorder(); + if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border) { + return !sendMessage(player, C.BORDER); + } + if ((EconHandler.manager != null) && area.USE_ECONOMY) { + Expression costExr = area.PRICES.get("claim"); double cost = costExr.evaluate((double) currentPlots); if (cost > 0d) { if (EconHandler.manager.getMoney(player) < cost) { @@ -67,16 +81,6 @@ public class Claim extends SubCommand { } sendMessage(player, C.REMOVED_GRANTED_PLOT, "1", "" + (grants - 1)); } - if (!schematic.isEmpty()) { - if (world.SCHEMATIC_CLAIM_SPECIFY) { - if (!world.SCHEMATICS.contains(schematic.toLowerCase())) { - return sendMessage(player, C.SCHEMATIC_INVALID, "non-existent: " + schematic); - } - if (!Permissions.hasPermission(player, C.PERMISSION_CLAIM_SCHEMATIC.f(schematic)) && !Permissions.hasPermission(player, C.PERMISSION_ADMIN_COMMAND_SCHEMATIC)) { - return sendMessage(player, C.NO_SCHEMATIC_PERMISSION, schematic); - } - } - } return plot.claim(player, false, schematic) || sendMessage(player, C.PLOT_NOT_CLAIMED); } } diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index d5b93ab5c..7320beae4 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -2630,6 +2630,12 @@ public class Plot { return this.getManager().setComponent(this.area, this.getId(), component, blocks); } + public int getDistanceFromOrigin() { + Location bot = getManager().getPlotBottomLocAbs(this.area, id); + Location top = getManager().getPlotTopLocAbs(this.area, id); + return Math.max(Math.max(Math.abs(bot.getX()), Math.abs(bot.getZ())), Math.max(Math.abs(top.getX()), Math.abs(top.getZ()))); + } + /** * Expand the world border to include the provided plot (if applicable). */ @@ -2641,12 +2647,7 @@ public class Plot { if (border == Integer.MAX_VALUE) { return; } - PlotManager manager = this.getManager(); - Location bot = manager.getPlotBottomLocAbs(this.area, id); - Location top = manager.getPlotTopLocAbs(this.area, id); - int botmax = Math.max(Math.abs(bot.getX()), Math.abs(bot.getZ())); - int topmax = Math.max(Math.abs(top.getX()), Math.abs(top.getZ())); - int max = Math.max(botmax, topmax); + int max = getDistanceFromOrigin(); if (max > border) { this.area.setMeta("worldBorder", max); }