mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e80629d708 | |||
| f41bfa7cd1 | |||
| 5af0cdef84 | |||
| e232953f11 | |||
| e8b284db69 | |||
| ed1024c9e7 | |||
| 153ad5f983 | |||
| 9e5b5b5fc7 | |||
| 67ca2c2458 |
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.6.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Bukkit</artifactId>
|
||||
|
||||
+2
-1
@@ -21,6 +21,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
|
||||
@@ -78,7 +79,7 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender sender) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
CompletableFuture.runAsync(() -> {
|
||||
reloadPluginConfig();
|
||||
try {
|
||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||
|
||||
+8
-3
@@ -9,7 +9,6 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
|
||||
public class AsyncTabCompleteBlockerListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@@ -18,8 +17,14 @@ public class AsyncTabCompleteBlockerListener implements Listener {
|
||||
Player player = (Player) event.getSender();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
String buffer = event.getBuffer();
|
||||
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
|
||||
if (event.getCompletions().isEmpty()) return;
|
||||
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
|
||||
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)));
|
||||
}
|
||||
|
||||
|
||||
+9
-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,14 @@ 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();
|
||||
|
||||
String fullCommand = event.getMessage().substring(label.length()+1);
|
||||
fullCommand = "/"+label+fullCommand;
|
||||
|
||||
event.setMessage(fullCommand);
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
|
||||
|
||||
+2
-3
@@ -17,13 +17,12 @@ public class TabCompleteBlockerListener implements Listener {
|
||||
Player player = (Player) event.getSender();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
String buffer = event.getBuffer();
|
||||
if (!buffer.endsWith(" ") && buffer.split(" ").length == 1) {
|
||||
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (/[tab] packet)");
|
||||
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
|
||||
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getCompletions().isEmpty()) {
|
||||
CommandWhitelistBukkit.getConfigCache().debug("Tab completion not provided");
|
||||
return;
|
||||
}
|
||||
event.setCompletions(
|
||||
|
||||
+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)) {
|
||||
|
||||
@@ -5,6 +5,7 @@ api-version: 1.13
|
||||
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
|
||||
authors: [YouHaveTrouble]
|
||||
website: youhavetrouble.me
|
||||
folia-supported: true
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
description: Control what commands players can use
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.6.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Common</artifactId>
|
||||
@@ -82,13 +82,13 @@
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>3.1.2-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<version>4.13.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
+1
-16
@@ -5,28 +5,13 @@ import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
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.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CWCommand {
|
||||
|
||||
public static MiniMessage miniMessage = MiniMessage.builder().tags(
|
||||
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 MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.6.0</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.5.0</version>
|
||||
<version>2.6.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Waterfall</artifactId>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.6.0</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>
|
||||
|
||||
Reference in New Issue
Block a user