Check border when claiming a plot

Also fixes #1467
This commit is contained in:
Jesse Boyd 2016-12-10 01:09:07 +11:00
parent 9fc464e896
commit 7b1c4a5042
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
2 changed files with 24 additions and 19 deletions

View File

@ -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<Double> 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<Double> 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);
}
}

View File

@ -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);
}