From c6d2746431669893c1c53f742bb63a4370bd4ed0 Mon Sep 17 00:00:00 2001 From: wotnak Date: Sat, 1 Jul 2023 21:57:15 +0200 Subject: [PATCH] add option to hide coordinates from command output by default use reducedDebugInfo gamerule to determine if coordinates should be shown allow to explicitly configure if coordinates should be shown or not for players with invunload.coordinates permission always show coordinates regardless of the configured option --- .../InvUnload/CommandSearchitem.java | 4 ++- .../jeff_media/InvUnload/CommandUnload.java | 2 +- .../InvUnload/CommandUnloadinfo.java | 2 +- .../java/de/jeff_media/InvUnload/Main.java | 29 ++++++++++++++++++- .../de/jeff_media/InvUnload/Visualizer.java | 3 ++ src/main/resources/config.yml | 16 +++++++--- src/main/resources/plugin.yml | 2 ++ 7 files changed, 50 insertions(+), 8 deletions(-) diff --git a/src/main/java/de/jeff_media/InvUnload/CommandSearchitem.java b/src/main/java/de/jeff_media/InvUnload/CommandSearchitem.java index 1763cf5..9bb4db9 100644 --- a/src/main/java/de/jeff_media/InvUnload/CommandSearchitem.java +++ b/src/main/java/de/jeff_media/InvUnload/CommandSearchitem.java @@ -122,7 +122,9 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } } - summary.print(UnloadSummary.PrintRecipient.PLAYER, p); + if (main.canSeeCoordinates(p)) { + summary.print(UnloadSummary.PrintRecipient.PLAYER, p); + } if(affectedChests.size()==0) { p.sendMessage(String.format(main.messages.MSG_NOTHING_FOUND,mat.name())); diff --git a/src/main/java/de/jeff_media/InvUnload/CommandUnload.java b/src/main/java/de/jeff_media/InvUnload/CommandUnload.java index 5658d98..e8ff856 100644 --- a/src/main/java/de/jeff_media/InvUnload/CommandUnload.java +++ b/src/main/java/de/jeff_media/InvUnload/CommandUnload.java @@ -145,7 +145,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command } } } - if(main.getConfig().getBoolean("always-show-summary")) { + if(main.getConfig().getBoolean("always-show-summary") && main.canSeeCoordinates(p)) { summary.print(PrintRecipient.PLAYER, p); } diff --git a/src/main/java/de/jeff_media/InvUnload/CommandUnloadinfo.java b/src/main/java/de/jeff_media/InvUnload/CommandUnloadinfo.java index 01dc3a3..bb94ac8 100644 --- a/src/main/java/de/jeff_media/InvUnload/CommandUnloadinfo.java +++ b/src/main/java/de/jeff_media/InvUnload/CommandUnloadinfo.java @@ -65,7 +65,7 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command if(laser.isStarted()) laser.stop(); } }*/ - if(main.visualizer.unloadSummaries.containsKey(p.getUniqueId())) { + if(main.visualizer.unloadSummaries.containsKey(p.getUniqueId()) && main.canSeeCoordinates(p)) { UnloadSummary summary = main.visualizer.unloadSummaries.get(p.getUniqueId()); if(summary!=null) { summary.print(PrintRecipient.PLAYER, p); diff --git a/src/main/java/de/jeff_media/InvUnload/Main.java b/src/main/java/de/jeff_media/InvUnload/Main.java index ca4ec6d..0ee9cd3 100644 --- a/src/main/java/de/jeff_media/InvUnload/Main.java +++ b/src/main/java/de/jeff_media/InvUnload/Main.java @@ -6,6 +6,8 @@ import de.jeff_media.InvUnload.utils.EnchantmentUtils; import org.bstats.bukkit.Metrics; import org.bukkit.Bukkit; +import org.bukkit.GameRule; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.Listener; import org.bukkit.plugin.java.JavaPlugin; @@ -30,7 +32,7 @@ public class Main extends JavaPlugin implements Listener { int mcMinorVersion; // 14 for 1.14, 13 for 1.13, ... @SuppressWarnings("FieldCanBeLocal") - private final int currentConfigVersion = 34; + private final int currentConfigVersion = 37; public Messages messages; protected BlockUtils blockUtils; @@ -173,6 +175,7 @@ private void setDefaultConfigValues() { getConfig().addDefault("particle-count", 100); getConfig().addDefault("always-show-summary", true); + getConfig().addDefault("show-coordinates", "default"); getConfig().addDefault("laser-animation", true); getConfig().addDefault("laser-default-duration", 5); @@ -284,4 +287,28 @@ private void saveAllPlayerSettings() { } } + /** + * Determines if given command sender can see coordinates of the chests in command output. + */ + public boolean canSeeCoordinates(CommandSender commandSender) { + if (commandSender.hasPermission("invunload.coordinates")) { + return true; + } + + // Get reducedDebugInfo gamerule value. + boolean reducedDebugInfo = false; + if (commandSender instanceof Player) { + reducedDebugInfo = ((Player) commandSender).getWorld().getGameRuleValue(GameRule.REDUCED_DEBUG_INFO); + } + + // By default, use reducedDebugInfo gamerule to decide if coordinates should be displayed. + if (this.getConfig().getString("show-coordinates").equals("default")) { + return !reducedDebugInfo; + } + + // If show-coordinates config value is not set to 'default' + // ignore the gamerule and use configured boolean value. + return this.getConfig().getBoolean("show-coordinates"); + } + } diff --git a/src/main/java/de/jeff_media/InvUnload/Visualizer.java b/src/main/java/de/jeff_media/InvUnload/Visualizer.java index 13a20fa..25147c9 100644 --- a/src/main/java/de/jeff_media/InvUnload/Visualizer.java +++ b/src/main/java/de/jeff_media/InvUnload/Visualizer.java @@ -85,6 +85,9 @@ public void run() { } void printSummaryToPlayer(Player p) { + if (!main.canSeeCoordinates(p)) { + return; + } UnloadSummary summary = unloadSummaries.get(p.getUniqueId()); if(summary==null) return; summary.print(PrintRecipient.PLAYER, p); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6d57ee6..f31b389 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -46,9 +46,10 @@ ####### Permissions ####### ############################### -# invunload.use: Allows to use the commands /unload, /dump, /unloadinfo, /blacklist -# invunload.reload: Allows to reload the config using /unload reload -# invunload.search: Allows to use the command /searchitem +# invunload.use: Allows to use the commands /unload, /dump, /unloadinfo, /blacklist +# invunload.reload: Allows to reload the config using /unload reload +# invunload.search: Allows to use the command /searchitem +# invunload.coordinates: Allows to always see coordinates even when they are disabled in configuration ############################### ####### General config ####### @@ -113,6 +114,13 @@ sound-effect: ENTITY_PLAYER_LEVELUP # When set to false, the summary is only shown when using /unloadinfo (or /dumpinfo). always-show-summary: true +# Determines if coordinates should be shown in the text summaries and the output of the /searchitem command. +# Can be overridden for specific player/group by granting 'invunload.coordinates' permission. +# When set to default coordinates will be shown/hidden based on the reducedDebugInfo gamerule value. +# When set to true the gamerule will be ignored and coordinates will be shown. +# When set to false the gamerule will be ignored and coordinates will be hidden. +show-coordinates: default + # When set to true, InvUnload will draw the laser beam everytime you /unload or /dump # When set to false, InvUnload only draws the laser beam on /unloadinfo and /search laser-animation: false @@ -499,4 +507,4 @@ message-cooldown: "&cPlease wait a moment before running the command again." debug: false # please do not change the following line manually! -config-version: 35 +config-version: 37 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 3e86e79..bc70fd2 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -57,3 +57,5 @@ permissions: description: Allows usage of the /searchitem command invunload.reload: description: Allows to reload the config using /unload reload + invunload.coordinates: + descrition: Allows to see coordinates even when they are disabled in configuration. \ No newline at end of file