From 1a12a80a32d36d70398cd0d3dfcee9bca74d0fe6 Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Thu, 12 Mar 2020 15:22:55 +1300 Subject: [PATCH] Remove disguises from tab complete and prevent all usage by changing required permission in config, closes #432 --- .../disguise/DisguiseConfig.java | 33 +++++++++++++++++++ src/main/resources/config.yml | 14 ++++++++ src/main/resources/plugin.yml | 4 --- 3 files changed, 47 insertions(+), 4 deletions(-) diff --git a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java index 96f929eb..e8bc3e19 100644 --- a/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java +++ b/src/main/java/me/libraryaddict/disguise/DisguiseConfig.java @@ -18,11 +18,14 @@ import org.bukkit.command.CommandSender; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.entity.Entity; +import org.bukkit.permissions.Permission; +import org.bukkit.permissions.PermissionDefault; import java.io.File; import java.io.IOException; import java.io.PrintWriter; import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.Map.Entry; @@ -209,6 +212,27 @@ public class DisguiseConfig { @Getter @Setter private static boolean notifyPlayerDisguised; + private static PermissionDefault commandVisibility = PermissionDefault.TRUE; + + public static PermissionDefault getCommandVisibility() { + return commandVisibility; + } + + public static void setCommandVisibility(PermissionDefault permissionDefault) { + if (permissionDefault == null || getCommandVisibility() == permissionDefault) { + return; + } + + commandVisibility = permissionDefault; + + for (Permission perm : LibsDisguises.getInstance().getDescription().getPermissions()) { + if (!perm.getName().startsWith("libsdisguises.seecmd")) { + continue; + } + + perm.setDefault(getCommandVisibility()); + } + } private DisguiseConfig() { } @@ -410,6 +434,15 @@ public class DisguiseConfig { "' to a valid option for SelfDisguisesScoreboard"); } + PermissionDefault commandVisibility = PermissionDefault.getByName(config.getString("Permissions.SeeCommands")); + + if (commandVisibility == null) { + DisguiseUtilities.getLogger().warning("Invalid option '" + config.getString("Permissions.SeeCommands") + + "' for Permissions.SeeCommands when loading config!"); + } else { + setCommandVisibility(commandVisibility); + } + loadCustomDisguises(); // Another wee trap for the non-legit diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d1efa4c2..2fb426c3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -14,6 +14,20 @@ Permissions: # negate with your permissions plugin ExplicitDisguises: false + # What should the default permissions be for seeing commands? + # This is a config option because I can't verify if they should be able to see commands normally due to my + # permissions system. My system is complex, but its a ton of control. + # This isn't an issue normally, but I recently received complaints from someone who doesn't believe in permissions... + # Some of you may also wish to hide these commands! + # The permissions for commands are a simple 'libsdisguises.seecmd.command' where 'command' can be + # 'disguise', 'undisguise' etc. A simple 'libsdisguises.seecmd' permission may also work for children + # If you change this while the server is running, players may need to rejoin for it to take effect + # TRUE = Everyone can see this, the default. Can be negated with permissions + # FALSE = No one can see this without permissions to allow it + # OP = Only operators can see this + # NOT_OP = Only non operators can see this + SeeCommands: TRUE + # Disables commands with the exception of /libsdisguises. Useful if you don't want the plugin to be used by anything # but a plugin # Useful if you didn't purchase the plugin. diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 258c8743..33e380b0 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -11,7 +11,6 @@ api-version: 1.13 commands: libsdisguises: aliases: [libsdisg, ld] - #permission: libsdisguises.seecmd.libsdisguises description: Main command for libsdisguises. disguise: aliases: [d, dis] @@ -117,7 +116,6 @@ permissions: description: See all commands in tab-completion default: true children: - #libsdisguises.seecmd.libsdisguises: true libsdisguises.seecmd.disguise: true libsdisguises.seecmd.disguiseentity: true libsdisguises.seecmd.disguisehelp: true @@ -136,8 +134,6 @@ permissions: libsdisguises.seecmd.copydisguise: true libsdisguises.seecmd.grabskin: true libsdisguises.seecmd.savedisguise: true - libsdisguises.seecmd.libsdisguises: - description: See the /libsdisguises command in tab-completion libsdisguises.seecmd.disguiseviewself: description: See the /disguiseviewself command in tab-completion libsdisguises.seecmd.disguise: