From be85708e5ace8aaa911dd9a35b6f62bf2b65d8ee Mon Sep 17 00:00:00 2001 From: Jordan Date: Thu, 28 Oct 2021 09:13:36 +0100 Subject: [PATCH] feat: Add border bypass permission (#3302) * Add border bypass permission - Fixes #3297 * Add permission to plots.admin permpack * Implement messages on leaving/entering border area * Rename to border.denied and make border msg red * change too le/ge as tthey are likely to be equal to border when hit. - Since we check for being across the border beforehand, it will hopefully not be spammed too much? - If it's spammed then either we use meta to set if a player's left the border, or we just remove the come-back-in altogether because it's a little looong --- .../bukkit/listener/PlayerEventListener.java | 69 +++++++++++++------ Bukkit/src/main/resources/plugin.yml | 3 + .../com/plotsquared/core/command/Claim.java | 10 +-- .../plotsquared/core/command/MainCommand.java | 2 +- .../core/permissions/Permission.java | 3 +- Core/src/main/resources/lang/messages_en.json | 4 +- 6 files changed, 62 insertions(+), 29 deletions(-) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java index c89c0a9ff..40912ef7d 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEventListener.java @@ -564,19 +564,31 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } int border = area.getBorder(); + int x1; if (x2 > border && this.tmpTeleport) { - to.setX(border - 1); - this.tmpTeleport = false; - player.teleport(event.getTo()); - this.tmpTeleport = true; - pp.sendMessage(TranslatableCaption.of("border.border")); - } - if (x2 < -border && this.tmpTeleport) { - to.setX(-border + 1); - this.tmpTeleport = false; - player.teleport(event.getTo()); - this.tmpTeleport = true; - pp.sendMessage(TranslatableCaption.of("border.border")); + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + to.setX(border - 1); + this.tmpTeleport = false; + player.teleport(event.getTo()); + this.tmpTeleport = true; + pp.sendMessage(TranslatableCaption.of("border.denied")); + } else { + pp.sendMessage(TranslatableCaption.of("border.bypass.exited")); + } + } else if (x2 < -border && this.tmpTeleport) { + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + to.setX(-border + 1); + this.tmpTeleport = false; + player.teleport(event.getTo()); + this.tmpTeleport = true; + pp.sendMessage(TranslatableCaption.of("border.denied")); + } else { + pp.sendMessage(TranslatableCaption.of("border.bypass.exited")); + } + } else if (((x1 = MathMan.roundInt(from.getX())) >= border && x2 <= border) || (x1 <= -border && x2 >= -border)) { + if (Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + pp.sendMessage(TranslatableCaption.of("border.bypass.entered")); + } } } int z2; @@ -643,18 +655,31 @@ public class PlayerEventListener extends PlotListener implements Listener { return; } int border = area.getBorder(); + int z1; if (z2 > border && this.tmpTeleport) { - to.setZ(border - 1); - this.tmpTeleport = false; - player.teleport(event.getTo()); - this.tmpTeleport = true; - pp.sendMessage(TranslatableCaption.of("border.border")); + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + to.setZ(border - 1); + this.tmpTeleport = false; + player.teleport(event.getTo()); + this.tmpTeleport = true; + pp.sendMessage(TranslatableCaption.of("border.denied")); + } else { + pp.sendMessage(TranslatableCaption.of("border.bypass.exited")); + } } else if (z2 < -border && this.tmpTeleport) { - to.setZ(-border + 1); - this.tmpTeleport = false; - player.teleport(event.getTo()); - this.tmpTeleport = true; - pp.sendMessage(TranslatableCaption.of("border.border")); + if (!Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + to.setZ(-border + 1); + this.tmpTeleport = false; + player.teleport(event.getTo()); + this.tmpTeleport = true; + pp.sendMessage(TranslatableCaption.of("border.denied")); + } else { + pp.sendMessage(TranslatableCaption.of("border.bypass.exited")); + } + } else if (((z1 = MathMan.roundInt(from.getZ())) >= border && z2 <= border) || (z1 <= -border && z2 >= -border)) { + if (Permissions.hasPermission(pp, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + pp.sendMessage(TranslatableCaption.of("border.bypass.entered")); + } } } } diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index d78a2f289..c4cecd6a4 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -248,9 +248,12 @@ permissions: plots.admin.components.other: true plots.admin.vehicle.break.unowned: true plots.admin.pve.unowned: true + plots.admin.border.bypass: true plots.teleport.delay.bypass: default: op + plots.admin.border.bypass: + default: op plots.worldedit.bypass: default: op plots.gamemode.bypass: diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index c55cbd13d..12040cfb0 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -183,10 +183,12 @@ public class Claim extends SubCommand { ); } } - int border = area.getBorder(); - if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) { - player.sendMessage(TranslatableCaption.of("border.border")); - return false; + if (!Permissions.hasPermission(player, Permission.PERMISSION_ADMIN_BYPASS_BORDER)) { + int border = area.getBorder(); + if (border != Integer.MAX_VALUE && plot.getDistanceFromOrigin() > border && !force) { + player.sendMessage(TranslatableCaption.of("border.denied")); + return false; + } } plot.setOwnerAbs(player.getUUID()); final String finalSchematic = schematic; diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index 57df9f710..065c2fe89 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -274,7 +274,7 @@ public class MainCommand extends Command { } tp = true; } else { - player.sendMessage(TranslatableCaption.of("border.border")); + player.sendMessage(TranslatableCaption.of("border.denied")); } // Trim command args = Arrays.copyOfRange(args, 1, args.length); diff --git a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java index 3357f7a28..ca07ac4ea 100644 --- a/Core/src/main/java/com/plotsquared/core/permissions/Permission.java +++ b/Core/src/main/java/com/plotsquared/core/permissions/Permission.java @@ -204,7 +204,8 @@ public enum Permission { PERMISSION_ADMIN_DEBUG_OTHER("plots.admin.debug.other"), PERMISSION_RATE("plots.rate"), PERMISSION_ADMIN_FLIGHT("plots.admin.flight"), - PERMISSION_ADMIN_COMPONENTS_OTHER("plots.admin.component.other"); + PERMISSION_ADMIN_COMPONENTS_OTHER("plots.admin.component.other"), + PERMISSION_ADMIN_BYPASS_BORDER("plots.admin.border.bypass"); // private final String text; diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 9f3864dc3..420f1b71d 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -53,7 +53,9 @@ "cluster.cluster_regenerated": "Successfully started cluster regeneration.", "cluster.cluster_teleporting": "Teleporting...", "cluster.cluster_info": "Current cluster: \nName: \nOwner: \nSize: \nRights: ", - "border.border": "You are outside the current map border.", + "border.denied": "You are outside the current map border.", + "border.bypass.exited": "You have bypassed the current map border area.", + "border.bypass.entered": "You have re-entered the current map border area.", "worldedit.worldedit_bypass": "To bypass your restrictions use ", "worldedit.worldedit_bypassed": "Currently bypassing WorldEdit restriction.", "gamemode.gamemode_was_bypassed": "You bypassed the gamemode () set for .",