Compare commits

...
3 Commits
Author SHA1 Message Date
YouHaveTrouble 4243c8d268 bump version 2026-10-11 14:26:32 +02:00
YouHaveTrouble 35fb36e77a deprecate protocollib use 2026-10-11 13:55:16 +02:00
iM7mD :)andYouHaveTrouble e75ef8aa3f Adding CHAT_AND_ACTION type and Sounds (#114)
* Added CHAT_AND_ACTION to MessageType

* Implement command denied sounds

* Add feature to play sounds on denied commands

* Added comment to command_denied_sound

* Added comment to command_denied_sound

* Added Sounds and CHAT_AND_ACTION to Waterfall

* minor qol changes
do not show configs for features on platforms that don't benefit from them
make the new message type enum more clear

---------

Co-authored-by: YouHaveTrouble <youhavetrouble@youhavetrouble.me>
2026-10-11 13:47:52 +02:00
14 changed files with 102 additions and 19 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.1</version> <version>2.13.0</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -72,9 +72,9 @@ public class CommandWhitelistBukkit extends JavaPlugin {
File configFile = new File("plugins/CommandWhitelist/config.yml"); File configFile = new File("plugins/CommandWhitelist/config.yml");
if (configCache == null) { if (configCache == null) {
try { try {
configCache = new ConfigCache(configFile, true, getSLF4JLogger()); configCache = new ConfigCache(configFile, true, true, getSLF4JLogger());
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {
configCache = new ConfigCache(configFile, true, null); configCache = new ConfigCache(configFile, true, true, null);
} }
return; return;
} }
@@ -5,7 +5,9 @@ import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil; import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@@ -41,6 +43,22 @@ public class PlayerCommandPreProcessListener implements Listener {
case ACTIONBAR: case ACTIONBAR:
audiences.player(player).sendActionBar(message); audiences.player(player).sendActionBar(message);
break; break;
case CHAT_AND_ACTIONBAR:
audiences.player(player).sendMessage(message);
audiences.player(player).sendActionBar(message);
break;
}
if(config.command_denied_sound_enabled) {
try {
String soundKey = config.command_denied_sound_key;
Key sound = Key.key(soundKey);
float soundVolume = config.command_denied_sound_volume;
float soundPitch = config.command_denied_sound_pitch;
audiences.player(player).playSound(Sound.sound(sound, Sound.Source.UI, soundVolume, soundPitch));
} catch (Exception e) {
config.warn("Invalid sound. unable to play sound!");
}
} }
return; return;
} }
@@ -18,6 +18,7 @@ import org.bukkit.plugin.Plugin;
import java.util.HashSet; import java.util.HashSet;
@Deprecated(forRemoval = true)
public class PacketCommandPreProcessListener { public class PacketCommandPreProcessListener {
public static void protocol(CommandWhitelistBukkit plugin) { public static void protocol(CommandWhitelistBukkit plugin) {
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.1</version> <version>2.13.0</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
@@ -2,6 +2,7 @@ package eu.endermite.commandwhitelist.common;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile; import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection; import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import net.kyori.adventure.key.Key;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -12,17 +13,22 @@ public class ConfigCache {
private final File configFile; private final File configFile;
private ConfigFile config; private ConfigFile config;
private final Object logger; private final Object logger;
private final boolean canDoProtocolLib; private final boolean canDoProtocolLib, supportsCommandDeniedMessage;
private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>(); private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>();
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist, public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
removed_from_whitelist, group_doesnt_exist, subcommand_denied; removed_from_whitelist, group_doesnt_exist, subcommand_denied, command_denied_sound_key;
public boolean useProtocolLib = false; public boolean useProtocolLib = false;
public boolean command_denied_sound_enabled = false;
public float command_denied_sound_volume = 1.0f;
public float command_denied_sound_pitch = 1.0f;
public MessageType messageType = MessageType.CHAT; public MessageType messageType = MessageType.CHAT;
public boolean debug = false; public boolean debug = false;
private final String default_command_denied_sound_key = "entity.villager.no";
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) { public ConfigCache(File configFile, boolean canDoProtocolLib, boolean supportsCommandDeniedMessage, Object logger) {
this.configFile = configFile; this.configFile = configFile;
this.canDoProtocolLib = canDoProtocolLib; this.canDoProtocolLib = canDoProtocolLib;
this.supportsCommandDeniedMessage = supportsCommandDeniedMessage;
this.logger = logger; this.logger = logger;
try { try {
@@ -43,8 +49,11 @@ public class ConfigCache {
} }
config.addDefault("messages.prefix", "CommandWhitelist > "); config.addDefault("messages.prefix", "CommandWhitelist > ");
config.addDefault("messages.command_denied", "No such command."); if (supportsCommandDeniedMessage) {
config.addDefault("messages.subcommand_denied", "You cannot use this subcommand"); config.addDefault("messages.command_denied", "No such command.");
config.addDefault("messages.subcommand_denied", "You cannot use this subcommand");
}
config.addDefault("messages.no_permission", "<red>You don't have permission to do this."); config.addDefault("messages.no_permission", "<red>You don't have permission to do this.");
config.addDefault("messages.no_such_subcommand", "<red>No subcommand by that name."); config.addDefault("messages.no_such_subcommand", "<red>No subcommand by that name.");
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded."); config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
@@ -57,7 +66,13 @@ public class ConfigCache {
if (canDoProtocolLib) 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("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 (supportsCommandDeniedMessage) {
config.addDefault("message_type", MessageType.CHAT.toString(), "Valid message types are CHAT and ACTIONBAR and CHAT_AND_ACTIONBAR.");
config.addDefault("command_denied_sound.enabled", false);
config.addDefault("command_denied_sound.key", "entity.villager.no");
config.addDefault("command_denied_sound.volume", 1.0f);
config.addDefault("command_denied_sound.pitch", 1.0f);
}
if (config.isNew()) { if (config.isNew()) {
List<String> exampleCommands = new ArrayList<>(); List<String> exampleCommands = new ArrayList<>();
@@ -95,8 +110,8 @@ public class ConfigCache {
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize()); config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
prefix = config.getString("messages.prefix"); prefix = config.getString("messages.prefix");
command_denied = config.getString("messages.command_denied"); command_denied = config.getString("messages.command_denied", "No such command.");
subcommand_denied = config.getString("messages.subcommand_denied"); subcommand_denied = config.getString("messages.subcommand_denied", "You cannot use this subcommand");
no_permission = config.getString("messages.no_permission"); no_permission = config.getString("messages.no_permission");
no_such_subcommand = config.getString("messages.no_such_subcommand"); no_such_subcommand = config.getString("messages.no_such_subcommand");
config_reloaded = config.getString("messages.config_reloaded"); config_reloaded = config.getString("messages.config_reloaded");
@@ -104,6 +119,32 @@ public class ConfigCache {
removed_from_whitelist = config.getString("messages.removed_from_whitelist"); removed_from_whitelist = config.getString("messages.removed_from_whitelist");
group_doesnt_exist = config.getString("messages.group_doesnt_exist"); group_doesnt_exist = config.getString("messages.group_doesnt_exist");
useProtocolLib = config.getBoolean("use_protocollib"); useProtocolLib = config.getBoolean("use_protocollib");
command_denied_sound_enabled = config.getBoolean("command_denied_sound.enabled", false);
if(command_denied_sound_enabled) {
try {
String temp_command_denied_sound_key = config.getString("command_denied_sound.key");
if(temp_command_denied_sound_key == null) {
warn("Invalid sound key. Using " + default_command_denied_sound_key);
command_denied_sound_key = default_command_denied_sound_key;
} else {
try {
Key isSound = Key.key(temp_command_denied_sound_key);
command_denied_sound_key = isSound.asString();
} catch (Exception e) {
warn("Invalid sound key. Using " + default_command_denied_sound_key);
command_denied_sound_key = default_command_denied_sound_key;
}
command_denied_sound_key = command_denied_sound_key.toLowerCase(Locale.ENGLISH);
}
command_denied_sound_volume = config.getFloat("command_denied_sound.volume");
command_denied_sound_pitch = config.getFloat("command_denied_sound.pitch");
} catch (Exception e) {
warn("Invalid sound. Using default sound configurations.");
command_denied_sound_key = default_command_denied_sound_key;
command_denied_sound_volume = 1.0f;
command_denied_sound_pitch = 1.0f;
}
}
debug = config.getBoolean("debug", false); debug = config.getBoolean("debug", false);
try { try {
String chatTypeId = config.getString("message_type"); String chatTypeId = config.getString("message_type");
@@ -121,6 +162,11 @@ public class ConfigCache {
groupList.put(key, loadCWGroup(key, groupSection)); groupList.put(key, loadCWGroup(key, groupSection));
} }
if (canDoProtocolLib) {
warn("Protocollib support is deprecated and will be removed in future versions. If you have an actual" +
" use case for it (aka plugin does not work without it), please reach out via discord (https://discord.youhavetrouble.me).");
}
return saveConfig(); return saveConfig();
} }
@@ -177,7 +223,7 @@ public class ConfigCache {
return groupList; return groupList;
} }
private void warn(String log) { public void warn(String log) {
if (logger == null) { if (logger == null) {
System.out.println("WARNING: "+log); System.out.println("WARNING: "+log);
return; return;
@@ -2,6 +2,6 @@ package eu.endermite.commandwhitelist.common;
public enum MessageType { public enum MessageType {
CHAT, ACTIONBAR CHAT, ACTIONBAR, CHAT_AND_ACTIONBAR
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.1</version> <version>2.13.0</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
@@ -52,7 +52,7 @@ public class CommandWhitelistVelocity {
private void reloadConfig() { private void reloadConfig() {
if (configCache == null) if (configCache == null)
configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, logger); configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, false, logger);
else else
configCache.reloadConfig(); configCache.reloadConfig();
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.1</version> <version>2.13.0</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
@@ -62,7 +62,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
public void loadConfig() { public void loadConfig() {
if (configCache == null) if (configCache == null)
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, getLogger()); configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, true, getLogger());
else else
configCache.reloadConfig(); configCache.reloadConfig();
} }
@@ -5,7 +5,9 @@ import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall; import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences; import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.event.ChatEvent;
@@ -45,6 +47,21 @@ public class BungeeChatEventListener implements Listener {
case ACTIONBAR: case ACTIONBAR:
audiences.player(player).sendActionBar(message); audiences.player(player).sendActionBar(message);
break; break;
case CHAT_AND_ACTIONBAR:
audiences.player(player).sendMessage(message);
audiences.player(player).sendActionBar(message);
break;
}
if(configCache.command_denied_sound_enabled) {
try {
String soundKey = configCache.command_denied_sound_key;
Key sound = Key.key(soundKey);
float soundVolume = configCache.command_denied_sound_volume;
float soundPitch = configCache.command_denied_sound_pitch;
audiences.player(player).playSound(Sound.sound(sound, Sound.Source.UI, soundVolume, soundPitch));
} catch (Exception e) {
configCache.warn("Invalid sound. unable to play sound!");
}
} }
return; return;
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.12.1</version> <version>2.13.0</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>
+1
View File
@@ -13,6 +13,7 @@ precisely what commands players can see and use.
<ul> <ul>
<li>Lock selected commands behind permission <li>Lock selected commands behind permission
<li>Overwrite default "no such command" message with your branding <li>Overwrite default "no such command" message with your branding
<li>Play configurable sounds when a command is denied</li>
<li>Block tab completion</li> <li>Block tab completion</li>
<li>Block command execution</li> <li>Block command execution</li>
<li>Block completion and execution of specified subcommands</li> <li>Block completion and execution of specified subcommands</li>