mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 14:36:56 +00:00
Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 9e5b5b5fc7 | |||
| 67ca2c2458 | |||
| 99f7c245da | |||
| cd4c41f1f2 | |||
| 8a86568ce9 | |||
| b08234d268 | |||
| 2c7a089fae | |||
| 41ff6d9d3e |
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Bukkit</artifactId>
|
||||
@@ -86,19 +86,19 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.1.1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<version>4.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -110,7 +110,7 @@
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>4.6.0</version>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
+5
-7
@@ -6,14 +6,12 @@ import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessLis
|
||||
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
|
||||
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
|
||||
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
|
||||
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
|
||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -42,11 +40,10 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
|
||||
if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) {
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||
} else {
|
||||
PacketCommandPreProcessListener.protocol(this);
|
||||
PacketCommandSendListener.protocol(this);
|
||||
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
||||
getLogger().warning("Using ProtocolLib for command filter!");
|
||||
getLogger().warning("Please make sure you actually need this. This is not a \"better way to do it\".");
|
||||
}
|
||||
try {
|
||||
// Use paper's async tab completions if possible
|
||||
@@ -55,6 +52,7 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
} catch (ClassNotFoundException ignored) {
|
||||
}
|
||||
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||
|
||||
PluginCommand command = getCommand("commandwhitelist");
|
||||
if (command != null) {
|
||||
@@ -74,9 +72,9 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
} catch (NoSuchMethodError e) {
|
||||
configCache = new ConfigCache(configFile, true, null);
|
||||
}
|
||||
return;
|
||||
}
|
||||
else
|
||||
configCache.reloadConfig();
|
||||
configCache.reloadConfig();
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender sender) {
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ public class BukkitCommandExecutor implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistBukkit.getServerCommands(), new File("plugins/CommandWhitelist/config.yml"))) {
|
||||
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."));
|
||||
|
||||
+5
-2
@@ -1,6 +1,7 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
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;
|
||||
@@ -16,8 +17,10 @@ public class PlayerCommandPreProcessListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
String label = CommandUtil.getCommandLabel(event.getMessage().toLowerCase());
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
|
||||
String label = caseSensitiveLabel.toLowerCase();
|
||||
event.setMessage(event.getMessage().replaceFirst(caseSensitiveLabel, label));
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
|
||||
|
||||
+4
-2
@@ -34,9 +34,11 @@ public class PacketCommandPreProcessListener {
|
||||
if (!string.startsWith("/")) return;
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
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);
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||
if (!commands.contains(label)) {
|
||||
|
||||
-40
@@ -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()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Common</artifactId>
|
||||
@@ -88,13 +88,13 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<version>4.11.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.17.1-R0.1-SNAPSHOT</version>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Velocity</artifactId>
|
||||
|
||||
+6
-3
@@ -11,6 +11,7 @@ import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||
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.velocity.command.VelocityMainCommand;
|
||||
@@ -87,10 +88,12 @@ public class CommandWhitelistVelocity {
|
||||
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
// Workaround for velocity executing "/ command" as valid command
|
||||
String command = event.getCommand().trim();
|
||||
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
String command = event.getCommand().split(" ")[0];
|
||||
if (server.getCommandManager().hasCommand(command)
|
||||
&& !allowedCommands.contains(command))
|
||||
String label = CommandUtil.getCommandLabel(command);
|
||||
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label))
|
||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.2</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Waterfall</artifactId>
|
||||
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
|
||||
return;
|
||||
}
|
||||
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistWaterfall.getServerCommands(), new File("plugins/CommandWhitelist/config.yml"))) {
|
||||
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."));
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.4.0</version>
|
||||
<version>2.5.2</version>
|
||||
<modules>
|
||||
<module>CommandWhitelistCommon</module>
|
||||
<module>CommandWhitelistBukkit</module>
|
||||
@@ -46,7 +46,7 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -71,7 +71,7 @@
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<version>4.11.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
Reference in New Issue
Block a user