Compare commits

..

6 Commits

11 changed files with 36 additions and 35 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.5.0</version> <version>2.5.5</version>
</parent> </parent>
<artifactId>Bukkit</artifactId> <artifactId>Bukkit</artifactId>
@@ -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,6 +1,7 @@
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;
@@ -16,8 +17,14 @@ public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.HIGHEST) @EventHandler(priority = EventPriority.HIGHEST)
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")) 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 fullCommand = event.getMessage().substring(label.length()+1);
fullCommand = "/"+label+fullCommand;
event.setMessage(fullCommand);
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences(); BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
ConfigCache config = CommandWhitelistBukkit.getConfigCache(); ConfigCache config = CommandWhitelistBukkit.getConfigCache();
@@ -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,9 +34,11 @@ 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)) {
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.5.0</version> <version>2.5.5</version>
</parent> </parent>
<artifactId>Common</artifactId> <artifactId>Common</artifactId>
@@ -5,28 +5,13 @@ import eu.endermite.commandwhitelist.common.ConfigCache;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
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.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;
import java.util.List; import java.util.List;
public class CWCommand { public class CWCommand {
public static MiniMessage miniMessage = MiniMessage.builder().tags( public static MiniMessage miniMessage = MiniMessage.miniMessage();
TagResolver.builder()
.resolver(StandardTags.color())
.resolver(StandardTags.decorations())
.resolver(StandardTags.gradient())
.resolver(StandardTags.font())
.resolver(StandardTags.reset())
.resolver(StandardTags.rainbow())
.resolver(StandardTags.translatable())
.resolver(StandardTags.newline())
.resolver(StandardTags.clickEvent())
.resolver(StandardTags.keybind())
.build()
).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);
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.5.0</version> <version>2.5.5</version>
</parent> </parent>
<artifactId>Velocity</artifactId> <artifactId>Velocity</artifactId>
@@ -11,6 +11,7 @@ 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;
@@ -87,10 +88,12 @@ public class CommandWhitelistVelocity {
if (player.hasPermission(CWPermission.BYPASS.permission())) return; 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); HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
String command = event.getCommand().split(" ")[0]; String label = CommandUtil.getCommandLabel(command);
if (server.getCommandManager().hasCommand(command) if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label))
&& !allowedCommands.contains(command))
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer()); event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
} }
+1 -1
View File
@@ -6,7 +6,7 @@
<parent> <parent>
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.5.0</version> <version>2.5.5</version>
</parent> </parent>
<artifactId>Waterfall</artifactId> <artifactId>Waterfall</artifactId>
+2 -2
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId> <groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId> <artifactId>CommandWhitelist</artifactId>
<version>2.5.0</version> <version>2.5.5</version>
<modules> <modules>
<module>CommandWhitelistCommon</module> <module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module> <module>CommandWhitelistBukkit</module>
@@ -46,7 +46,7 @@
</goals> </goals>
<configuration> <configuration>
<createDependencyReducedPom>false</createDependencyReducedPom> <createDependencyReducedPom>false</createDependencyReducedPom>
<finalName>${project.name}-${project.parent.version}</finalName> <finalName>${project.name}-${project.version}</finalName>
</configuration> </configuration>
</execution> </execution>
</executions> </executions>