Compare commits

..

4 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
9 changed files with 52 additions and 17 deletions
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</parent>
<artifactId>Bukkit</artifactId>
@@ -122,13 +122,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
* @param player Bukkit Player
* @return subcommands unavailable for the player
*/
public static HashSet<String> getSuggestions(org.bukkit.entity.Player player) {
public static HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
@@ -11,12 +11,13 @@ import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.util.HashSet;
public class PlayerCommandPreProcessListener implements Listener {
@EventHandler(priority = EventPriority.LOWEST)
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
public void PlayerExecuteCommand(PlayerCommandPreprocessEvent event) {
Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</parent>
<artifactId>Common</artifactId>
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</parent>
<artifactId>Velocity</artifactId>
@@ -4,9 +4,11 @@ import com.google.inject.Inject;
import com.google.inject.Injector;
import com.mojang.brigadier.Command;
import com.velocitypowered.api.command.CommandSource;
import com.velocitypowered.api.event.PostOrder;
import com.velocitypowered.api.event.Subscribe;
import com.velocitypowered.api.event.command.CommandExecuteEvent;
import com.velocitypowered.api.event.command.PlayerAvailableCommandsEvent;
import com.velocitypowered.api.event.player.TabCompleteEvent;
import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
import com.velocitypowered.api.plugin.annotation.DataDirectory;
import com.velocitypowered.api.proxy.Player;
@@ -22,10 +24,7 @@ import org.bstats.velocity.Metrics;
import org.slf4j.Logger;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.*;
public class CommandWhitelistVelocity {
@@ -74,7 +73,7 @@ public class CommandWhitelistVelocity {
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
}
@Subscribe
@Subscribe(order = PostOrder.LAST)
@SuppressWarnings("UnstableApiUsage")
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
Player player = event.getPlayer();
@@ -95,11 +94,45 @@ public class CommandWhitelistVelocity {
// Workaround for velocity executing "/ command" as valid command
String command = event.getCommand().trim();
if (command.startsWith("/")) command = command.substring(1);
HashSet<String> allowedCommands = getCommands(player);
String label = CommandUtil.getCommandLabel(command);
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label))
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label)) {
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
return;
}
HashSet<String> bannedSubCommands = getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (command.startsWith(bannedSubCommand)) {
event.setResult(CommandExecuteEvent.CommandResult.denied());
player.sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied));
return;
}
}
}
/**
* THIS IS FOR CLIENTS ON 1.12 AND BELOW, NOT GUARANTEED TO WORK, IF IT DOESN'T, PR OF GTFO
*/
@Subscribe
public void onUserTabCompleteEvent(TabCompleteEvent event) {
Player player = event.getPlayer();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String buffer = event.getPartialMessage();
if (event.getSuggestions().isEmpty()) return;
List<String> newSuggestions = CommandUtil.filterSuggestions(
buffer,
event.getSuggestions(),
getSuggestions(player)
);
event.getSuggestions().clear();
event.getSuggestions().addAll(newSuggestions);
}
public ConfigCache getConfigCache() {
@@ -127,12 +160,13 @@ public class CommandWhitelistVelocity {
* @param player Velocity Player
* @return subcommands unavailable for the player
*/
public HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) {
public HashSet<String> getSuggestions(Player player) {
HashSet<String> suggestionList = new HashSet<>();
HashMap<String, CWGroup> groups = configCache.getGroupList();
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
+1 -1
View File
@@ -6,7 +6,7 @@
<parent>
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
</parent>
<artifactId>Waterfall</artifactId>
@@ -100,7 +100,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission(s.getValue().getPermission())) continue;
if (!player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
+1 -1
View File
@@ -6,7 +6,7 @@
<groupId>eu.endermite.commandwhitelist</groupId>
<artifactId>CommandWhitelist</artifactId>
<version>2.9.0</version>
<version>2.10.0</version>
<modules>
<module>CommandWhitelistCommon</module>
<module>CommandWhitelistBukkit</module>