Compare commits

...

16 Commits

Author SHA1 Message Date
YouHaveTrouble b7d7646641 fix subcommand blocker
subcommandblocker broke when command included part of the subcommand, so for ex. /help he would remove "he" from the command and it would return as "/lp".
2021-07-02 16:14:20 +02:00
YouHaveTrouble 697a5e5720 priority shift 2021-06-02 21:22:12 +02:00
YouHaveTrouble 598756fec0 version bump 2021-06-02 16:00:36 +02:00
YouHaveTrouble 95ea1d8319 this probably needs to be handled anyway
ignoreCancelled seems to introduce the issue of completions not being filtered in some cases, and it shouldn't cause problems by running anyway
2021-06-02 15:52:13 +02:00
YouHaveTrouble 9da87b2769 fixed missing ignoreCancelled 2021-05-22 15:53:11 +02:00
YouHaveTrouble 12ed028460 guess what, legacy issues again. 2021-05-16 19:17:45 +02:00
YouHaveTrouble 66e6bff28e no idea how they managed to dispatch player command without / but ok 2021-05-07 00:43:54 +02:00
YouHaveTrouble 332e98f4a0 add fancy server counters 2021-03-30 16:34:34 +02:00
YouHaveTrouble 2085002c59 fix preProcessEvent no being registered in legacy mode 2021-03-26 15:36:05 +01:00
YouHaveTrouble 38d9d5115e add github actions 2021-03-15 15:08:23 +01:00
YouHaveTrouble 2fda6ac23e Merge remote-tracking branch 'origin/master' 2021-03-15 15:06:22 +01:00
YouHaveTrouble 6a4a27e7b3 fix legacy mode event registration 2021-03-15 15:01:17 +01:00
YouHaveTrouble 42bfaa2efb version bump and update depends 2021-03-15 15:00:46 +01:00
YouHaveTrouble adbf02a4c3 Create FUNDING.yml 2021-02-21 14:12:58 +01:00
YouHaveTrouble 94d5afdb47 version bump 2021-02-02 22:37:04 +01:00
YouHaveTrouble c943455392 remove all copies of completion 2021-02-02 22:29:49 +01:00
10 changed files with 116 additions and 20 deletions
+12
View File
@@ -0,0 +1,12 @@
# These are supported funding model platforms
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: YouHaveTrouble
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
+36
View File
@@ -0,0 +1,36 @@
name: Build CommandWhitelist Jar
on:
push:
branches:
- master
pull_request:
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout Git repo
uses: actions/checkout@v1
- name: Restore Maven cache
uses: actions/cache@v1
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: Set up JDK 1.8
uses: actions/setup-java@v1
with:
java-version: 1.8
- name: Build with Maven
run: mvn package --file pom.xml
- name: Copy artifacts
uses: actions/upload-artifact@master
with:
name: CommandWhitelist
path: target/CommandWhitelist*.jar
+3 -3
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite</groupId> <groupId>eu.endermite</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>1.7.0</version> <version>1.7.8</version>
<packaging>jar</packaging> <packaging>jar</packaging>
<name>CommandWhitelist</name> <name>CommandWhitelist</name>
@@ -84,7 +84,7 @@
<dependency> <dependency>
<groupId>org.spigotmc</groupId> <groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId> <artifactId>spigot-api</artifactId>
<version>1.16.3-R0.1-SNAPSHOT</version> <version>1.16.5-R0.1-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
@@ -108,7 +108,7 @@
<dependency> <dependency>
<groupId>com.comphenix.protocol</groupId> <groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId> <artifactId>ProtocolLib</artifactId>
<version>4.5.0</version> <version>4.6.0</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>
+3
View File
@@ -1,6 +1,9 @@
Command Whitelist is a plugin that allows you to control Command Whitelist is a plugin that allows you to control
precisely what commands players can see and use. precisely what commands players can see and use.
<img src="https://img.shields.io/bstats/servers/8705?label=Spigot%20servers%20using%20CommandWhitelist&style=for-the-badge">
<img src="https://img.shields.io/bstats/servers/8704?label=Proxy%20servers%20using%20CommandWhitelist&style=for-the-badge">
<h3>Plugin Features</h3> <h3>Plugin Features</h3>
<ul> <ul>
@@ -63,4 +63,11 @@ public class CommandsList {
return last; return last;
} }
public static String getCommandLabel(String cmd) {
String[] parts = cmd.split(" ");
if (parts[0].startsWith("/"))
parts[0] = parts[0].substring(1);
return parts[0];
}
} }
@@ -28,15 +28,16 @@ public class CommandWhitelist extends JavaPlugin {
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib"); Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this); getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
if (!isLegacy) { if (!isLegacy) {
if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) { if (!getConfigCache().isUseProtocolLib() || protocollib == null || !protocollib.isEnabled()) {
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
} else { } else {
PacketCommandSendListener.protocol(this); PacketCommandSendListener.protocol(this);
getLogger().info(ChatColor.AQUA+"Using ProtocolLib for command filter!"); getLogger().info(ChatColor.AQUA+"Using ProtocolLib for command filter!");
} }
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
} else { } else {
getLogger().info(ChatColor.AQUA+"Running in legacy mode..."); getLogger().info(ChatColor.AQUA+"Running in legacy mode...");
if (protocollib != null) { if (protocollib != null) {
@@ -46,8 +47,6 @@ public class CommandWhitelist extends JavaPlugin {
} }
} }
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
getCommand("commandwhitelist").setExecutor(new MainCommand()); getCommand("commandwhitelist").setExecutor(new MainCommand());
getCommand("commandwhitelist").setTabCompleter(new MainCommand()); getCommand("commandwhitelist").setTabCompleter(new MainCommand());
@@ -19,6 +19,7 @@ public class LegacyPlayerTabChatCompleteListener {
public static void protocol(CommandWhitelist plugin) { public static void protocol(CommandWhitelist plugin) {
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager(); ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
tabCompleteServerBound(protocolManager, plugin); tabCompleteServerBound(protocolManager, plugin);
tabCompleteClientBound(protocolManager, plugin);
} }
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) { public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) {
@@ -52,4 +53,33 @@ public class LegacyPlayerTabChatCompleteListener {
} }
}); });
} }
public static void tabCompleteClientBound(ProtocolManager protocolManager, Plugin plugin) {
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.TAB_COMPLETE) {
@Override
public void onPacketReceiving(PacketEvent event) {
try {
Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) {
return;
}
PacketContainer packet = event.getPacket();
String command = packet.getSpecificModifier(String.class).read(0);
String label = CommandsList.getCommandLabel(command);
List<String> commandList = CommandsList.getCommands(player);
if (command.equals("/"))
return;
for (String cmd : commandList) {
if (cmd.startsWith("/"+label+" "))
return;
}
event.setCancelled(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
} }
@@ -13,22 +13,23 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class PlayerCommandPreProcessListener implements Listener { public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) if (player.hasPermission("commandwhitelist.bypass"))
return; return;
String command = event.getMessage().toLowerCase(); String command = event.getMessage().toLowerCase();
if (command.startsWith("/"))
command = command.substring(1);
for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) { for (Map.Entry<String, List<String>> s : CommandWhitelist.getConfigCache().getPermList().entrySet()) {
if (!player.hasPermission("commandwhitelist.commands." + s.getKey())) if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
continue; continue;
for (String comm : s.getValue()) { for (String comm : s.getValue()) {
comm = comm.toLowerCase(); comm = comm.toLowerCase();
if (command.equalsIgnoreCase("/" + comm) || command.startsWith("/" + comm + " ")) { if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
String rawCmd = event.getMessage();
List<String> bannedSubCommands = CommandsList.getSuggestions(player); List<String> bannedSubCommands = CommandsList.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) { for (String bannedSubCommand : bannedSubCommands) {
if (rawCmd.startsWith("/"+bannedSubCommand)) { if (command.startsWith(bannedSubCommand)) {
event.setCancelled(true); event.setCancelled(true);
ConfigCache config = CommandWhitelist.getConfigCache(); ConfigCache config = CommandWhitelist.getConfigCache();
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied()))); player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.getPrefix() + RandomStuff.getMessage(config.getCommandDeniedList(), config.getSubCommandDenied())));
@@ -8,7 +8,7 @@ import org.bukkit.event.Listener;
import java.util.*; import java.util.*;
public class PlayerCommandSendListener implements Listener { public class PlayerCommandSendListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.NORMAL)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) { public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
Player player = event.getPlayer(); Player player = event.getPlayer();
if (player.hasPermission("commandwhitelist.bypass")) if (player.hasPermission("commandwhitelist.bypass"))
@@ -14,20 +14,28 @@ public class TabCompleteBlockerListener implements Listener {
return; return;
Player player = (Player) event.getSender(); Player player = (Player) event.getSender();
String buffer = event.getBuffer(); String buffer = event.getBuffer();
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
List<String> blockedCommands = CommandsList.getSuggestions(player); List<String> blockedCommands = CommandsList.getSuggestions(player);
List<String> suggestions = event.getCompletions(); List<String> suggestions = event.getCompletions();
for (String s : blockedCommands) { for (String s : blockedCommands) {
String slast = CommandsList.getLastArgument(s); String slast = CommandsList.getLastArgument(s);
String scommand = s.replace(slast, ""); String scommand = s.replace(slast, "");
cmd = cmd.replace(CommandsList.getLastArgument(cmd), ""); String[] cmdSplit = buffer.split(" ");
if (cmd.startsWith("/" + scommand + " ")) { StringBuilder cmdBuilder = new StringBuilder();
continue; for (int i = 0; i <= cmdSplit.length-1; i++)
} cmdBuilder.append(cmdSplit[i]).append(" ");
String cmd = cmdBuilder.toString();
if (cmd.startsWith("/"+scommand)) {
// This sometimes throws exceptions. No clue why, it just does. try/catch is the only fix.
// Probably happening when plugin adds suggestions in this event on the same priority - not confirmed.
try { try {
while (suggestions.contains(slast))
suggestions.remove(slast); suggestions.remove(slast);
} catch (Exception ignored) {} } catch (Exception ignored) {}
} }
}
event.setCompletions(suggestions); event.setCompletions(suggestions);
} }
} }