From 58016bb1c84df6d60d79f4dcff60bc7a7c0aedc1 Mon Sep 17 00:00:00 2001 From: Jordan Date: Sun, 3 Aug 2025 10:13:48 +0100 Subject: [PATCH] fix: allow admin override when setting plot context in command (#4712) * fix: allow admin override when setting plot context in command - when admins (plots.admin or console) attempted to use /plot x;z to set context on a plot they are denied on, it would not work - fixes #4696 * Print error to user if denied --- .../plotsquared/core/command/MainCommand.java | 59 +++++++++++-------- Core/src/main/resources/lang/messages_en.json | 1 + 2 files changed, 35 insertions(+), 25 deletions(-) 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 507883a13..5ceafa601 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -283,32 +283,41 @@ public class MainCommand extends Command { } } - private CompletableFuture> preparePlotArgument(@Nullable Plot newPlot, - @Nonnull CommandExecutionData data, - @Nullable PlotArea area) { - if (newPlot != null && (data.player() instanceof ConsolePlayer - || (area != null && area.equals(newPlot.getArea())) - || data.player().hasPermission(Permission.PERMISSION_ADMIN) - || data.player().hasPermission(Permission.PERMISSION_ADMIN_AREA_SUDO)) - && !newPlot.isDenied(data.player().getUUID())) { - return fetchPlotCenterLocation(newPlot) - .thenApply(newLoc -> { - if (!data.player().canTeleport(newLoc)) { - data.player().sendMessage(TranslatableCaption.of("border.denied")); - return Optional.empty(); - } - // Save meta - var originalCommandMeta = setCommandScope(data.player(), new TemporaryCommandMeta(newLoc, newPlot)); - return Optional.of(new CommandExecutionData( - data.player(), - Arrays.copyOfRange(data.args(), 1, data.args().length), // Trimmed command - data.confirm(), - data.whenDone(), - originalCommandMeta - )); - }); + private CompletableFuture> preparePlotArgument( + @Nullable Plot newPlot, + @Nonnull CommandExecutionData data, + @Nullable PlotArea area + ) { + if (newPlot == null) { + return CompletableFuture.completedFuture(Optional.of(data)); } - return CompletableFuture.completedFuture(Optional.of(data)); + final PlotPlayer player = data.player(); + final boolean isAdmin = player instanceof ConsolePlayer || player.hasPermission(Permission.PERMISSION_ADMIN); + final boolean isDenied = newPlot.isDenied(player.getUUID()); + if (!isAdmin) { + if (isDenied) { + throw new CommandException(TranslatableCaption.of("deny.cannot_interact")); + } + if (area != null && area.equals(newPlot.getArea()) && !player.hasPermission(Permission.PERMISSION_ADMIN_AREA_SUDO)) { + return CompletableFuture.completedFuture(Optional.of(data)); + } + } + return fetchPlotCenterLocation(newPlot) + .thenApply(newLoc -> { + if (!player.canTeleport(newLoc)) { + player.sendMessage(TranslatableCaption.of("border.denied")); + return Optional.empty(); + } + // Save meta + var originalCommandMeta = setCommandScope(player, new TemporaryCommandMeta(newLoc, newPlot)); + return Optional.of(new CommandExecutionData( + player, + Arrays.copyOfRange(data.args(), 1, data.args().length), // Trimmed command + data.confirm(), + data.whenDone(), + originalCommandMeta + )); + }); } private Optional prepareFlagArgument(@Nonnull CommandExecutionData data, @Nonnull PlotArea area) { diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index 04c8825b5..ead61d08f 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -415,6 +415,7 @@ "deny.denied_added": "You successfully denied the player from this plot.", "deny.no_enter": "You are denied from the plot and therefore not allowed to enter.", "deny.you_got_denied": "You are denied from the plot you were previously on, and got teleported to spawn.", + "deny.cannot_interact": "You are denied from the plot and therefore cannot interact with it.", "deny.cant_remove_owner": "You can't remove the plot owner.", "kick.player_not_in_plot": "The player is not on this plot.", "kick.cannot_kick_player": "You cannot kick the player .",