From 19cea0e129d4fafbc095e25dbb27fc3b600ab086 Mon Sep 17 00:00:00 2001 From: NotMyFault Date: Tue, 11 May 2021 18:50:37 +0200 Subject: [PATCH] Un-stringify plot id calls - PlotId#toString() already stringifies IDs, no need to call String.valueOf() - Add tab completion to `/plot debugroadregen` - Add `plots.flag.notify-leave.bypass` permission separating from notify-enter - Add message notifying the player if the attempt to enter a plot they are denied from --- Bukkit/src/main/resources/plugin.yml | 6 +++++- .../core/backup/SimpleBackupManager.java | 2 +- .../java/com/plotsquared/core/command/Buy.java | 5 ++++- .../java/com/plotsquared/core/command/Clear.java | 2 +- .../plotsquared/core/command/DebugRoadRegen.java | 14 +++++++++++++- .../java/com/plotsquared/core/command/Delete.java | 2 +- .../java/com/plotsquared/core/command/Done.java | 5 ++++- .../com/plotsquared/core/command/Download.java | 10 +++++----- .../java/com/plotsquared/core/command/Set.java | 2 +- .../plotsquared/core/listener/PlotListener.java | 10 +++++++--- Core/src/main/resources/lang/messages_en.json | 3 ++- 11 files changed, 44 insertions(+), 17 deletions(-) diff --git a/Bukkit/src/main/resources/plugin.yml b/Bukkit/src/main/resources/plugin.yml index 31f286c14..2ca2622f4 100644 --- a/Bukkit/src/main/resources/plugin.yml +++ b/Bukkit/src/main/resources/plugin.yml @@ -294,9 +294,13 @@ permissions: plots.worldedit.bypass: default: false plots.gamemode.bypass: - default: op + default: false plots.confirm.bypass: default: false + plots.flag.notify-enter.bypass: + default: false + plots.flag.notify-leave.bypass: + default: false plots.permpack.basicflags: default: op diff --git a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java index 30c3e2e90..c78643c13 100644 --- a/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java +++ b/Core/src/main/java/com/plotsquared/core/backup/SimpleBackupManager.java @@ -107,7 +107,7 @@ public class SimpleBackupManager implements BackupManager { if (player != null) { player.sendMessage( TranslatableCaption.of("backups.backup_automatic_started"), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); } profile.createBackup().whenComplete((backup, throwable) -> { diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index feeb43954..d8cf1fa60 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -132,7 +132,10 @@ public class Buy extends Command { plot.removeFlag(event.getFlag()); } plot.setOwner(player.getUUID()); - player.sendMessage(TranslatableCaption.of("working.claimed"), Template.of("plot", String.valueOf(plot.getId()))); + player.sendMessage( + TranslatableCaption.of("working.claimed"), + Template.of("plot", plot.getId().toString()) + ); whenDone.run(Buy.this, CommandResult.SUCCESS); }, () -> { this.econHandler.depositMoney(player, price); diff --git a/Core/src/main/java/com/plotsquared/core/command/Clear.java b/Core/src/main/java/com/plotsquared/core/command/Clear.java index f093d2d8a..75c380b55 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Clear.java +++ b/Core/src/main/java/com/plotsquared/core/command/Clear.java @@ -135,7 +135,7 @@ public class Clear extends Command { player.sendMessage( TranslatableCaption.of("working.clearing_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); }); }); diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java index 328978b41..7b9fbdb09 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugRoadRegen.java @@ -39,6 +39,10 @@ import net.kyori.adventure.text.minimessage.Template; import org.checkerframework.checker.nullness.qual.NonNull; import java.util.Arrays; +import java.util.Collection; +import java.util.Locale; +import java.util.stream.Collectors; +import java.util.stream.Stream; @CommandDeclaration(command = "debugroadregen", usage = DebugRoadRegen.USAGE, @@ -110,7 +114,7 @@ public class DebugRoadRegen extends SubCommand { ; player.sendMessage( TranslatableCaption.of("debugroadregen.regen_done"), - Template.of("value", String.valueOf(plot.getId())) + Template.of("value", plot.getId().toString()) ); player.sendMessage( TranslatableCaption.of("debugroadregen.regen_all"), @@ -173,4 +177,12 @@ public class DebugRoadRegen extends SubCommand { return true; } + @Override + public Collection tab(final PlotPlayer player, String[] args, boolean space) { + return Stream.of("plot", "region") + .filter(value -> value.startsWith(args[0].toLowerCase(Locale.ENGLISH))) + .map(value -> new Command(null, false, value, "plots.debugroadregen", RequiredType.NONE, null) { + }).collect(Collectors.toList()); + } + } diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index 1b3a8033c..3992c377f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -126,7 +126,7 @@ public class Delete extends SubCommand { player.sendMessage( TranslatableCaption.of("working.deleting_done"), Template.of("amount", String.valueOf(System.currentTimeMillis() - start)), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); }); if (result) { diff --git a/Core/src/main/java/com/plotsquared/core/command/Done.java b/Core/src/main/java/com/plotsquared/core/command/Done.java index f40e28f51..1ccec2feb 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Done.java +++ b/Core/src/main/java/com/plotsquared/core/command/Done.java @@ -96,7 +96,10 @@ public class Done extends SubCommand { return false; } plot.addRunning(); - player.sendMessage(TranslatableCaption.of("web.generating_link"), Template.of("plot", String.valueOf(plot.getId()))); + player.sendMessage( + TranslatableCaption.of("web.generating_link"), + Template.of("plot", plot.getId().toString()) + ); final Settings.Auto_Clear doneRequirements = Settings.AUTO_CLEAR.get("done"); if (ExpireManager.IMP == null || doneRequirements == null) { finish(plot, player, true); diff --git a/Core/src/main/java/com/plotsquared/core/command/Download.java b/Core/src/main/java/com/plotsquared/core/command/Download.java index 67426b452..153dce9f7 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Download.java +++ b/Core/src/main/java/com/plotsquared/core/command/Download.java @@ -128,14 +128,14 @@ public class Download extends SubCommand { player.sendMessage(TranslatableCaption.of("schematics.mca_file_size")); plot.addRunning(); this.worldUtil.saveWorld(world); - this.worldUtil.upload(plot, null, null, new RunnableVal() { + this.worldUtil.upload(plot, null, null, new RunnableVal<>() { @Override public void run(URL url) { plot.removeRunning(); if (url == null) { player.sendMessage( TranslatableCaption.of("web.generating_link_failed"), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); return; } @@ -146,7 +146,7 @@ public class Download extends SubCommand { sendUsage(player); return false; } - player.sendMessage(TranslatableCaption.of("web.generating_link"), Template.of("plot", String.valueOf(plot.getId()))); + player.sendMessage(TranslatableCaption.of("web.generating_link"), Template.of("plot", plot.getId().toString())); return true; } @@ -185,7 +185,7 @@ public class Download extends SubCommand { schematicHandler .getCompoundTag(plot) .whenComplete((compoundTag, throwable) -> { - schematicHandler.upload(compoundTag, null, null, new RunnableVal() { + schematicHandler.upload(compoundTag, null, null, new RunnableVal<>() { @Override public void run(URL value) { player.sendMessage( @@ -205,7 +205,7 @@ public class Download extends SubCommand { if (throwable != null || !result.isSuccess()) { player.sendMessage( TranslatableCaption.of("web.generating_link_failed"), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); } else { player.sendMessage( diff --git a/Core/src/main/java/com/plotsquared/core/command/Set.java b/Core/src/main/java/com/plotsquared/core/command/Set.java index 1b4abb6f9..748aa01c2 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Set.java +++ b/Core/src/main/java/com/plotsquared/core/command/Set.java @@ -168,7 +168,7 @@ public class Set extends SubCommand { plot.removeRunning(); player.sendMessage( TranslatableCaption.of("working.component_complete"), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); }); if (Settings.QUEUE.NOTIFY_PROGRESS) { diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 6705dd179..b1f047328 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -142,6 +142,10 @@ public class PlotListener { public boolean plotEntry(final PlotPlayer player, final Plot plot) { if (plot.isDenied(player.getUUID()) && !Permissions .hasPermission(player, "plots.admin.entry.denied")) { + player.sendMessage( + TranslatableCaption.of("deny.no_enter"), + Template.of("plot", plot.toString()) + ); return false; } try (final MetaDataAccess lastPlot = player.accessTemporaryMetaData(PlayerMetaDataKeys.TEMPORARY_LAST_PLOT)) { @@ -208,7 +212,7 @@ public class PlotListener { player.sendMessage( TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", String.valueOf(gameMode)), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); } } @@ -223,7 +227,7 @@ public class PlotListener { player.sendMessage( TranslatableCaption.of("gamemode.gamemode_was_bypassed"), Template.of("gamemode", String.valueOf(guestGameMode)), - Template.of("plot", String.valueOf(plot.getId())) + Template.of("plot", plot.getId().toString()) ); } } @@ -379,7 +383,7 @@ public class PlotListener { } if (plot.getFlag(NotifyLeaveFlag.class)) { - if (!Permissions.hasPermission(player, "plots.flag.notify-enter.bypass")) { + if (!Permissions.hasPermission(player, "plots.flag.notify-leave.bypass")) { for (UUID uuid : plot.getOwners()) { final PlotPlayer owner = PlotSquared.platform().playerManager().getPlayerIfExists(uuid); if ((owner != null) && !owner.getUUID().equals(player.getUUID()) && owner.canSee(player)) { diff --git a/Core/src/main/resources/lang/messages_en.json b/Core/src/main/resources/lang/messages_en.json index b09667603..be7b4944c 100644 --- a/Core/src/main/resources/lang/messages_en.json +++ b/Core/src/main/resources/lang/messages_en.json @@ -373,7 +373,8 @@ "chat.plot_chat_format": "[Plot Chat] [] : ", "chat.plot_chat_forced": "This world forces everyone to use plot chat.", "deny.denied_added": "You successfully denied the player from this plot.", - "deny.you_got_denied": "You are denied from the plot you were previously on, and got teleported to spawn..", + "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.cant_remove_owner": "You can't remove the plot owner.", "kick.you_got_kicked": "You got kicked from the plot!", "trusted.trusted_added": "You successfully trusted a user to the plot.",