Compare commits

...

50 Commits

Author SHA1 Message Date
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
YouHaveTrouble 6b31e7c76c bump version 2023-06-09 11:04:04 +02:00
YouHaveTrouble 1ea3f3f550 update config dependency 2023-06-09 11:03:45 +02:00
YouHaveTrouble 00f7d292fa Merge pull request #70 from DaJokni/1.20
Update ConfigurationMaster-API to add 1.20 support
2023-06-07 23:52:43 +02:00
DaJokni 653cd0e242 Change protocollib version to 5.0.0, because snapshot no longer exists 2023-06-07 22:29:20 +03:00
DaJokni 6b1763a260 Update ConfigurationMaster-API to add 1.20 support 2023-06-07 22:27:15 +03:00
YouHaveTrouble cd3ee4b214 bump version 2023-04-29 13:22:09 +02:00
YouHaveTrouble ea54ae3175 Merge "Improved Velocity Module" #69 from 4drian3d/velocity
Improved Velocity Module
2023-04-29 13:19:46 +02:00
Adrian c36ac056d5 Simplified suggestions 2023-04-28 18:25:19 -05:00
Adrian 7186c4de6c Improved Velocity Module 2023-04-28 17:53:37 -05:00
YouHaveTrouble dfa254f263 update funding 2023-04-26 23:48:01 +02:00
YouHaveTrouble e80629d708 bump version 2023-04-26 23:23:07 +02:00
YouHaveTrouble f41bfa7cd1 make bukkit module folia compatible
thanks to @Aitooor for figuring out what needed to be changed
2023-04-26 23:20:52 +02:00
YouHaveTrouble 5af0cdef84 update depends 2023-04-26 23:15:14 +02:00
YouHaveTrouble e232953f11 bump version 2022-12-29 21:56:35 +01:00
YouHaveTrouble e8b284db69 do not complete from legacy tab complete packet 2022-12-29 21:54:50 +01:00
YouHaveTrouble ed1024c9e7 make minimessage resolve all tags 2022-12-20 19:04:22 +01:00
YouHaveTrouble 153ad5f983 fix errors when using regex expressions in executing command 2022-10-08 20:12:08 +02:00
YouHaveTrouble 9e5b5b5fc7 fix velocity weird command handling 2022-09-28 19:24:18 +02:00
YouHaveTrouble 67ca2c2458 lowercase command label 2022-09-28 13:33:03 +02:00
YouHaveTrouble 99f7c245da bump version 2022-07-31 15:59:16 +02:00
YouHaveTrouble cd4c41f1f2 make protocollib message a warning so it maybe catches more eyes 2022-07-31 15:59:05 +02:00
YouHaveTrouble 8a86568ce9 drop packet level command send event 2022-07-31 15:47:56 +02:00
YouHaveTrouble b08234d268 update depends 2022-07-31 15:47:04 +02:00
YouHaveTrouble 2c7a089fae bump version 2022-05-01 15:22:00 +02:00
YouHaveTrouble 41ff6d9d3e don't replace config. whops 2022-05-01 15:20:00 +02:00
YouHaveTrouble 9e13c7b2f1 bump version 2022-04-19 20:35:01 +02:00
YouHaveTrouble 0716514787 add full commands list dump command 2022-04-19 20:33:47 +02:00
YouHaveTrouble 428ee93996 make keybind and clickevent work 2022-04-01 20:44:48 +02:00
YouHaveTrouble 8b45057544 make <newline> work 2022-03-21 17:11:46 +01:00
YouHaveTrouble 29f7b6438e / don't make sense here 2022-03-18 19:44:12 +01:00
YouHaveTrouble 8de56d2863 change how minimessage is shaded in + bump version 2022-03-18 19:43:39 +01:00
YouHaveTrouble d8421126e2 this doesn't work 2022-03-18 19:22:26 +01:00
YouHaveTrouble 0554ef59f7 update adventure platforms 2022-03-18 19:01:37 +01:00
YouHaveTrouble 0567640eea update and relocate minimessage 2022-03-18 13:14:23 +01:00
22 changed files with 539 additions and 284 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
# These are supported funding model platforms # These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] github: YouHaveTrouble
patreon: # Replace with a single Patreon username patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username open_collective: # Replace with a single Open Collective username
ko_fi: YouHaveTrouble ko_fi: YouHaveTrouble
+14 -8
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.2.6</version> <version>2.10.0</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -25,7 +25,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.13.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -86,13 +86,19 @@
<dependency> <dependency>
<groupId>io.papermc.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version> <version>1.19.4-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-platform-bukkit</artifactId> <artifactId>adventure-platform-bukkit</artifactId>
<version>4.0.1</version> <version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -104,19 +110,19 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>4.6.0</version> <version>5.1.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bukkit</artifactId> <artifactId>bstats-bukkit</artifactId>
<version>3.0.0</version> <version>3.0.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.mojang</groupId> <groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId> <artifactId>brigadier</artifactId>
<version>1.0.17</version> <version>1.0.18</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -1,29 +1,27 @@
package eu.endermite.commandwhitelist.bukkit; package eu.endermite.commandwhitelist.bukkit;
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor; import eu.endermite.commandwhitelist.bukkit.command.BukkitCommandExecutor;
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener; import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener; import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener; import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener; import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener; import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
import eu.endermite.commandwhitelist.common.CWGroup; import eu.endermite.commandwhitelist.common.CWGroup;
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.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import org.bstats.bukkit.Metrics; import org.bstats.bukkit.Metrics;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.help.HelpTopic;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.HashSet; import java.util.concurrent.CompletableFuture;
import java.util.Map;
public class CommandWhitelistBukkit extends JavaPlugin { public class CommandWhitelistBukkit extends JavaPlugin {
@@ -43,11 +41,10 @@ public class CommandWhitelistBukkit extends JavaPlugin {
if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) { if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) {
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this); getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
} else { } else {
PacketCommandPreProcessListener.protocol(this); PacketCommandPreProcessListener.protocol(this);
PacketCommandSendListener.protocol(this); getLogger().warning("Using ProtocolLib for command filter!");
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!"); getLogger().warning("Please make sure you actually need this. This is not a \"better way to do it\".");
} }
try { try {
// Use paper's async tab completions if possible // Use paper's async tab completions if possible
@@ -56,10 +53,11 @@ public class CommandWhitelistBukkit extends JavaPlugin {
} catch (ClassNotFoundException ignored) { } catch (ClassNotFoundException ignored) {
} }
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this); getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
PluginCommand command = getCommand("commandwhitelist"); PluginCommand command = getCommand("commandwhitelist");
if (command != null) { if (command != null) {
MainCommandExecutor executor = new MainCommandExecutor(); BukkitCommandExecutor executor = new BukkitCommandExecutor();
command.setExecutor(executor); command.setExecutor(executor);
command.setTabCompleter(executor); command.setTabCompleter(executor);
} }
@@ -75,20 +73,20 @@ public class CommandWhitelistBukkit extends JavaPlugin {
} catch (NoSuchMethodError e) { } catch (NoSuchMethodError e) {
configCache = new ConfigCache(configFile, true, null); configCache = new ConfigCache(configFile, true, null);
} }
return;
} }
else configCache.reloadConfig();
configCache.reloadConfig();
} }
public void reloadPluginConfig(CommandSender sender) { public void reloadPluginConfig(CommandSender sender) {
getServer().getScheduler().runTaskAsynchronously(this, () -> { CompletableFuture.runAsync(() -> {
reloadPluginConfig(); reloadPluginConfig();
try { try {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
p.updateCommands(); p.updateCommands();
} }
} catch (Exception ignored) {} } catch (Exception ignored) {}
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.config_reloaded)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded));
}); });
} }
@@ -124,13 +122,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
* @param player Bukkit Player * @param player Bukkit Player
* @return subcommands unavailable for the 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<>(); HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList(); HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
@@ -151,4 +149,18 @@ public class CommandWhitelistBukkit extends JavaPlugin {
} }
return commandDeniedMessage; return commandDeniedMessage;
} }
public static ArrayList<String> getServerCommands() {
try {
return new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet());
} catch (NoSuchMethodError error) {
HashSet<String> commands = new HashSet<>();
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
String cmd = topic.getName();
if (Character.isUpperCase(cmd.charAt(0))) continue;
commands.add(topic.getName());
}
return new ArrayList<>(commands);
}
}
} }
@@ -2,20 +2,18 @@ package eu.endermite.commandwhitelist.bukkit.command;
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.commands.CWCommand; import eu.endermite.commandwhitelist.common.commands.CWCommand;
import net.kyori.adventure.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import org.bukkit.Bukkit;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor; import org.bukkit.command.TabExecutor;
import org.bukkit.help.HelpTopic;
import java.util.ArrayList; import java.io.File;
import java.util.HashSet;
import java.util.List; import java.util.List;
public class MainCommandExecutor implements TabExecutor { public class BukkitCommandExecutor implements TabExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
@@ -31,37 +29,49 @@ public class MainCommandExecutor implements TabExecutor {
switch (commandType) { switch (commandType) {
case RELOAD: case RELOAD:
if (!sender.hasPermission(CWPermission.RELOAD.permission())) { if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true; return true;
} }
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender); CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
return true; return true;
case ADD: case ADD:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true; return true;
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1])) if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1]))); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1])));
else else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1]))); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
return true; return true;
case REMOVE: case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true; return true;
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1])) if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1]))); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1])));
else else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1]))); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return true; return true;
case DUMP:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
return true;
}
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistBukkit.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) {
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
}
return true;
case HELP: case HELP:
default: default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
@@ -74,18 +84,13 @@ public class MainCommandExecutor implements TabExecutor {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) { public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
List<String> serverCommands; return CWCommand.commandSuggestions(
try { CommandWhitelistBukkit.getConfigCache(),
serverCommands = new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet()); CommandWhitelistBukkit.getServerCommands(),
} catch (NoSuchMethodError error) { args,
HashSet<String> commands = new HashSet<>(); sender.hasPermission(CWPermission.RELOAD.permission()),
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) { sender.hasPermission(CWPermission.ADMIN.permission()),
String cmd = topic.getName(); CWCommand.ImplementationType.BUKKIT
if (Character.isUpperCase(cmd.charAt(0))) continue; );
commands.add(topic.getName());
}
serverCommands = new ArrayList<>(commands);
}
return CWCommand.commandSuggestions(CommandWhitelistBukkit.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.BUKKIT);
} }
} }
@@ -9,7 +9,6 @@ import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
public class AsyncTabCompleteBlockerListener implements Listener { public class AsyncTabCompleteBlockerListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
@@ -18,8 +17,14 @@ public class AsyncTabCompleteBlockerListener implements Listener {
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer(); String buffer = event.getBuffer();
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true); if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
if (event.getCompletions().isEmpty()) return; CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)");
event.setCancelled(true);
return;
}
if (event.getCompletions().isEmpty()) {
return;
}
event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player))); event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player)));
} }
@@ -1,42 +1,52 @@
package eu.endermite.commandwhitelist.bukkit.listeners; package eu.endermite.commandwhitelist.bukkit.listeners;
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit; import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
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.platform.bukkit.BukkitAudiences; import net.kyori.adventure.platform.bukkit.BukkitAudiences;
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;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.HashSet; import java.util.HashSet;
public class PlayerCommandPreProcessListener implements Listener { public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.LOWEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { public void PlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String label = CommandUtil.getCommandLabel(event.getMessage().toLowerCase()); String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
String label = caseSensitiveLabel.toLowerCase();
String messageWithoutSlash = event.getMessage().startsWith("/") ? event.getMessage().substring(1) : event.getMessage();
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
ConfigCache config = CommandWhitelistBukkit.getConfigCache(); ConfigCache config = CommandWhitelistBukkit.getConfigCache();
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player); HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
if (!commands.contains(label)) { if (!commands.contains(label)) {
event.setCancelled(true); event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); Component message = CWCommand.getParsedErrorMessage(
messageWithoutSlash,
config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)
);
audiences.player(player).sendMessage(message);
return; return;
} }
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player); HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) { if (messageWithoutSlash.startsWith(bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied)); audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
return; return;
} }
} }
} }
} }
@@ -17,13 +17,12 @@ public class TabCompleteBlockerListener implements Listener {
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getBuffer(); String buffer = event.getBuffer();
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) { if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (/[tab] packet)"); CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
if (event.getCompletions().isEmpty()) { if (event.getCompletions().isEmpty()) {
CommandWhitelistBukkit.getConfigCache().debug("Tab completion not provided");
return; return;
} }
event.setCompletions( event.setCompletions(
@@ -34,21 +34,23 @@ public class PacketCommandPreProcessListener {
if (!string.startsWith("/")) return; if (!string.startsWith("/")) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
ConfigCache config = CommandWhitelistBukkit.getConfigCache(); ConfigCache config = CommandWhitelistBukkit.getConfigCache();
String label = CommandUtil.getCommandLabel(string.toLowerCase()); String caseSensitiveLabel = CommandUtil.getCommandLabel(string);
String label = caseSensitiveLabel.toLowerCase();
packet.getStrings().write(0, string.replaceFirst(caseSensitiveLabel, label));
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player); HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
if (!commands.contains(label)) { if (!commands.contains(label)) {
event.setCancelled(true); event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label))); audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
return; return;
} }
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player); HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) { if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(config.prefix + config.subcommand_denied)); CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
return; return;
} }
} }
@@ -1,40 +0,0 @@
package eu.endermite.commandwhitelist.bukkit.listeners.protocollib;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.ProtocolLibrary;
import com.comphenix.protocol.ProtocolManager;
import com.comphenix.protocol.events.ListenerPriority;
import com.comphenix.protocol.events.PacketAdapter;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.mojang.brigadier.tree.RootCommandNode;
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
import eu.endermite.commandwhitelist.common.CWPermission;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.HashSet;
public class PacketCommandSendListener {
public static void protocol(CommandWhitelistBukkit plugin) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
commandSendListener(protocolManager, plugin);
}
public static void commandSendListener(ProtocolManager protocolManager, Plugin plugin) {
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.COMMANDS) {
@Override
public void onPacketSending(PacketEvent event) {
Player player = event.getPlayer();
if (event.isPlayerTemporary()) return;
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
PacketContainer packet = event.getPacket();
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
node.getChildren().removeIf((cmd) -> !commandList.contains(cmd.getName()));
}
});
}
}
@@ -5,6 +5,7 @@ api-version: 1.13
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
authors: [YouHaveTrouble] authors: [YouHaveTrouble]
website: youhavetrouble.me website: youhavetrouble.me
folia-supported: true
softdepend: softdepend:
- ProtocolLib - ProtocolLib
description: Control what commands players can use description: Control what commands players can use
+13 -7
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.2.6</version> <version>2.10.0</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
@@ -25,7 +25,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.13.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -76,25 +76,31 @@
<dependency> <dependency>
<groupId>com.github.thatsmusic99</groupId> <groupId>com.github.thatsmusic99</groupId>
<artifactId>ConfigurationMaster-API</artifactId> <artifactId>ConfigurationMaster-API</artifactId>
<version>v2.0.0-BETA-1</version> <version>v2.0.0-BETA-9</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>1.1.0</version> <version>3.3.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.papermc.paper</groupId> <groupId>io.papermc.paper</groupId>
<artifactId>paper-api</artifactId> <artifactId>paper-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version> <version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>io.github.waterfallmc</groupId> <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId> <artifactId>waterfall-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version> <version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -1,5 +1,9 @@
package eu.endermite.commandwhitelist.common; package eu.endermite.commandwhitelist.common;
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@@ -63,4 +67,32 @@ public class CommandUtil {
return parts[0]; return parts[0];
} }
/**
* Dumps command list to a file
*
* @param serverCommands Commands to dump
* @return True on successful file save
*/
public static boolean dumpAllBukkitCommands(ArrayList<String> serverCommands, File file) {
try {
File parent = new File(file.getParent());
if (!parent.exists())
parent.mkdir();
if (!file.exists())
file.createNewFile();
} catch (IOException e) {
return false;
}
try {
ConfigFile dumpFile = ConfigFile.loadConfig(file);
dumpFile.set("commands", serverCommands);
dumpFile.save();
} catch (Exception e) {
return false;
}
return true;
}
} }
@@ -24,13 +24,22 @@ public class ConfigCache {
this.canDoProtocolLib = canDoProtocolLib; this.canDoProtocolLib = canDoProtocolLib;
this.logger = logger; this.logger = logger;
reloadConfig(); try {
reloadConfig();
} catch (Exception e) {
e.printStackTrace();
}
} }
public boolean reloadConfig() { public boolean reloadConfig() {
createFiles(); createFiles();
config = ConfigFile.loadConfig(configFile); try {
config = ConfigFile.loadConfig(configFile);
} catch (Exception e) {
e.printStackTrace();
return false;
}
config.addDefault("messages.prefix", "CommandWhitelist > "); config.addDefault("messages.prefix", "CommandWhitelist > ");
config.addDefault("messages.command_denied", "No such command."); config.addDefault("messages.command_denied", "No such command.");
@@ -106,7 +115,7 @@ public class ConfigCache {
try { try {
config.save(); config.save();
return true; return true;
} catch (IOException e) { } catch (Exception e) {
return false; return false;
} }
} }
@@ -3,9 +3,12 @@ package eu.endermite.commandwhitelist.common.commands;
import eu.endermite.commandwhitelist.common.CWGroup; import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.ConfigCache; import eu.endermite.commandwhitelist.common.ConfigCache;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.format.NamedTextColor; import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.minimessage.MiniMessage; import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.transformation.TransformationType; 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.ArrayList;
import java.util.Collection; import java.util.Collection;
@@ -13,15 +16,7 @@ import java.util.List;
public class CWCommand { public class CWCommand {
public static MiniMessage miniMessage = MiniMessage.builder() public static MiniMessage miniMessage = MiniMessage.miniMessage();
.removeDefaultTransformations()
.transformation(TransformationType.COLOR)
.transformation(TransformationType.DECORATION)
.transformation(TransformationType.GRADIENT)
.transformation(TransformationType.RESET)
.transformation(TransformationType.RAINBOW)
.transformation(TransformationType.PRE)
.build();
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) { public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
CWGroup cwGroup = configCache.getGroupList().get(group); CWGroup cwGroup = configCache.getGroupList().get(group);
@@ -41,24 +36,24 @@ public class CWCommand {
} }
public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) { public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
Component component = miniMessage.parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble") final TextComponent.Builder builder = Component.text();
.append(Component.newline()); builder.append(miniMessage.deserialize("<rainbow><bold>CommandWhitelist by YouHaveTrouble</bold>"), Component.newline());
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE))); builder.append(Component.text(baseCommand + " help", NamedTextColor.AQUA), Component.text(" - Displays this message", NamedTextColor.BLUE));
if (showReloadCommand) { if (showReloadCommand) {
component = component.append(Component.newline()); builder.append(Component.newline());
component = component.append(Component.text("/" + baseCommand + " reload").color(NamedTextColor.AQUA).append(Component.text(" - Reloads plugin configuration").color(NamedTextColor.BLUE))); builder.append(Component.text(baseCommand + " reload", NamedTextColor.AQUA), Component.text(" - Reloads plugin configuration", NamedTextColor.BLUE));
} }
if (showAdminCommands) { if (showAdminCommands) {
component = component.append(Component.newline()); builder.append(Component.newline());
component = component.append(Component.text("/" + baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Add a command to selected permission group").color(NamedTextColor.BLUE))); builder.append(Component.text(baseCommand + " add <group> <command>", NamedTextColor.AQUA), Component.text(" - Add a command to selected permission group", NamedTextColor.BLUE));
component = component.append(Component.newline()); builder.append(Component.newline());
component = component.append(Component.text("/" + baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Removes a command from selected permission group").color(NamedTextColor.BLUE))); builder.append(Component.text(baseCommand + " remove <group> <command>", NamedTextColor.AQUA), Component.text(" - Removes a command from selected permission group", NamedTextColor.BLUE));
} }
return component; return builder.build();
} }
public enum CommandType { public enum CommandType {
ADD, REMOVE, HELP, RELOAD ADD, REMOVE, HELP, RELOAD, DUMP
} }
public enum ImplementationType { public enum ImplementationType {
@@ -83,6 +78,7 @@ public class CWCommand {
if (adminPerm) { if (adminPerm) {
list.add("add"); list.add("add");
list.add("remove"); list.add("remove");
list.add("dump");
} }
} }
return list; return list;
@@ -95,6 +91,8 @@ public class CWCommand {
list.add("add"); list.add("add");
if ("remove".startsWith(args[0]) && adminPerm) if ("remove".startsWith(args[0]) && adminPerm)
list.add("remove"); list.add("remove");
if ("dump".startsWith(args[0]) && adminPerm)
list.add("dump");
return list; return list;
case 2: case 2:
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) { if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
@@ -139,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)));
}
} }
+17 -7
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.2.6</version> <version>2.10.0</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
@@ -25,7 +25,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.13.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -50,6 +50,16 @@
<shadedPattern>eu.endermite.bstats</shadedPattern> <shadedPattern>eu.endermite.bstats</shadedPattern>
</relocation> </relocation>
</relocations> </relocations>
<artifactSet>
<excludes>
<exclude>net.kyori:adventure-api</exclude>
<exclude>net.kyori:adventure-key</exclude>
<exclude>net.kyori:examination-api</exclude>
<exclude>net.kyori:examination-string</exclude>
<exclude>org.jetbrains:annotations</exclude>
<exclude>org.intellij.lang:annotations</exclude>
</excludes>
</artifactSet>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>
@@ -65,8 +75,8 @@
<repositories> <repositories>
<repository> <repository>
<id>velocitypowered-repo</id> <id>papermc</id>
<url>https://repo.velocitypowered.com/releases/</url> <url>https://papermc.io/repo/repository/maven-public/</url>
</repository> </repository>
<repository> <repository>
<id>minecraft-libraries</id> <id>minecraft-libraries</id>
@@ -82,7 +92,7 @@
<dependency> <dependency>
<groupId>com.velocitypowered</groupId> <groupId>com.velocitypowered</groupId>
<artifactId>velocity-api</artifactId> <artifactId>velocity-api</artifactId>
<version>3.0.0</version> <version>3.3.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -94,7 +104,7 @@
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-velocity</artifactId> <artifactId>bstats-velocity</artifactId>
<version>2.2.1</version> <version>3.0.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -1,78 +1,84 @@
package eu.endermite.commandwhitelist.velocity; package eu.endermite.commandwhitelist.velocity;
import com.velocitypowered.api.command.CommandMeta; 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.command.CommandSource;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent; 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.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory; import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.Player;
import com.velocitypowered.api.proxy.ProxyServer; import com.velocitypowered.api.proxy.ProxyServer;
import eu.endermite.commandwhitelist.common.CWGroup; import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
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.velocity.command.VelocityMainCommand; import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
import net.kyori.adventure.identity.Identity;
import org.bstats.charts.SimplePie; import org.bstats.charts.SimplePie;
import org.bstats.velocity.Metrics; import org.bstats.velocity.Metrics;
import org.slf4j.Logger; import org.slf4j.Logger;
import javax.inject.Inject;
import java.io.File;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
public class CommandWhitelistVelocity { public class CommandWhitelistVelocity {
private static CommandWhitelistVelocity plugin; private final ProxyServer server;
private static ProxyServer server; private ConfigCache configCache;
private static ConfigCache configCache; private final Path folder;
private static Path folder; private final Logger logger;
private static Logger logger;
private final Metrics.Factory metricsFactory; private final Metrics.Factory metricsFactory;
private final Injector injector;
@Inject @Inject
public CommandWhitelistVelocity(ProxyServer server, Logger logger, @DataDirectory final Path folder, Metrics.Factory metricsFactory) { public CommandWhitelistVelocity(
CommandWhitelistVelocity.server = server; ProxyServer server,
CommandWhitelistVelocity.folder = folder; Logger logger,
CommandWhitelistVelocity.plugin = this; @DataDirectory final Path folder,
CommandWhitelistVelocity.logger = logger; Metrics.Factory metricsFactory,
Injector injector
) {
this.server = server;
this.folder = folder;
this.logger = logger;
this.metricsFactory = metricsFactory; this.metricsFactory = metricsFactory;
this.injector = injector;
} }
private static void reloadConfig() { private void reloadConfig() {
if (configCache == null) if (configCache == null)
configCache = new ConfigCache(new File(String.valueOf(folder), "config.yml"), false, logger); configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, logger);
else else
configCache.reloadConfig(); configCache.reloadConfig();
} }
public static void reloadConfig(CommandSource source) { public int reloadConfig(CommandSource source) {
server.getScheduler().buildTask(plugin, () -> { server.getScheduler().buildTask(this, () -> {
reloadConfig(); reloadConfig();
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix + getConfigCache().config_reloaded)); source.sendMessage(CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded));
}).schedule(); }).schedule();
return Command.SINGLE_SUCCESS;
} }
@Subscribe @Subscribe
public void onProxyInitialization(ProxyInitializeEvent event) { public void onProxyInitialization(ProxyInitializeEvent event) {
reloadConfig(); reloadConfig();
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build(); injector.getInstance(VelocityMainCommand.class).register();
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
Metrics metrics = metricsFactory.make(this, 8704); Metrics metrics = metricsFactory.make(this, 8704);
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity")); metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
} }
@Subscribe @Subscribe(order = PostOrder.LAST)
@SuppressWarnings("UnstableApiUsage")
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) { public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player); HashSet<String> allowedCommands = getCommands(player);
event.getRootNode().getChildren().removeIf((commandNode) -> event.getRootNode().getChildren().removeIf((commandNode) ->
server.getCommandManager().hasCommand(commandNode.getName()) server.getCommandManager().hasCommand(commandNode.getName())
&& !allowedCommands.contains(commandNode.getName()) && !allowedCommands.contains(commandNode.getName())
@@ -80,20 +86,56 @@ public class CommandWhitelistVelocity {
} }
@Subscribe @Subscribe
public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.CommandExecuteEvent event) { public void onUserCommandExecuteEvent(CommandExecuteEvent event) {
if (!(event.getCommandSource() instanceof Player)) return; if (!(event.getCommandSource() instanceof Player)) return;
Player player = (Player) event.getCommandSource(); Player player = (Player) event.getCommandSource();
if (player.hasPermission(CWPermission.BYPASS.permission())) return; if (player.hasPermission(CWPermission.BYPASS.permission())) return;
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player); // Workaround for velocity executing "/ command" as valid command
String command = event.getCommand().split(" ")[0]; String command = event.getCommand().trim();
if (server.getCommandManager().hasCommand(command) if (command.startsWith("/")) command = command.substring(1);
&& !allowedCommands.contains(command))
HashSet<String> allowedCommands = getCommands(player);
String label = CommandUtil.getCommandLabel(command);
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); 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;
}
}
} }
public static ConfigCache getConfigCache() { /**
* 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() {
return configCache; return configCache;
} }
@@ -101,7 +143,7 @@ public class CommandWhitelistVelocity {
* @param player Velocity Player * @param player Velocity Player
* @return commands available to the player * @return commands available to the player
*/ */
public static HashSet<String> getCommands(Player player) { public HashSet<String> getCommands(Player player) {
HashMap<String, CWGroup> groups = configCache.getGroupList(); HashMap<String, CWGroup> groups = configCache.getGroupList();
HashSet<String> commandList = new HashSet<>(); HashSet<String> commandList = new HashSet<>();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
@@ -118,15 +160,20 @@ public class CommandWhitelistVelocity {
* @param player Velocity Player * @param player Velocity Player
* @return subcommands unavailable for the player * @return subcommands unavailable for the player
*/ */
public static HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) { public HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>(); HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
} }
public ArrayList<String> getServerCommands() {
return new ArrayList<>(server.getCommandManager().getAliases());
}
} }
@@ -1,83 +1,143 @@
package eu.endermite.commandwhitelist.velocity.command; package eu.endermite.commandwhitelist.velocity.command;
import com.google.inject.Inject;
import com.mojang.brigadier.Command;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import com.velocitypowered.api.command.BrigadierCommand;
import com.velocitypowered.api.command.CommandManager;
import com.velocitypowered.api.command.CommandSource; import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.permission.Tristate;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import eu.endermite.commandwhitelist.common.CWGroup;
import eu.endermite.commandwhitelist.common.CWPermission; 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 eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity; import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import java.util.ArrayList; import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public class VelocityMainCommand implements SimpleCommand { public final class VelocityMainCommand {
@Inject
private CommandManager commandManager;
@Inject
private CommandWhitelistVelocity plugin;
@Inject
@DataDirectory
private Path dataDirectory;
@Override public void register() {
public void execute(final Invocation invocation) { LiteralCommandNode<CommandSource> node = LiteralArgumentBuilder
CommandSource sender = invocation.source(); .<CommandSource>literal("vcw")
String[] args = invocation.arguments(); .requires(src -> src.getPermissionValue("commandwhitelist.command") != Tristate.FALSE)
String label = invocation.alias(); .executes(ctx -> {
CommandSource source = ctx.getSource();
source.sendMessage(CWCommand.helpComponent("vcw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission())));
return Command.SINGLE_SUCCESS;
})
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
.requires(src -> src.hasPermission(CWPermission.RELOAD.permission()))
.executes(ctx -> plugin.reloadConfig(ctx.getSource()))
)
.then(LiteralArgumentBuilder.<CommandSource>literal("add")
.requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
.then(RequiredArgumentBuilder.<CommandSource, String>argument("group", StringArgumentType.word())
.suggests((ctx, builder) -> {
plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest);
return builder.buildFuture();
})
.then(RequiredArgumentBuilder.<CommandSource, String>argument("command", StringArgumentType.word())
.suggests((ctx, builder) -> {
CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class));
if (group == null) return builder.buildFuture();
if (args.length == 0) { for (String cmd : plugin.getServerCommands()) {
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); if (cmd.charAt(0) == '/')
return; cmd = cmd.substring(1);
} if (cmd.indexOf(':') != -1) {
String[] cmdSplit = cmd.split(":");
if (cmdSplit.length < 2) continue;
cmd = cmdSplit[1];
}
if (group.getCommands().contains(cmd)) continue;
builder.suggest(cmd);
}
return builder.buildFuture();
})
.executes(ctx -> {
CommandSource source = ctx.getSource();
ConfigCache configCache = plugin.getConfigCache();
String arg1 = ctx.getArgument("group", String.class);
String arg2 = ctx.getArgument("command", String.class);
try { if (CWCommand.addToWhitelist(configCache, arg2, arg1))
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase()); source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.added_to_whitelist, arg2, arg1)));
switch (commandType) { else
case RELOAD: source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1)));
if (!sender.hasPermission(CWPermission.RELOAD.permission())) { return Command.SINGLE_SUCCESS;
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission)); })
return; )
} )
CommandWhitelistVelocity.reloadConfig(sender); )
return; .then(LiteralArgumentBuilder.<CommandSource>literal("remove")
case ADD: .requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { .then(RequiredArgumentBuilder.<CommandSource, String>argument("group", StringArgumentType.word())
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission)); .suggests((ctx, builder) -> {
return; plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest);
} return builder.buildFuture();
if (args.length == 3) { })
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1])) .then(RequiredArgumentBuilder.<CommandSource, String>argument("command", StringArgumentType.word())
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1]))); .suggests((ctx, builder) -> {
else CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class));
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1]))); if (group == null) return builder.buildFuture();
} else
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
return;
case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
sender.sendMessage(CWCommand.miniMessage.parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
return;
}
if (args.length == 3) {
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
else
sender.sendMessage(CWCommand.miniMessage.parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
} else
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
case HELP:
default:
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
}
} catch (IllegalArgumentException e) { for (String s : group.getCommands()) {
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); builder.suggest(s);
} }
return; return builder.buildFuture();
} })
.executes(ctx -> {
CommandSource source = ctx.getSource();
ConfigCache configCache = plugin.getConfigCache();
String arg1 = ctx.getArgument("group", String.class);
String arg2 = ctx.getArgument("command", String.class);
@Override if (CWCommand.removeFromWhitelist(configCache, arg2, arg1))
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) { source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.removed_from_whitelist, arg2, arg1)));
CommandSource source = invocation.source(); else
String[] args = invocation.arguments(); source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1)));
return CompletableFuture.supplyAsync(() -> { return Command.SINGLE_SUCCESS;
List<String> serverCommands = new ArrayList<>(); })
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.VELOCITY); )
}); )
)
.then(LiteralArgumentBuilder.<CommandSource>literal("dump")
.requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
.executes(ctx -> {
CommandSource source = ctx.getSource();
source.sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(plugin.getServerCommands(), dataDirectory.resolve("command_dump.yml").toFile())) {
source.sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
source.sendMessage(Component.text("Failed to save the file."));
}
return Command.SINGLE_SUCCESS;
})
)
.then(LiteralArgumentBuilder.<CommandSource>literal("help")
.executes(ctx -> {
CommandSource source = ctx.getSource();
source.sendMessage(CWCommand.helpComponent("cw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission())));
return Command.SINGLE_SUCCESS;
})
)
.build();
final BrigadierCommand command = new BrigadierCommand(node);
commandManager.register(commandManager.metaBuilder(command).plugin(plugin).build(), command);
} }
} }
+12 -6
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.2.6</version> <version>2.10.0</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
@@ -25,7 +25,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.13.0</version>
<configuration> <configuration>
<source>${java.version}</source> <source>${java.version}</source>
<target>${java.version}</target> <target>${java.version}</target>
@@ -34,7 +34,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId> <artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version> <version>3.6.0</version>
<executions> <executions>
<execution> <execution>
<phase>package</phase> <phase>package</phase>
@@ -88,19 +88,25 @@
<dependency> <dependency>
<groupId>io.github.waterfallmc</groupId> <groupId>io.github.waterfallmc</groupId>
<artifactId>waterfall-api</artifactId> <artifactId>waterfall-api</artifactId>
<version>1.17-R0.1-SNAPSHOT</version> <version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-platform-bungeecord</artifactId> <artifactId>adventure-platform-bungeecord</artifactId>
<version>4.0.1</version> <version>4.3.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.17.0</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.bstats</groupId> <groupId>org.bstats</groupId>
<artifactId>bstats-bungeecord</artifactId> <artifactId>bstats-bungeecord</artifactId>
<version>3.0.0</version> <version>3.0.2</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>
@@ -11,14 +11,13 @@ import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.CommandSender; import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Plugin; import net.md_5.bungee.api.plugin.Plugin;
import org.bstats.bungeecord.Metrics; import org.bstats.bungeecord.Metrics;
import org.bstats.charts.SimplePie; import org.bstats.charts.SimplePie;
import java.io.File; import java.io.File;
import java.util.HashMap; import java.util.*;
import java.util.HashSet;
import java.util.Map;
public final class CommandWhitelistWaterfall extends Plugin { public final class CommandWhitelistWaterfall extends Plugin {
@@ -71,7 +70,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
public void loadConfigAsync(CommandSender sender) { public void loadConfigAsync(CommandSender sender) {
getProxy().getScheduler().runAsync(this, () -> { getProxy().getScheduler().runAsync(this, () -> {
loadConfig(); loadConfig();
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
}); });
} }
@@ -101,7 +100,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
for (Map.Entry<String, CWGroup> s : groups.entrySet()) { for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default")) if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue; if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands()); suggestionList.addAll(s.getValue().getSubCommands());
} }
return suggestionList; return suggestionList;
@@ -122,4 +121,12 @@ public final class CommandWhitelistWaterfall extends Plugin {
} }
return commandDeniedMessage; return commandDeniedMessage;
} }
public static ArrayList<String> getServerCommands() {
ArrayList<String> serverCommands = new ArrayList<>();
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return serverCommands;
}
} }
@@ -1,6 +1,7 @@
package eu.endermite.commandwhitelist.waterfall.command; package eu.endermite.commandwhitelist.waterfall.command;
import eu.endermite.commandwhitelist.common.CWPermission; import eu.endermite.commandwhitelist.common.CWPermission;
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;
@@ -10,6 +11,7 @@ import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.TabExecutor; import net.md_5.bungee.api.plugin.TabExecutor;
import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -36,37 +38,49 @@ public class BungeeMainCommand extends Command implements TabExecutor {
switch (commandType) { switch (commandType) {
case RELOAD: case RELOAD:
if (!sender.hasPermission(CWPermission.RELOAD.permission())) { if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission));
return; return;
} }
CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender); CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender);
return; return;
case ADD: case ADD:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission));
return; return;
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.addToWhitelist(configCache, args[2], args[1])) if (CWCommand.addToWhitelist(configCache, args[2], args[1]))
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.added_to_whitelist)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.added_to_whitelist));
else else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist));
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
return; return;
case REMOVE: case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) { if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.no_permission)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission));
return; return;
} }
if (args.length == 3) { if (args.length == 3) {
if (CWCommand.removeFromWhitelist(configCache, args[2], args[1])) if (CWCommand.removeFromWhitelist(configCache, args[2], args[1]))
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.removed_from_whitelist)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.removed_from_whitelist));
else else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist)); audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist));
} else } else
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>")); audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return; return;
case DUMP:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
return;
}
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistWaterfall.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) {
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
} else {
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
}
return;
case HELP: case HELP:
default: default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()))); audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
@@ -80,10 +94,13 @@ public class BungeeMainCommand extends Command implements TabExecutor {
@Override @Override
public Iterable<String> onTabComplete(CommandSender sender, String[] args) { public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
List<String> serverCommands = new ArrayList<>(); return CWCommand.commandSuggestions(
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) { CommandWhitelistWaterfall.getConfigCache(),
serverCommands.add(command.getValue().getName()); CommandWhitelistWaterfall.getServerCommands(),
} args,
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.WATERFALL); sender.hasPermission(CWPermission.RELOAD.permission()),
sender.hasPermission(CWPermission.ADMIN.permission()),
CWCommand.ImplementationType.WATERFALL
);
} }
} }
@@ -6,7 +6,9 @@ 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.platform.bungeecord.BungeeAudiences; import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
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.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
@@ -15,7 +17,7 @@ import java.util.HashSet;
public class BungeeChatEventListener implements Listener { public class BungeeChatEventListener implements Listener {
@EventHandler @EventHandler
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) { public void onChatEvent(ChatEvent event) {
if (event.isCancelled()) return; if (event.isCancelled()) return;
if (!(event.getSender() instanceof ProxiedPlayer)) return; if (!(event.getSender() instanceof ProxiedPlayer)) return;
if (!event.isProxyCommand()) return; if (!event.isProxyCommand()) return;
@@ -32,7 +34,11 @@ public class BungeeChatEventListener implements Listener {
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player); HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
if (!commands.contains(label)) { if (!commands.contains(label)) {
event.setCancelled(true); event.setCancelled(true);
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label))); Component message = CWCommand.getParsedErrorMessage(
command,
configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)
);
audiences.player(player).sendMessage(message);
return; return;
} }
@@ -40,7 +46,7 @@ public class BungeeChatEventListener implements Listener {
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (command.startsWith(bannedSubCommand)) { if (command.startsWith(bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
audiences.player(player).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.subcommand_denied)); audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied));
return; return;
} }
} }
+46 -8
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.2.6</version> <version>2.10.0</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>
@@ -23,6 +23,50 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<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>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories> <repositories>
<repository> <repository>
<id>sonatype</id> <id>sonatype</id>
@@ -34,13 +78,7 @@
<dependency> <dependency>
<groupId>net.kyori</groupId> <groupId>net.kyori</groupId>
<artifactId>adventure-api</artifactId> <artifactId>adventure-api</artifactId>
<version>4.9.2</version> <version>4.17.0</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>net.kyori</groupId>
<artifactId>adventure-text-minimessage</artifactId>
<version>4.1.0-SNAPSHOT</version>
<scope>compile</scope> <scope>compile</scope>
</dependency> </dependency>
</dependencies> </dependencies>