diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java index 4470ac2..5dcaaf4 100644 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java +++ b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/CommandWhitelistBukkit.java @@ -1,7 +1,10 @@ package eu.endermite.commandwhitelist.bukkit; import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor; -import eu.endermite.commandwhitelist.bukkit.listeners.*; +import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener; +import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener; +import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener; +import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener; import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener; import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener; import eu.endermite.commandwhitelist.common.CWGroup; @@ -20,7 +23,6 @@ import java.io.File; import java.util.HashMap; import java.util.HashSet; - import java.util.Map; public class CommandWhitelistBukkit extends JavaPlugin { @@ -126,4 +128,20 @@ public static HashSet getSuggestions(org.bukkit.entity.Player player) { } return suggestionList; } + + /** + * @return Command denied message. Will use custom if command exists in any group. + */ + public static String getCommandDeniedMessage(String command) { + String commandDeniedMessage = configCache.command_denied; + HashMap groups = configCache.getGroupList(); + for (CWGroup group : groups.values()) { + if (group.getCommands().contains(command)) { + if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue; + commandDeniedMessage = group.getCommandDeniedMessage(); + break; // get first message we find + } + } + return commandDeniedMessage; + } } diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java index 96006cd..cae568f 100644 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java +++ b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/PlayerCommandPreProcessListener.java @@ -24,7 +24,7 @@ public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreproce HashSet commands = CommandWhitelistBukkit.getCommands(player); if (!commands.contains(label)) { event.setCancelled(true); - audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied)); + audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); return; } diff --git a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java index 2ba481b..629fbec 100644 --- a/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java +++ b/CommandWhitelistBukkit/src/main/java/eu/endermite/commandwhitelist/bukkit/listeners/protocollib/PacketCommandPreProcessListener.java @@ -12,6 +12,7 @@ import eu.endermite.commandwhitelist.common.CommandUtil; import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.commands.CWCommand; +import net.kyori.adventure.platform.bukkit.BukkitAudiences; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; @@ -37,12 +38,12 @@ public void onPacketReceiving(PacketEvent event) { ConfigCache config = CommandWhitelistBukkit.getConfigCache(); String label = CommandUtil.getCommandLabel(string.toLowerCase()); HashSet commands = CommandWhitelistBukkit.getCommands(player); + BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); if (!commands.contains(label)) { event.setCancelled(true); - CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.command_denied)); + audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); return; } - HashSet bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player); for (String bannedSubCommand : bannedSubCommands) { if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) { diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java index 3563b8e..86e8581 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWGroup.java @@ -1,17 +1,20 @@ package eu.endermite.commandwhitelist.common; +import org.jetbrains.annotations.Nullable; + import java.util.*; public class CWGroup { - private final String id, permission; + private final String id, permission, commandDeniedMessage; private final HashSet commands = new HashSet<>(); private final HashSet subCommands = new HashSet<>(); - public CWGroup(String id, Collection commands, Collection subCommands) { + public CWGroup(String id, Collection commands, Collection subCommands, String custom_command_denied_message) { this.id = id; - this.permission = "commandwhitelist.group."+id; + this.permission = "commandwhitelist.group." + id; this.commands.addAll(commands); + this.commandDeniedMessage = custom_command_denied_message; this.subCommands.addAll(subCommands); } @@ -27,6 +30,10 @@ public HashSet getCommands() { return commands; } + public @Nullable String getCommandDeniedMessage() { + return commandDeniedMessage; + } + public void addCommand(String command) { commands.add(command); } diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java index ac3dad4..57cf792 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/CWPermission.java @@ -18,6 +18,7 @@ public String permission() { /** * Allows to check specific group permission + * * @param configCache * @param groupId * @return diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java index 32d0042..c45cf77 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java @@ -51,9 +51,11 @@ public boolean reloadConfig() { exampleCommands.add("example"); List exampleSubCommands = new ArrayList<>(); exampleSubCommands.add("example of"); + String exampleCustomCommandDeniedMessage = "You don't have commandwhitelist.group.example permission."; config.addExample("groups.example.commands", exampleCommands, "This is the WHITELIST of commands that players will be able to see/use in the group \"example\""); config.addExample("groups.example.subcommands", exampleSubCommands, "This is the BLACKLIST of subcommands that players will NOT be able to see/use in the group \"example\""); + config.addExample("groups.example.custom_command_denied_message", exampleCustomCommandDeniedMessage, "This is a custom message that players will see if they do not have commandwhitelist.group. permission.\ncommandwhitelist.group.example in this case\nIf you don't want to use a custom message, set custom_command_denid_message: \"\""); config.addComment("groups.example", "All groups except from default require commandwhitelist.group. permission\ncommandwhitelist.group.example in this case\n If you wish to leave the list empty, put \"commands: []\" or \"subcommands: []\""); } @@ -75,7 +77,9 @@ public boolean reloadConfig() { List defaultSubcommands = new ArrayList<>(); defaultSubcommands.add("help about"); - config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands).serialize()); + String defaultCustomCommandDeniedMessage = ""; + + config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize()); prefix = config.getString("messages.prefix"); command_denied = config.getString("messages.command_denied"); @@ -130,7 +134,8 @@ public CWGroup loadCWGroup(String id, ConfigSection section) { } List subCommands = section.getStringList(id + ".subcommands"); - return new CWGroup(id, commands, subCommands); + String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message"); + return new CWGroup(id, commands, subCommands, customCommandDeniedMessage); } public void saveCWGroup(String id, CWGroup group) { diff --git a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java index 62201d3..9a85c6d 100644 --- a/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java +++ b/CommandWhitelistVelocity/src/main/java/eu/endermite/commandwhitelist/velocity/CommandWhitelistVelocity.java @@ -55,7 +55,7 @@ private static void reloadConfig() { public static void reloadConfig(CommandSource source) { server.getScheduler().buildTask(plugin, () -> { reloadConfig(); - source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix+getConfigCache().config_reloaded)); + source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix + getConfigCache().config_reloaded)); }).schedule(); } @@ -65,7 +65,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) { CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build(); server.getCommandManager().register(commandMeta, new VelocityMainCommand()); Metrics metrics = metricsFactory.make(this, 8704); - metrics.addCustomChart(new SimplePie("proxy", ()-> "Velocity")); + metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity")); } @Subscribe @@ -74,7 +74,7 @@ public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) { if (player.hasPermission(CWPermission.BYPASS.permission())) return; HashSet allowedCommands = CommandWhitelistVelocity.getCommands(player); event.getRootNode().getChildren().removeIf((commandNode) -> - server.getCommandManager().hasCommand(commandNode.getName()) + server.getCommandManager().hasCommand(commandNode.getName()) && !allowedCommands.contains(commandNode.getName()) ); } diff --git a/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json b/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json index c53f31b..735a687 100644 --- a/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json +++ b/CommandWhitelistVelocity/src/main/resources/velocity-plugin.json @@ -1,9 +1,9 @@ { - "id":"commandwhitelist", - "name":"CommandWhitelist", - "version":"${project.version}", - "description":"You decide what commands players can use or tab complete on your server!", - "authors":["YouHaveTrouble"], - "dependencies":[], - "main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity" + "id": "commandwhitelist", + "name": "CommandWhitelist", + "version": "${project.version}", + "description": "You decide what commands players can use or tab complete on your server!", + "authors": ["YouHaveTrouble"], + "dependencies": [], + "main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity" } \ No newline at end of file diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java index e9ef04b..2633d60 100644 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java +++ b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/CommandWhitelistWaterfall.java @@ -8,7 +8,6 @@ import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener; import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.connection.ProxiedPlayer; @@ -30,7 +29,7 @@ public final class CommandWhitelistWaterfall extends Plugin { @Override public void onEnable() { plugin = this; - getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName()); + getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName()); loadConfig(); audiences = BungeeAudiences.create(this); Metrics metrics = new Metrics(this, 8704); @@ -53,6 +52,7 @@ public void onEnable() { public static CommandWhitelistWaterfall getPlugin() { return plugin; } + public static ConfigCache getConfigCache() { return configCache; } @@ -106,4 +106,20 @@ public static HashSet getSuggestions(ProxiedPlayer player) { } return suggestionList; } + + /** + * @return Command denied message. Will use custom if command exists in any group. + */ + public static String getCommandDeniedMessage(String command) { + String commandDeniedMessage = configCache.command_denied; + HashMap groups = configCache.getGroupList(); + for (CWGroup group : groups.values()) { + if (group.getCommands().contains(command)) { + if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue; + commandDeniedMessage = group.getCommandDeniedMessage(); + break; // get first message we find + } + } + return commandDeniedMessage; + } } diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java index 6c2ab56..bff163a 100644 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java +++ b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/command/BungeeMainCommand.java @@ -52,7 +52,7 @@ public void execute(CommandSender sender, String[] args) { else audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist)); } else - audiences.sender(sender).sendMessage(Component.text("/"+label+" add ")); + audiences.sender(sender).sendMessage(Component.text("/" + label + " add ")); return; case REMOVE: if (!sender.hasPermission(CWPermission.ADMIN.permission())) { @@ -65,7 +65,7 @@ public void execute(CommandSender sender, String[] args) { else audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist)); } else - audiences.sender(sender).sendMessage(Component.text("/"+label+" remove ")); + audiences.sender(sender).sendMessage(Component.text("/" + label + " remove ")); return; case HELP: default: @@ -84,6 +84,6 @@ public Iterable onTabComplete(CommandSender sender, String[] args) { for (Map.Entry command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) { serverCommands.add(command.getValue().getName()); } - return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission())); + return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())); } } diff --git a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java index 8e155a3..4ba380f 100644 --- a/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java +++ b/CommandWhitelistWaterfall/src/main/java/eu/endermite/commandwhitelist/waterfall/listeners/BungeeChatEventListener.java @@ -6,7 +6,6 @@ import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; import net.kyori.adventure.platform.bungeecord.BungeeAudiences; -import net.kyori.adventure.text.minimessage.MiniMessage; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; @@ -33,7 +32,7 @@ public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) { HashSet commands = CommandWhitelistWaterfall.getCommands(player); if (!commands.contains(label)) { event.setCancelled(true); - CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.command_denied)); + CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label))); return; }