From 7a707068e26cc93edb8cd17990b79730a2adce08 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Tue, 17 Dec 2024 17:14:50 +0100 Subject: [PATCH] added ability to send command denied message as action bar in bukkit and waterfall --- CommandWhitelistBukkit/pom.xml | 2 +- .../listeners/PlayerCommandPreProcessListener.java | 9 ++++++++- CommandWhitelistCommon/pom.xml | 2 +- .../commandwhitelist/common/ConfigCache.java | 13 +++++++++++++ .../commandwhitelist/common/MessageType.java | 7 +++++++ CommandWhitelistVelocity/pom.xml | 2 +- CommandWhitelistWaterfall/pom.xml | 2 +- .../listeners/BungeeChatEventListener.java | 9 ++++++++- pom.xml | 2 +- 9 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/MessageType.java diff --git a/CommandWhitelistBukkit/pom.xml b/CommandWhitelistBukkit/pom.xml index 89f9652..1a7022b 100644 --- a/CommandWhitelistBukkit/pom.xml +++ b/CommandWhitelistBukkit/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.10.0 + 2.11.0 Bukkit 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 b81410e..b23ed61 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 @@ -34,7 +34,14 @@ public class PlayerCommandPreProcessListener implements Listener { messageWithoutSlash, config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label) ); - audiences.player(player).sendMessage(message); + switch (config.messageType) { + case CHAT: + audiences.player(player).sendMessage(message); + break; + case ACTIONBAR: + audiences.player(player).sendActionBar(message); + break; + } return; } diff --git a/CommandWhitelistCommon/pom.xml b/CommandWhitelistCommon/pom.xml index 9682ab6..0c2082a 100644 --- a/CommandWhitelistCommon/pom.xml +++ b/CommandWhitelistCommon/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.10.0 + 2.11.0 Common 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 ccc7362..47ffe14 100644 --- a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/ConfigCache.java @@ -17,6 +17,7 @@ public class ConfigCache { public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist, removed_from_whitelist, group_doesnt_exist, subcommand_denied; public boolean useProtocolLib = false; + public MessageType messageType = MessageType.CHAT; public boolean debug = false; public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) { @@ -56,6 +57,8 @@ public class ConfigCache { if (canDoProtocolLib) config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect."); + config.addDefault("message_type", MessageType.CHAT.toString(), "Valid message types are CHAT and ACTIONBAR. Does nothing on velocity."); + if (config.isNew()) { List exampleCommands = new ArrayList<>(); exampleCommands.add("example"); @@ -102,6 +105,16 @@ public class ConfigCache { group_doesnt_exist = config.getString("messages.group_doesnt_exist"); useProtocolLib = config.getBoolean("use_protocollib"); debug = config.getBoolean("debug", false); + try { + String chatTypeId = config.getString("message_type"); + if (chatTypeId == null) { + warn("Invalid message type. Using CHAT."); + } else { + messageType = MessageType.valueOf(chatTypeId.toUpperCase(Locale.ENGLISH)); + } + } catch (IllegalArgumentException e) { + warn("Invalid message type. Using CHAT."); + } ConfigSection groupSection = config.getConfigSection("groups"); for (String key : groupSection.getKeys(false)) { diff --git a/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/MessageType.java b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/MessageType.java new file mode 100644 index 0000000..c7f46e2 --- /dev/null +++ b/CommandWhitelistCommon/src/main/java/eu/endermite/commandwhitelist/common/MessageType.java @@ -0,0 +1,7 @@ +package eu.endermite.commandwhitelist.common; + +public enum MessageType { + + CHAT, ACTIONBAR + +} diff --git a/CommandWhitelistVelocity/pom.xml b/CommandWhitelistVelocity/pom.xml index d2a6429..754d0f9 100644 --- a/CommandWhitelistVelocity/pom.xml +++ b/CommandWhitelistVelocity/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.10.0 + 2.11.0 Velocity diff --git a/CommandWhitelistWaterfall/pom.xml b/CommandWhitelistWaterfall/pom.xml index a71748d..dda6ad1 100644 --- a/CommandWhitelistWaterfall/pom.xml +++ b/CommandWhitelistWaterfall/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.10.0 + 2.11.0 Waterfall 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 0d34bbe..6f4dcd8 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 @@ -38,7 +38,14 @@ public class BungeeChatEventListener implements Listener { command, configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label) ); - audiences.player(player).sendMessage(message); + switch (configCache.messageType) { + case CHAT: + audiences.player(player).sendMessage(message); + break; + case ACTIONBAR: + audiences.player(player).sendActionBar(message); + break; + } return; } diff --git a/pom.xml b/pom.xml index 96b83cf..350b8af 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ eu.endermite.commandwhitelist CommandWhitelist - 2.10.0 + 2.11.0 CommandWhitelistCommon CommandWhitelistBukkit