Skip to content

Commit c904075

Browse files
authored
Remove redundant permission checks for Flag List Command (#4747)
1 parent 53eead4 commit c904075

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

Core/src/main/java/com/plotsquared/core/command/FlagCommand.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ private static boolean checkPermValue(
173173
}
174174

175175
/**
176-
* Checks if the player is allowed to modify the flags at their current location
176+
* Checks if the player is allowed to interact with flags at their current location
177177
*
178178
* @return {@code true} if the player is allowed to modify the flags at their current location
179179
*/
180-
private static boolean checkRequirements(final @NonNull PlotPlayer<?> player) {
180+
private static boolean checkRequirements(final @NonNull PlotPlayer<?> player, final @NonNull Permission permissionIfNotOwner) {
181181
final Plot plot = player.getCurrentPlot();
182182
if (plot == null) {
183183
player.sendMessage(TranslatableCaption.of("errors.not_in_plot"));
@@ -187,10 +187,10 @@ private static boolean checkRequirements(final @NonNull PlotPlayer<?> player) {
187187
player.sendMessage(TranslatableCaption.of("working.plot_not_claimed"));
188188
return false;
189189
}
190-
if (!plot.isOwner(player.getUUID()) && !player.hasPermission(Permission.PERMISSION_SET_FLAG_OTHER)) {
190+
if (!plot.isOwner(player.getUUID()) && !player.hasPermission(permissionIfNotOwner)) {
191191
player.sendMessage(
192192
TranslatableCaption.of("permission.no_permission"),
193-
TagResolver.resolver("node", Tag.inserting(Permission.PERMISSION_SET_FLAG_OTHER))
193+
TagResolver.resolver("node", Tag.inserting(permissionIfNotOwner))
194194
);
195195
return false;
196196
}
@@ -328,7 +328,7 @@ public void set(
328328
final RunnableVal3<Command, Runnable, Runnable> confirm,
329329
final RunnableVal2<Command, CommandResult> whenDone
330330
) {
331-
if (!checkRequirements(player)) {
331+
if (!checkRequirements(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
332332
return;
333333
}
334334
if (args.length < 2) {
@@ -393,7 +393,7 @@ public void add(
393393
final RunnableVal3<Command, Runnable, Runnable> confirm,
394394
final RunnableVal2<Command, CommandResult> whenDone
395395
) {
396-
if (!checkRequirements(player)) {
396+
if (!checkRequirements(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
397397
return;
398398
}
399399
if (args.length < 2) {
@@ -468,7 +468,7 @@ public void remove(
468468
final RunnableVal3<Command, Runnable, Runnable> confirm,
469469
final RunnableVal2<Command, CommandResult> whenDone
470470
) {
471-
if (!checkRequirements(player)) {
471+
if (!checkRequirements(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
472472
return;
473473
}
474474
if (args.length != 1 && args.length != 2) {
@@ -595,7 +595,7 @@ public void list(
595595
final RunnableVal3<Command, Runnable, Runnable> confirm,
596596
final RunnableVal2<Command, CommandResult> whenDone
597597
) {
598-
if (!checkRequirements(player)) {
598+
if (!checkRequirements(player, Permission.PERMISSION_FLAG_LIST_OTHER)) {
599599
return;
600600
}
601601

@@ -645,7 +645,7 @@ public void info(
645645
final RunnableVal3<Command, Runnable, Runnable> confirm,
646646
final RunnableVal2<Command, CommandResult> whenDone
647647
) {
648-
if (!checkRequirements(player)) {
648+
if (!checkRequirements(player, Permission.PERMISSION_SET_FLAG_OTHER)) {
649649
return;
650650
}
651651
if (args.length < 1) {

Core/src/main/java/com/plotsquared/core/permissions/Permission.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ public enum Permission implements ComponentLike {
145145
PERMISSION_FLAG_REMOVE("plots.flag.remove"),
146146
PERMISSION_FLAG_ADD("plots.flag.add"),
147147
PERMISSION_FLAG_LIST("plots.flag.list"),
148+
PERMISSION_FLAG_LIST_OTHER("plots.flag.list.other"),
148149
PERMISSION_ADMIN_COMMAND_KICK("plots.admin.command.kick"),
149150
PERMISSION_GRANT_SINGLE("plots.grant"),
150151
PERMISSION_GRANT("plots.grant.%s"),

0 commit comments

Comments
 (0)