Compare commits

..
28 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
YouHaveTrouble 55ee46e167 bump version 2026-08-26 14:11:58 +02:00
OverwriteMC 55b9647890 Validate tab completion requests before exposing command suggestions (#113)
* validate the requested command before exposing argument completions

* fix waterfall tab completion filtering

* some formatting

basic idea formatting wont be bad
2026-08-26 14:06:07 +02:00
YouHaveTrouble 6e38130675 update configurationmaster version 2025-12-08 10:16:04 +01:00
YouHaveTrouble 3b3621d1d2 update dependencies 2025-12-07 12:02:34 +01:00
YouHaveTrouble 6a3dc807af bump version 2025-07-24 16:53:44 +02:00
YouHaveTrouble c5bf4b757f update to 1.21.7-8 compatible bukkit adventure platform 2025-07-24 16:51:18 +02:00
YouHaveTrouble 402dd8b48f migrate to java 21 2025-07-24 16:44:17 +02:00
YouHaveTrouble 74af326f80 update paper repo link and adventure libs 2025-07-15 18:34:19 +02:00
YouHaveTrouble 7a707068e2 added ability to send command denied message as action bar in bukkit and waterfall 2024-12-17 17:14:50 +01:00
YouHaveTrouble b4fda1cb9e bump version 2024-07-14 14:21:14 +02:00
YouHaveTrouble a42f546e4d add subcommand execution blocker to velocity 2024-07-14 14:21:06 +02:00
YouHaveTrouble 7222b910e5 mini cleanup 2024-07-14 14:20:37 +02:00
YouHaveTrouble e3c6103ec7 the permission was flipped all those years... 2024-07-14 14:19:55 +02:00
YouHaveTrouble 1872ea87d7 bump version 2024-06-27 17:13:30 +02:00
YouHaveTrouble 1295e497b7 placeholder for executed command for bukkit and waterfall version 2024-06-27 17:13:23 +02:00
YouHaveTrouble 1755cf5c2b bump version 2024-06-26 21:18:35 +02:00
YouHaveTrouble f53ca566bf go back to 1.19.4 api because 1.21 requires java 21 to access!!!1111111one 2024-06-26 21:18:27 +02:00
YouHaveTrouble c5af7595d9 Merge pull request #89 from R00tB33rMan/dependency-upgrades
Guice 7.0.0 Compatibility & Various Safe Dependency Upgrades
2024-06-26 21:14:01 +02:00
R00tB33rMan a30253d8bb Upgrade various dependencies and replace outdated import with working import for Guice 7.0.0 compatibility 2024-06-26 14:49:18 -04:00
YouHaveTrouble ccb3dafb82 Merge pull request #86 from gecko10000/event-priority
Change PreprocessEvent priority to handle more deny messages
2024-04-15 19:10:25 +02:00
gecko10000 fe254e7684 Change PreprocessEvent priority to handle more deny messages 2024-04-15 10:06:46 -07:00
YouHaveTrouble 350f50588e remove stray log 2023-11-05 22:06:18 +01:00
YouHaveTrouble 9a5820bbd6 bump version 2023-11-05 22:04:35 +01:00
YouHaveTrouble 3c31081b42 do not correct the command input
in case some mongoloid plugin decides to not filter out the / and rawdog the message into Player#performCommand
2023-11-05 22:04:29 +01:00
YouHaveTrouble 75b91a70d3 fix resetting config 2023-06-09 19:20:57 +02:00
18 changed files with 324 additions and 101 deletions
+14 -20
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.8.0</version>
<version>2.13.0</version>
</parent>
<artifactId>Bukkit</artifactId>
@@ -15,7 +15,7 @@
<description>You decide what commands players can use or tab complete on your server!</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>youhavetrouble.me</url>
@@ -25,7 +25,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -51,7 +51,7 @@
</relocation>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>eu.endermite</shadedPattern>
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
</relocation>
</relocations>
</configuration>
@@ -73,12 +73,12 @@
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
<id>sonatype-snapshots</id>
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
@@ -86,19 +86,19 @@
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.21.8-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId>
<version>4.1.1</version>
<version>4.4.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.11.0</version>
<version>4.23.0</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -108,22 +108,16 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<groupId>net.dmulloy2</groupId>
<artifactId>ProtocolLib</artifactId>
<version>5.0.0</version>
<version>5.4.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.17</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
@@ -20,7 +20,10 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
public class CommandWhitelistBukkit extends JavaPlugin {
@@ -69,9 +72,9 @@ public class CommandWhitelistBukkit extends JavaPlugin {
File configFile = new File("plugins/CommandWhitelist/config.yml");
if (configCache == null) {
try {
configCache = new ConfigCache(configFile, true, getSLF4JLogger());
configCache = new ConfigCache(configFile, true, true, getSLF4JLogger());
} catch (NoSuchMethodError e) {
configCache = new ConfigCache(configFile, true, null);
configCache = new ConfigCache(configFile, true, true, null);
}
return;
}
@@ -85,7 +88,8 @@ public class CommandWhitelistBukkit extends JavaPlugin {
for (Player p : Bukkit.getOnlinePlayers()) {
p.updateCommands();
}
} catch (Exception ignored) {}
} catch (Exception ignored) {
}
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded));
});
}
@@ -122,13 +126,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
* @param player Bukkit Player
* @return subcommands unavailable for the player
*/
public static HashSet<String> getSuggestions(org.bukkit.entity.Player player) {
public static HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
@@ -13,11 +13,12 @@ public class AsyncTabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void onCommandTabComplete(AsyncTabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return;
Player player = (Player) event.getSender();
if (!(event.getSender() instanceof Player player)) return;
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer();
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
int commandEnd = buffer.indexOf(' ');
if (commandEnd < 0 || buffer.charAt(0) != '/' || !CommandWhitelistBukkit.getCommands(player)
.contains(buffer.substring(1, commandEnd).toLowerCase())) {
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented " + event.getSender().getName() + "'s tab completion (sus packet)");
event.setCancelled(true);
return;
@@ -5,39 +5,68 @@ import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.HashSet;
public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
@EventHandler(priority = EventPriority.LOWEST)
public void PlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
String label = caseSensitiveLabel.toLowerCase();
String messageWithoutSlash = event.getMessage().startsWith("/") ? event.getMessage().substring(1) : event.getMessage();
String fullCommand = event.getMessage().substring(label.length()+1);
fullCommand = "/"+label+fullCommand;
event.setMessage(fullCommand);
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
if (!commands.contains(label)) {
event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
Component message = CWCommand.getParsedErrorMessage(
messageWithoutSlash,
config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)
);
switch (config.messageType) {
case CHAT:
audiences.player(player).sendMessage(message);
break;
case ACTIONBAR:
audiences.player(player).sendActionBar(message);
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;
}
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
if (messageWithoutSlash.startsWith(bannedSubCommand)) {
event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
return;
@@ -13,11 +13,12 @@ public class TabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL)
public void onCommandTabComplete(TabCompleteEvent event) {
if (!(event.getSender() instanceof Player)) return;
Player player = (Player) event.getSender();
if (!(event.getSender() instanceof Player player)) return;
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer();
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
int commandEnd = buffer.indexOf(' ');
if (commandEnd < 0 || buffer.charAt(0) != '/' || !CommandWhitelistBukkit.getCommands(player)
.contains(buffer.substring(1, commandEnd).toLowerCase())) {
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented " + event.getSender().getName() + "'s tab completion (sus packet)");
event.setCancelled(true);
return;
@@ -18,6 +18,7 @@ import org.bukkit.plugin.Plugin;
import java.util.HashSet;
@Deprecated(forRemoval = true)
public class PacketCommandPreProcessListener {
public static void protocol(CommandWhitelistBukkit plugin) {
+17 -11
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.8.0</version>
<version>2.13.0</version>
</parent>
<artifactId>Common</artifactId>
@@ -15,7 +15,7 @@
<description>You decide what commands players can use or tab complete on your server!</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>youhavetrouble.me</url>
@@ -25,7 +25,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -44,6 +44,12 @@
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>${project.name}-${project.parent.version}</finalName>
<relocations>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
@@ -60,7 +66,7 @@
<repositories>
<repository>
<id>pluginwiki-repo</id>
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
<url>https://repo.bsdevelopment.org/releases</url>
</repository>
<repository>
<id>velocitypowered-repo</id>
@@ -68,7 +74,7 @@
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public</url>
</repository>
</repositories>
@@ -76,31 +82,31 @@
<dependency>
<groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-BETA-6</version>
<version>v2.0.0-rc.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.2-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.13.1</version>
<version>4.23.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId>
<version>1.19-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
@@ -2,6 +2,7 @@ package eu.endermite.commandwhitelist.common;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
import net.kyori.adventure.key.Key;
import java.io.File;
import java.io.IOException;
@@ -12,16 +13,22 @@ public class ConfigCache {
private final File configFile;
private ConfigFile config;
private final Object logger;
private final boolean canDoProtocolLib;
private final boolean canDoProtocolLib, supportsCommandDeniedMessage;
private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>();
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 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 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.canDoProtocolLib = canDoProtocolLib;
this.supportsCommandDeniedMessage = supportsCommandDeniedMessage;
this.logger = logger;
try {
@@ -42,8 +49,11 @@ public class ConfigCache {
}
config.addDefault("messages.prefix", "CommandWhitelist > ");
if (supportsCommandDeniedMessage) {
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_such_subcommand", "<red>No subcommand by that name.");
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
@@ -56,6 +66,14 @@ 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.");
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()) {
List<String> exampleCommands = new ArrayList<>();
exampleCommands.add("example");
@@ -92,8 +110,8 @@ public class ConfigCache {
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
prefix = config.getString("messages.prefix");
command_denied = config.getString("messages.command_denied");
subcommand_denied = config.getString("messages.subcommand_denied");
command_denied = config.getString("messages.command_denied", "No such command.");
subcommand_denied = config.getString("messages.subcommand_denied", "You cannot use this subcommand");
no_permission = config.getString("messages.no_permission");
no_such_subcommand = config.getString("messages.no_such_subcommand");
config_reloaded = config.getString("messages.config_reloaded");
@@ -101,13 +119,54 @@ public class ConfigCache {
removed_from_whitelist = config.getString("messages.removed_from_whitelist");
group_doesnt_exist = config.getString("messages.group_doesnt_exist");
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);
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)) {
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();
}
@@ -164,7 +223,7 @@ public class ConfigCache {
return groupList;
}
private void warn(String log) {
public void warn(String log) {
if (logger == null) {
System.out.println("WARNING: "+log);
return;
@@ -0,0 +1,7 @@
package eu.endermite.commandwhitelist.common;
public enum MessageType {
CHAT, ACTIONBAR, CHAT_AND_ACTIONBAR
}
@@ -6,6 +6,10 @@ import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.Tag;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -133,4 +137,23 @@ public class CWCommand {
}
}
/**
* Get a message component for a command denied message
* @param inputCommandString command that was denied as string
* @param message raw message to display
* @return parsed message component
*/
public static Component getParsedErrorMessage(String inputCommandString, String message) {
MiniMessage miniMessage = MiniMessage.builder()
.tags(TagResolver.builder()
.resolvers(StandardTags.defaults(), commandContentResolver(inputCommandString))
.build())
.build();
return miniMessage.deserialize(message);
}
private static TagResolver commandContentResolver(String rawCommand) {
return TagResolver.resolver("command", (context, builder) -> Tag.selfClosingInserting(Component.text(rawCommand)));
}
}
+7 -7
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.8.0</version>
<version>2.13.0</version>
</parent>
<artifactId>Velocity</artifactId>
@@ -15,7 +15,7 @@
<description>You decide what commands players can use or tab complete on your server!</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>youhavetrouble.me</url>
@@ -25,7 +25,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -76,7 +76,7 @@
<repositories>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public</url>
</repository>
<repository>
<id>minecraft-libraries</id>
@@ -92,7 +92,7 @@
<dependency>
<groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId>
<version>3.1.2-SNAPSHOT</version>
<version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
@@ -104,7 +104,7 @@
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-velocity</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -1,11 +1,14 @@
package eu.endermite.commandwhitelist.velocity;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.mojang.brigadier.Command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
@@ -20,12 +23,8 @@ import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import javax.inject.Inject;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
public class CommandWhitelistVelocity {
@@ -53,7 +52,7 @@ public class CommandWhitelistVelocity {
private void reloadConfig() {
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
configCache.reloadConfig();
}
@@ -74,7 +73,7 @@ public class CommandWhitelistVelocity {
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
}
@Subscribe
@Subscribe(order = PostOrder.LAST)
@SuppressWarnings("UnstableApiUsage")
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
Player player = event.getPlayer();
@@ -95,11 +94,45 @@ public class CommandWhitelistVelocity {
// Workaround for velocity executing "/ command" as valid command
String command = event.getCommand().trim();
if (command.startsWith("/")) command = command.substring(1);
HashSet<String> allowedCommands = getCommands(player);
String label = CommandUtil.getCommandLabel(command);
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label))
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
return;
}
HashSet<String> bannedSubCommands = getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (command.startsWith(bannedSubCommand)) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
player.sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied));
return;
}
}
}
/**
* THIS IS FOR CLIENTS ON 1.12 AND BELOW, NOT GUARANTEED TO WORK, IF IT DOESN'T, PR OF GTFO
*/
@Subscribe
public void onUserTabCompleteEvent(TabCompleteEvent event) {
Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getPartialMessage();
if (event.getSuggestions().isEmpty()) return;
List<String> newSuggestions = CommandUtil.filterSuggestions(
buffer,
event.getSuggestions(),
getSuggestions(player)
);
event.getSuggestions().clear();
event.getSuggestions().addAll(newSuggestions);
}
public ConfigCache getConfigCache() {
@@ -127,12 +160,13 @@ public class CommandWhitelistVelocity {
* @param player Velocity Player
* @return subcommands unavailable for the player
*/
public HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) {
public HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
+9 -9
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.8.0</version>
<version>2.13.0</version>
</parent>
<artifactId>Waterfall</artifactId>
@@ -15,7 +15,7 @@
<description>You decide what commands players can use or tab complete on your server!</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<url>youhavetrouble.me</url>
@@ -25,7 +25,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -74,7 +74,7 @@
</repository>
<repository>
<id>papermc</id>
<url>https://papermc.io/repo/repository/maven-public/</url>
<url>https://repo.papermc.io/repository/maven-public</url>
</repository>
</repositories>
@@ -88,25 +88,25 @@
<dependency>
<groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-platform-bungeecord</artifactId>
<version>4.1.0</version>
<version>4.4.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.10.1</version>
<version>4.23.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId>
<version>3.0.0</version>
<version>3.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>
@@ -62,7 +62,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
public void loadConfig() {
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
configCache.reloadConfig();
}
@@ -100,7 +100,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
@@ -5,8 +5,12 @@ import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.sound.Sound;
import net.kyori.adventure.text.Component;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.event.ChatEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
@@ -15,7 +19,7 @@ import java.util.HashSet;
public class BungeeChatEventListener implements Listener {
@EventHandler
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
public void onChatEvent(ChatEvent event) {
if (event.isCancelled()) return;
if (!(event.getSender() instanceof ProxiedPlayer)) return;
if (!event.isProxyCommand()) return;
@@ -32,7 +36,33 @@ public class BungeeChatEventListener implements Listener {
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
if (!commands.contains(label)) {
event.setCancelled(true);
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)));
Component message = CWCommand.getParsedErrorMessage(
command,
configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)
);
switch (configCache.messageType) {
case CHAT:
audiences.player(player).sendMessage(message);
break;
case ACTIONBAR:
audiences.player(player).sendActionBar(message);
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;
}
@@ -7,19 +7,35 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
import java.util.List;
public class BungeeTabcompleteListener implements Listener {
@EventHandler
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
if (event.getSuggestions().isEmpty()) return;
if (!(event.getSender() instanceof ProxiedPlayer)) return;
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
CommandUtil.filterSuggestions(
String cursor = event.getCursor();
int commandEnd = cursor.indexOf(' ');
if (commandEnd >= 0 && cursor.charAt(0) == '/') {
String command = cursor.substring(1, commandEnd).toLowerCase();
if (CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().isExecutableCommand(command, player)
&& !CommandWhitelistWaterfall.getCommands(player).contains(command)) {
event.setCancelled(true);
return;
}
}
if (event.getSuggestions().isEmpty()) return;
List<String> suggestions = CommandUtil.filterSuggestions(
event.getCursor(),
event.getSuggestions(),
CommandWhitelistWaterfall.getSuggestions(player)
);
event.getSuggestions().clear();
event.getSuggestions().addAll(suggestions);
}
}
+22 -5
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.8.0</version>
<version>2.13.0</version>
<modules>
<module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module>
@@ -19,7 +19,7 @@
<description>Control what commands players can use</description>
<properties>
<java.version>1.8</java.version>
<java.version>21</java.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
@@ -28,7 +28,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
@@ -37,7 +37,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
@@ -47,6 +47,19 @@
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>${project.name}-${project.version}</finalName>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>net.kyori</pattern>
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
@@ -65,13 +78,17 @@
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
<repository>
<id>papermc</id>
<url>https://repo.papermc.io/repository/maven-public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId>
<version>4.11.0</version>
<version>4.23.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
+1
View File
@@ -13,6 +13,7 @@ precisely what commands players can see and use.
<ul>
<li>Lock selected commands behind permission
<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 command execution</li>
<li>Block completion and execution of specified subcommands</li>