mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
42 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6e38130675 | |||
| 3b3621d1d2 | |||
| 6a3dc807af | |||
| c5bf4b757f | |||
| 402dd8b48f | |||
| 74af326f80 | |||
| 7a707068e2 | |||
| b4fda1cb9e | |||
| a42f546e4d | |||
| 7222b910e5 | |||
| e3c6103ec7 | |||
| 1872ea87d7 | |||
| 1295e497b7 | |||
| 1755cf5c2b | |||
| f53ca566bf | |||
| c5af7595d9 | |||
| a30253d8bb | |||
| ccb3dafb82 | |||
| fe254e7684 | |||
| 350f50588e | |||
| 9a5820bbd6 | |||
| 3c31081b42 | |||
| 75b91a70d3 | |||
| 6b31e7c76c | |||
| 1ea3f3f550 | |||
| 00f7d292fa | |||
| 653cd0e242 | |||
| 6b1763a260 | |||
| cd3ee4b214 | |||
| ea54ae3175 | |||
| c36ac056d5 | |||
| 7186c4de6c | |||
| dfa254f263 | |||
| e80629d708 | |||
| f41bfa7cd1 | |||
| 5af0cdef84 | |||
| e232953f11 | |||
| e8b284db69 | |||
| ed1024c9e7 | |||
| 153ad5f983 | |||
| 9e5b5b5fc7 | |||
| 67ca2c2458 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
github: YouHaveTrouble
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: YouHaveTrouble
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.12.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Bukkit</artifactId>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>youhavetrouble.me</url>
|
||||
@@ -25,7 +25,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -34,7 +34,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -51,7 +51,7 @@
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>net.kyori</pattern>
|
||||
<shadedPattern>eu.endermite</shadedPattern>
|
||||
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
@@ -73,12 +73,12 @@
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
<id>sonatype-snapshots</id>
|
||||
<url>https://central.sonatype.com/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -86,19 +86,19 @@
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<version>1.21.8-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</artifactId>
|
||||
<version>4.1.1</version>
|
||||
<version>4.4.1-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<version>4.23.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -108,22 +108,16 @@
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>net.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>5.0.0-SNAPSHOT</version>
|
||||
<version>5.4.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bukkit</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>brigadier</artifactId>
|
||||
<version>1.0.17</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
+4
-3
@@ -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()) {
|
||||
@@ -121,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;
|
||||
|
||||
+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)));
|
||||
}
|
||||
|
||||
|
||||
+25
-7
@@ -1,36 +1,54 @@
|
||||
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;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
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.HIGHEST)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandPreprocessEvent event) {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public void PlayerExecuteCommand(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 messageWithoutSlash = event.getMessage().startsWith("/") ? event.getMessage().substring(1) : event.getMessage();
|
||||
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
|
||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||
if (!commands.contains(label)) {
|
||||
event.setCancelled(true);
|
||||
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||
Component message = CWCommand.getParsedErrorMessage(
|
||||
messageWithoutSlash,
|
||||
config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)
|
||||
);
|
||||
switch (config.messageType) {
|
||||
case CHAT:
|
||||
audiences.player(player).sendMessage(message);
|
||||
break;
|
||||
case ACTIONBAR:
|
||||
audiences.player(player).sendActionBar(message);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||
|
||||
for (String bannedSubCommand : bannedSubCommands) {
|
||||
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||
if (messageWithoutSlash.startsWith(bannedSubCommand)) {
|
||||
event.setCancelled(true);
|
||||
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
|
||||
return;
|
||||
@@ -38,4 +56,4 @@ public class PlayerCommandPreProcessListener implements Listener {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+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.12.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Common</artifactId>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>youhavetrouble.me</url>
|
||||
@@ -25,7 +25,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -34,7 +34,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -44,6 +44,12 @@
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>net.kyori</pattern>
|
||||
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -60,7 +66,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>pluginwiki-repo</id>
|
||||
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||
<url>https://repo.bsdevelopment.org/releases</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>velocitypowered-repo</id>
|
||||
@@ -68,7 +74,7 @@
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
<url>https://repo.papermc.io/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -76,31 +82,31 @@
|
||||
<dependency>
|
||||
<groupId>com.github.thatsmusic99</groupId>
|
||||
<artifactId>ConfigurationMaster-API</artifactId>
|
||||
<version>v2.0.0-BETA-1</version>
|
||||
<version>v2.0.0-rc.3</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<version>4.23.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.19-R0.1-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.waterfallmc</groupId>
|
||||
<artifactId>waterfall-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+4
-3
@@ -84,11 +84,12 @@ public class CommandUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
ConfigFile dumpFile = ConfigFile.loadConfig(file);
|
||||
dumpFile.set("commands", serverCommands);
|
||||
|
||||
try {
|
||||
ConfigFile dumpFile = ConfigFile.loadConfig(file);
|
||||
dumpFile.set("commands", serverCommands);
|
||||
dumpFile.save();
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
||||
+25
-3
@@ -17,6 +17,7 @@ public class ConfigCache {
|
||||
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
|
||||
removed_from_whitelist, group_doesnt_exist, subcommand_denied;
|
||||
public boolean useProtocolLib = false;
|
||||
public MessageType messageType = MessageType.CHAT;
|
||||
public boolean debug = false;
|
||||
|
||||
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) {
|
||||
@@ -24,13 +25,22 @@ public class ConfigCache {
|
||||
this.canDoProtocolLib = canDoProtocolLib;
|
||||
this.logger = logger;
|
||||
|
||||
reloadConfig();
|
||||
try {
|
||||
reloadConfig();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean reloadConfig() {
|
||||
|
||||
createFiles();
|
||||
config = ConfigFile.loadConfig(configFile);
|
||||
try {
|
||||
config = ConfigFile.loadConfig(configFile);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
config.addDefault("messages.prefix", "CommandWhitelist > ");
|
||||
config.addDefault("messages.command_denied", "No such command.");
|
||||
@@ -47,6 +57,8 @@ public class ConfigCache {
|
||||
if (canDoProtocolLib)
|
||||
config.addDefault("use_protocollib", false, "Do not enable if you don't have issues with aliased commands.\nThis requires server restart to take effect.");
|
||||
|
||||
config.addDefault("message_type", MessageType.CHAT.toString(), "Valid message types are CHAT and ACTIONBAR. Does nothing on velocity.");
|
||||
|
||||
if (config.isNew()) {
|
||||
List<String> exampleCommands = new ArrayList<>();
|
||||
exampleCommands.add("example");
|
||||
@@ -93,6 +105,16 @@ public class ConfigCache {
|
||||
group_doesnt_exist = config.getString("messages.group_doesnt_exist");
|
||||
useProtocolLib = config.getBoolean("use_protocollib");
|
||||
debug = config.getBoolean("debug", false);
|
||||
try {
|
||||
String chatTypeId = config.getString("message_type");
|
||||
if (chatTypeId == null) {
|
||||
warn("Invalid message type. Using CHAT.");
|
||||
} else {
|
||||
messageType = MessageType.valueOf(chatTypeId.toUpperCase(Locale.ENGLISH));
|
||||
}
|
||||
} catch (IllegalArgumentException e) {
|
||||
warn("Invalid message type. Using CHAT.");
|
||||
}
|
||||
|
||||
ConfigSection groupSection = config.getConfigSection("groups");
|
||||
for (String key : groupSection.getKeys(false)) {
|
||||
@@ -106,7 +128,7 @@ public class ConfigCache {
|
||||
try {
|
||||
config.save();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
package eu.endermite.commandwhitelist.common;
|
||||
|
||||
public enum MessageType {
|
||||
|
||||
CHAT, ACTIONBAR
|
||||
|
||||
}
|
||||
+33
-24
@@ -3,30 +3,20 @@ package eu.endermite.commandwhitelist.common.commands;
|
||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.Tag;
|
||||
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);
|
||||
@@ -46,20 +36,20 @@ public class CWCommand {
|
||||
}
|
||||
|
||||
public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
|
||||
Component component = miniMessage.deserialize("<rainbow><bold>CommandWhitelist by YouHaveTrouble</bold>")
|
||||
.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE)));
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
builder.append(miniMessage.deserialize("<rainbow><bold>CommandWhitelist by YouHaveTrouble</bold>"), Component.newline());
|
||||
builder.append(Component.text(baseCommand + " help", NamedTextColor.AQUA), Component.text(" - Displays this message", NamedTextColor.BLUE));
|
||||
if (showReloadCommand) {
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " reload").color(NamedTextColor.AQUA).append(Component.text(" - Reloads plugin configuration").color(NamedTextColor.BLUE)));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " reload", NamedTextColor.AQUA), Component.text(" - Reloads plugin configuration", NamedTextColor.BLUE));
|
||||
}
|
||||
if (showAdminCommands) {
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Add a command to selected permission group").color(NamedTextColor.BLUE)));
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Removes a command from selected permission group").color(NamedTextColor.BLUE)));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " add <group> <command>", NamedTextColor.AQUA), Component.text(" - Add a command to selected permission group", NamedTextColor.BLUE));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " remove <group> <command>", NamedTextColor.AQUA), Component.text(" - Removes a command from selected permission group", NamedTextColor.BLUE));
|
||||
}
|
||||
return component;
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public enum CommandType {
|
||||
@@ -147,4 +137,23 @@ public class CWCommand {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a message component for a command denied message
|
||||
* @param inputCommandString command that was denied as string
|
||||
* @param message raw message to display
|
||||
* @return parsed message component
|
||||
*/
|
||||
public static Component getParsedErrorMessage(String inputCommandString, String message) {
|
||||
MiniMessage miniMessage = MiniMessage.builder()
|
||||
.tags(TagResolver.builder()
|
||||
.resolvers(StandardTags.defaults(), commandContentResolver(inputCommandString))
|
||||
.build())
|
||||
.build();
|
||||
return miniMessage.deserialize(message);
|
||||
}
|
||||
|
||||
private static TagResolver commandContentResolver(String rawCommand) {
|
||||
return TagResolver.resolver("command", (context, builder) -> Tag.selfClosingInserting(Component.text(rawCommand)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.12.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Velocity</artifactId>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>youhavetrouble.me</url>
|
||||
@@ -25,7 +25,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -34,7 +34,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -50,6 +50,16 @@
|
||||
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
<artifactSet>
|
||||
<excludes>
|
||||
<exclude>net.kyori:adventure-api</exclude>
|
||||
<exclude>net.kyori:adventure-key</exclude>
|
||||
<exclude>net.kyori:examination-api</exclude>
|
||||
<exclude>net.kyori:examination-string</exclude>
|
||||
<exclude>org.jetbrains:annotations</exclude>
|
||||
<exclude>org.intellij.lang:annotations</exclude>
|
||||
</excludes>
|
||||
</artifactSet>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -66,7 +76,7 @@
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
<url>https://repo.papermc.io/repository/maven-public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>minecraft-libraries</id>
|
||||
@@ -82,7 +92,7 @@
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>3.1.2-SNAPSHOT</version>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@@ -94,7 +104,7 @@
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-velocity</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+80
-42
@@ -1,79 +1,84 @@
|
||||
package eu.endermite.commandwhitelist.velocity;
|
||||
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
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;
|
||||
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;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
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 {
|
||||
|
||||
private static CommandWhitelistVelocity plugin;
|
||||
private static ProxyServer server;
|
||||
private static ConfigCache configCache;
|
||||
private static Path folder;
|
||||
private static Logger logger;
|
||||
private final ProxyServer server;
|
||||
private ConfigCache configCache;
|
||||
private final Path folder;
|
||||
private final Logger logger;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
private final Injector injector;
|
||||
|
||||
@Inject
|
||||
public CommandWhitelistVelocity(ProxyServer server, Logger logger, @DataDirectory final Path folder, Metrics.Factory metricsFactory) {
|
||||
CommandWhitelistVelocity.server = server;
|
||||
CommandWhitelistVelocity.folder = folder;
|
||||
CommandWhitelistVelocity.plugin = this;
|
||||
CommandWhitelistVelocity.logger = logger;
|
||||
public CommandWhitelistVelocity(
|
||||
ProxyServer server,
|
||||
Logger logger,
|
||||
@DataDirectory final Path folder,
|
||||
Metrics.Factory metricsFactory,
|
||||
Injector injector
|
||||
) {
|
||||
this.server = server;
|
||||
this.folder = folder;
|
||||
this.logger = logger;
|
||||
this.metricsFactory = metricsFactory;
|
||||
|
||||
this.injector = injector;
|
||||
}
|
||||
|
||||
private static void reloadConfig() {
|
||||
private void reloadConfig() {
|
||||
if (configCache == null)
|
||||
configCache = new ConfigCache(new File(String.valueOf(folder), "config.yml"), false, logger);
|
||||
configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, logger);
|
||||
else
|
||||
configCache.reloadConfig();
|
||||
}
|
||||
|
||||
public static void reloadConfig(CommandSource source) {
|
||||
server.getScheduler().buildTask(plugin, () -> {
|
||||
public int reloadConfig(CommandSource source) {
|
||||
server.getScheduler().buildTask(this, () -> {
|
||||
reloadConfig();
|
||||
source.sendMessage(Identity.nil(), CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||
source.sendMessage(CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||
}).schedule();
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
reloadConfig();
|
||||
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
||||
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
||||
injector.getInstance(VelocityMainCommand.class).register();
|
||||
Metrics metrics = metricsFactory.make(this, 8704);
|
||||
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@Subscribe(order = PostOrder.LAST)
|
||||
@SuppressWarnings("UnstableApiUsage")
|
||||
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
HashSet<String> allowedCommands = getCommands(player);
|
||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||
server.getCommandManager().hasCommand(commandNode.getName())
|
||||
&& !allowedCommands.contains(commandNode.getName())
|
||||
@@ -81,32 +86,64 @@ public class CommandWhitelistVelocity {
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.CommandExecuteEvent event) {
|
||||
public void onUserCommandExecuteEvent(CommandExecuteEvent event) {
|
||||
if (!(event.getCommandSource() instanceof Player)) return;
|
||||
Player player = (Player) event.getCommandSource();
|
||||
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
String command = event.getCommand().split(" ")[0];
|
||||
if (server.getCommandManager().hasCommand(command)
|
||||
&& !allowedCommands.contains(command))
|
||||
// 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)) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ConfigCache getConfigCache() {
|
||||
/**
|
||||
* 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() {
|
||||
return configCache;
|
||||
}
|
||||
|
||||
public static Path getConfigPath() {
|
||||
return folder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player Velocity Player
|
||||
* @return commands available to the player
|
||||
*/
|
||||
public static HashSet<String> getCommands(Player player) {
|
||||
public HashSet<String> getCommands(Player player) {
|
||||
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||
HashSet<String> commandList = new HashSet<>();
|
||||
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||
@@ -123,18 +160,19 @@ public class CommandWhitelistVelocity {
|
||||
* @param player Velocity Player
|
||||
* @return subcommands unavailable for the player
|
||||
*/
|
||||
public static 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;
|
||||
}
|
||||
|
||||
public static ArrayList<String> getServerCommands() {
|
||||
public ArrayList<String> getServerCommands() {
|
||||
return new ArrayList<>(server.getCommandManager().getAliases());
|
||||
}
|
||||
|
||||
|
||||
+126
-87
@@ -1,104 +1,143 @@
|
||||
package eu.endermite.commandwhitelist.velocity.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
||||
import com.velocitypowered.api.command.BrigadierCommand;
|
||||
import com.velocitypowered.api.command.CommandManager;
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import com.velocitypowered.api.permission.Tristate;
|
||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
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.CommandWhitelistVelocity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class VelocityMainCommand implements SimpleCommand {
|
||||
public final class VelocityMainCommand {
|
||||
@Inject
|
||||
private CommandManager commandManager;
|
||||
@Inject
|
||||
private CommandWhitelistVelocity plugin;
|
||||
@Inject
|
||||
@DataDirectory
|
||||
private Path dataDirectory;
|
||||
|
||||
@Override
|
||||
public void execute(final Invocation invocation) {
|
||||
CommandSource sender = invocation.source();
|
||||
String[] args = invocation.arguments();
|
||||
String label = invocation.alias();
|
||||
public void register() {
|
||||
LiteralCommandNode<CommandSource> node = LiteralArgumentBuilder
|
||||
.<CommandSource>literal("vcw")
|
||||
.requires(src -> src.getPermissionValue("commandwhitelist.command") != Tristate.FALSE)
|
||||
.executes(ctx -> {
|
||||
CommandSource source = ctx.getSource();
|
||||
source.sendMessage(CWCommand.helpComponent("vcw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission())));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("reload")
|
||||
.requires(src -> src.hasPermission(CWPermission.RELOAD.permission()))
|
||||
.executes(ctx -> plugin.reloadConfig(ctx.getSource()))
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("add")
|
||||
.requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
|
||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("group", StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> {
|
||||
plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest);
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("command", StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> {
|
||||
CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class));
|
||||
if (group == null) return builder.buildFuture();
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
return;
|
||||
}
|
||||
for (String cmd : plugin.getServerCommands()) {
|
||||
if (cmd.charAt(0) == '/')
|
||||
cmd = cmd.substring(1);
|
||||
if (cmd.indexOf(':') != -1) {
|
||||
String[] cmdSplit = cmd.split(":");
|
||||
if (cmdSplit.length < 2) continue;
|
||||
cmd = cmdSplit[1];
|
||||
}
|
||||
if (group.getCommands().contains(cmd)) continue;
|
||||
builder.suggest(cmd);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.executes(ctx -> {
|
||||
CommandSource source = ctx.getSource();
|
||||
ConfigCache configCache = plugin.getConfigCache();
|
||||
String arg1 = ctx.getArgument("group", String.class);
|
||||
String arg2 = ctx.getArgument("command", String.class);
|
||||
|
||||
try {
|
||||
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||
switch (commandType) {
|
||||
case RELOAD:
|
||||
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
CommandWhitelistVelocity.reloadConfig(sender);
|
||||
return;
|
||||
case ADD:
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||
else
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||
return;
|
||||
case REMOVE:
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||
else
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||
return;
|
||||
case DUMP:
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
sender.sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistVelocity.getServerCommands(), new File(String.valueOf(CommandWhitelistVelocity.getConfigPath()), "command_dump.yml"))) {
|
||||
sender.sendMessage(Component.text("Commands dumped to command_dump.yml"));
|
||||
} else {
|
||||
sender.sendMessage(Component.text("Failed to save the file."));
|
||||
}
|
||||
return;
|
||||
case HELP:
|
||||
default:
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
if (CWCommand.addToWhitelist(configCache, arg2, arg1))
|
||||
source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.added_to_whitelist, arg2, arg1)));
|
||||
else
|
||||
source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1)));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("remove")
|
||||
.requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
|
||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("group", StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> {
|
||||
plugin.getConfigCache().getGroupList().keySet().forEach(builder::suggest);
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.then(RequiredArgumentBuilder.<CommandSource, String>argument("command", StringArgumentType.word())
|
||||
.suggests((ctx, builder) -> {
|
||||
CWGroup group = plugin.getConfigCache().getGroupList().get(ctx.getArgument("group", String.class));
|
||||
if (group == null) return builder.buildFuture();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (String s : group.getCommands()) {
|
||||
builder.suggest(s);
|
||||
}
|
||||
return builder.buildFuture();
|
||||
})
|
||||
.executes(ctx -> {
|
||||
CommandSource source = ctx.getSource();
|
||||
ConfigCache configCache = plugin.getConfigCache();
|
||||
String arg1 = ctx.getArgument("group", String.class);
|
||||
String arg2 = ctx.getArgument("command", String.class);
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
||||
CommandSource source = invocation.source();
|
||||
String[] args = invocation.arguments();
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
List<String> serverCommands = CommandWhitelistVelocity.getServerCommands();
|
||||
return CWCommand.commandSuggestions(
|
||||
CommandWhitelistVelocity.getConfigCache(),
|
||||
serverCommands,
|
||||
args,
|
||||
source.hasPermission(CWPermission.RELOAD.permission()),
|
||||
source.hasPermission(CWPermission.ADMIN.permission()),
|
||||
CWCommand.ImplementationType.VELOCITY
|
||||
);
|
||||
});
|
||||
if (CWCommand.removeFromWhitelist(configCache, arg2, arg1))
|
||||
source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.removed_from_whitelist, arg2, arg1)));
|
||||
else
|
||||
source.sendMessage(CWCommand.miniMessage.deserialize(String.format(configCache.prefix + configCache.group_doesnt_exist, arg1)));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
)
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("dump")
|
||||
.requires(src -> src.hasPermission(CWPermission.ADMIN.permission()))
|
||||
.executes(ctx -> {
|
||||
CommandSource source = ctx.getSource();
|
||||
source.sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||
if (CommandUtil.dumpAllBukkitCommands(plugin.getServerCommands(), dataDirectory.resolve("command_dump.yml").toFile())) {
|
||||
source.sendMessage(Component.text("Commands dumped to command_dump.yml"));
|
||||
} else {
|
||||
source.sendMessage(Component.text("Failed to save the file."));
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
.then(LiteralArgumentBuilder.<CommandSource>literal("help")
|
||||
.executes(ctx -> {
|
||||
CommandSource source = ctx.getSource();
|
||||
source.sendMessage(CWCommand.helpComponent("cw", source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission())));
|
||||
return Command.SINGLE_SUCCESS;
|
||||
})
|
||||
)
|
||||
.build();
|
||||
|
||||
final BrigadierCommand command = new BrigadierCommand(node);
|
||||
commandManager.register(commandManager.metaBuilder(command).plugin(plugin).build(), command);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.12.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>Waterfall</artifactId>
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<url>youhavetrouble.me</url>
|
||||
@@ -25,7 +25,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -34,7 +34,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -74,7 +74,7 @@
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||
<url>https://repo.papermc.io/repository/maven-public</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
@@ -88,25 +88,25 @@
|
||||
<dependency>
|
||||
<groupId>io.github.waterfallmc</groupId>
|
||||
<artifactId>waterfall-api</artifactId>
|
||||
<version>1.17-R0.1-SNAPSHOT</version>
|
||||
<version>1.21-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||
<version>4.1.0</version>
|
||||
<version>4.4.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<version>4.23.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.bstats</groupId>
|
||||
<artifactId>bstats-bungeecord</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<version>3.0.2</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
+15
-2
@@ -6,7 +6,9 @@ import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.event.ChatEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
@@ -15,7 +17,7 @@ import java.util.HashSet;
|
||||
public class BungeeChatEventListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
||||
public void onChatEvent(ChatEvent event) {
|
||||
if (event.isCancelled()) return;
|
||||
if (!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||
if (!event.isProxyCommand()) return;
|
||||
@@ -32,7 +34,18 @@ public class BungeeChatEventListener implements Listener {
|
||||
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player);
|
||||
if (!commands.contains(label)) {
|
||||
event.setCancelled(true);
|
||||
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)));
|
||||
Component message = CWCommand.getParsedErrorMessage(
|
||||
command,
|
||||
configCache.prefix + CommandWhitelistWaterfall.getCommandDeniedMessage(label)
|
||||
);
|
||||
switch (configCache.messageType) {
|
||||
case CHAT:
|
||||
audiences.player(player).sendMessage(message);
|
||||
break;
|
||||
case ACTIONBAR:
|
||||
audiences.player(player).sendActionBar(message);
|
||||
break;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.5.0</version>
|
||||
<version>2.12.0</version>
|
||||
<modules>
|
||||
<module>CommandWhitelistCommon</module>
|
||||
<module>CommandWhitelistBukkit</module>
|
||||
@@ -19,7 +19,7 @@
|
||||
|
||||
<description>Control what commands players can use</description>
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<java.version>21</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<version>3.13.0</version>
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
@@ -37,7 +37,7 @@
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.2.4</version>
|
||||
<version>3.6.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
@@ -46,7 +46,20 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||
<finalName>${project.name}-${project.version}</finalName>
|
||||
<transformers>
|
||||
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
|
||||
<manifestEntries>
|
||||
<paperweight-mappings-namespace>mojang</paperweight-mappings-namespace>
|
||||
</manifestEntries>
|
||||
</transformer>
|
||||
</transformers>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>net.kyori</pattern>
|
||||
<shadedPattern>eu.endermite.net.kyori</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -65,13 +78,17 @@
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>papermc</id>
|
||||
<url>https://repo.papermc.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.11.0</version>
|
||||
<version>4.23.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
Reference in New Issue
Block a user