mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 350f50588e | |||
| 9a5820bbd6 | |||
| 3c31081b42 | |||
| 75b91a70d3 | |||
| 6b31e7c76c | |||
| 1ea3f3f550 | |||
| 00f7d292fa | |||
| 653cd0e242 | |||
| 6b1763a260 |
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Bukkit</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Bukkit</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori</pattern>
|
||||||
|
<shadedPattern>eu.endermite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>dmulloy2-repo</id>
|
||||||
|
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.19-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.1.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.11.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>5.0.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bukkit</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.mojang</groupId>
|
||||||
|
<artifactId>brigadier</artifactId>
|
||||||
|
<version>1.0.17</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+166
@@ -0,0 +1,166 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.command.BukkitCommandExecutor;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import org.bstats.bukkit.Metrics;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.PluginCommand;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.help.HelpTopic;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
public class CommandWhitelistBukkit extends JavaPlugin {
|
||||||
|
|
||||||
|
private static CommandWhitelistBukkit commandWhitelist;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
private static BukkitAudiences audiences;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
|
||||||
|
commandWhitelist = this;
|
||||||
|
audiences = BukkitAudiences.create(this);
|
||||||
|
|
||||||
|
reloadPluginConfig();
|
||||||
|
|
||||||
|
Plugin protocollib = getServer().getPluginManager().getPlugin("ProtocolLib");
|
||||||
|
|
||||||
|
if (!getConfigCache().useProtocolLib || protocollib == null || !protocollib.isEnabled()) {
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandPreProcessListener(), this);
|
||||||
|
} else {
|
||||||
|
PacketCommandPreProcessListener.protocol(this);
|
||||||
|
getLogger().warning("Using ProtocolLib for command filter!");
|
||||||
|
getLogger().warning("Please make sure you actually need this. This is not a \"better way to do it\".");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// Use paper's async tab completions if possible
|
||||||
|
Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent");
|
||||||
|
getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this);
|
||||||
|
} catch (ClassNotFoundException ignored) {
|
||||||
|
}
|
||||||
|
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||||
|
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||||
|
|
||||||
|
PluginCommand command = getCommand("commandwhitelist");
|
||||||
|
if (command != null) {
|
||||||
|
BukkitCommandExecutor executor = new BukkitCommandExecutor();
|
||||||
|
command.setExecutor(executor);
|
||||||
|
command.setTabCompleter(executor);
|
||||||
|
}
|
||||||
|
|
||||||
|
new Metrics(this, 8705);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadPluginConfig() {
|
||||||
|
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
||||||
|
if (configCache == null) {
|
||||||
|
try {
|
||||||
|
configCache = new ConfigCache(configFile, true, getSLF4JLogger());
|
||||||
|
} catch (NoSuchMethodError e) {
|
||||||
|
configCache = new ConfigCache(configFile, true, null);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadPluginConfig(CommandSender sender) {
|
||||||
|
CompletableFuture.runAsync(() -> {
|
||||||
|
reloadPluginConfig();
|
||||||
|
try {
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
p.updateCommands();
|
||||||
|
}
|
||||||
|
} catch (Exception ignored) {}
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.config_reloaded));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelistBukkit getPlugin() {
|
||||||
|
return commandWhitelist;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BukkitAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bukkit Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(org.bukkit.entity.Player player) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission(s.getValue().getPermission()))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bukkit Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getSuggestions(org.bukkit.entity.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;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> getServerCommands() {
|
||||||
|
try {
|
||||||
|
return new ArrayList<>(Bukkit.getCommandMap().getKnownCommands().keySet());
|
||||||
|
} catch (NoSuchMethodError error) {
|
||||||
|
HashSet<String> commands = new HashSet<>();
|
||||||
|
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
|
||||||
|
String cmd = topic.getName();
|
||||||
|
if (Character.isUpperCase(cmd.charAt(0))) continue;
|
||||||
|
commands.add(topic.getName());
|
||||||
|
}
|
||||||
|
return new ArrayList<>(commands);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+96
@@ -0,0 +1,96 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.command.TabExecutor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class BukkitCommandExecutor implements TabExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
|
||||||
|
return true;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case DUMP:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||||
|
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistBukkit.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) {
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
|
||||||
|
} else {
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||||
|
return CWCommand.commandSuggestions(
|
||||||
|
CommandWhitelistBukkit.getConfigCache(),
|
||||||
|
CommandWhitelistBukkit.getServerCommands(),
|
||||||
|
args,
|
||||||
|
sender.hasPermission(CWPermission.RELOAD.permission()),
|
||||||
|
sender.hasPermission(CWPermission.ADMIN.permission()),
|
||||||
|
CWCommand.ImplementationType.BUKKIT
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+31
@@ -0,0 +1,31 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class AsyncTabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST)
|
||||||
|
public void onCommandTabComplete(AsyncTabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
String buffer = event.getBuffer();
|
||||||
|
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)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
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 org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
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(CWPermission.BYPASS.permission())) return;
|
||||||
|
String caseSensitiveLabel = CommandUtil.getCommandLabel(event.getMessage());
|
||||||
|
String label = caseSensitiveLabel.toLowerCase();
|
||||||
|
|
||||||
|
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)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||||
|
String messageWithoutSlash = event.getMessage().startsWith("/") ? event.getMessage().substring(1) : event.getMessage();
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (messageWithoutSlash.startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+20
@@ -0,0 +1,20 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PlayerCommandSendListener implements Listener {
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||||
|
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||||
|
}
|
||||||
|
}
|
||||||
+36
@@ -0,0 +1,36 @@
|
|||||||
|
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 org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
import org.bukkit.event.server.TabCompleteEvent;
|
||||||
|
|
||||||
|
public class TabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onCommandTabComplete(TabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
String buffer = event.getBuffer();
|
||||||
|
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)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners.protocollib;
|
||||||
|
|
||||||
|
import com.comphenix.protocol.PacketType;
|
||||||
|
import com.comphenix.protocol.ProtocolLibrary;
|
||||||
|
import com.comphenix.protocol.ProtocolManager;
|
||||||
|
import com.comphenix.protocol.events.ListenerPriority;
|
||||||
|
import com.comphenix.protocol.events.PacketAdapter;
|
||||||
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
import com.comphenix.protocol.events.PacketEvent;
|
||||||
|
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 org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.plugin.Plugin;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class PacketCommandPreProcessListener {
|
||||||
|
|
||||||
|
public static void protocol(CommandWhitelistBukkit plugin) {
|
||||||
|
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||||
|
commandExecListener(protocolManager, plugin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void commandExecListener(ProtocolManager protocolManager, Plugin plugin) {
|
||||||
|
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Client.CHAT) {
|
||||||
|
@Override
|
||||||
|
public void onPacketReceiving(PacketEvent event) {
|
||||||
|
PacketContainer packet = event.getPacket();
|
||||||
|
String string = packet.getStrings().read(0);
|
||||||
|
if (!string.startsWith("/")) return;
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
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)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + CommandWhitelistBukkit.getCommandDeniedMessage(label)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+6
-6
@@ -1,14 +1,14 @@
|
|||||||
name: "${project.name}"
|
name: CommandWhitelist
|
||||||
|
prefix: CommandWhitelist
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
api-version: 1.13
|
api-version: 1.13
|
||||||
main: "${project.groupId}.bukkit.CommandWhitelistBukkit"
|
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
|
||||||
authors:
|
authors: [YouHaveTrouble]
|
||||||
- "YouHaveTrouble"
|
website: youhavetrouble.me
|
||||||
website: "${project.url}"
|
|
||||||
folia-supported: true
|
folia-supported: true
|
||||||
softdepend:
|
softdepend:
|
||||||
- ProtocolLib
|
- ProtocolLib
|
||||||
description: "${project.description}"
|
description: Control what commands players can use
|
||||||
commands:
|
commands:
|
||||||
commandwhitelist:
|
commandwhitelist:
|
||||||
aliases:
|
aliases:
|
||||||
@@ -0,0 +1,108 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Common</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>pluginwiki-repo</id>
|
||||||
|
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>velocitypowered-repo</id>
|
||||||
|
<url>https://repo.velocitypowered.com/releases/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.thatsmusic99</groupId>
|
||||||
|
<artifactId>ConfigurationMaster-API</artifactId>
|
||||||
|
<version>v2.0.0-BETA-7</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.velocitypowered</groupId>
|
||||||
|
<artifactId>velocity-api</artifactId>
|
||||||
|
<version>3.1.2-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.13.1</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.papermc.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.19-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>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
+65
@@ -0,0 +1,65 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class CWGroup {
|
||||||
|
|
||||||
|
private final String id, permission, commandDeniedMessage;
|
||||||
|
private final HashSet<String> commands = new HashSet<>();
|
||||||
|
private final HashSet<String> subCommands = new HashSet<>();
|
||||||
|
|
||||||
|
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands, String custom_command_denied_message) {
|
||||||
|
this.id = id;
|
||||||
|
this.permission = "commandwhitelist.group." + id;
|
||||||
|
this.commands.addAll(commands);
|
||||||
|
this.commandDeniedMessage = custom_command_denied_message;
|
||||||
|
this.subCommands.addAll(subCommands);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPermission() {
|
||||||
|
return permission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getCommands() {
|
||||||
|
return commands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public @Nullable String getCommandDeniedMessage() {
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addCommand(String command) {
|
||||||
|
commands.add(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeCommand(String command) {
|
||||||
|
commands.remove(command);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashSet<String> getSubCommands() {
|
||||||
|
return subCommands;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSubCommand(String subCommand) {
|
||||||
|
subCommands.add(subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSubCommand(String subCommand) {
|
||||||
|
subCommands.remove(subCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
public HashMap<String, Object> serialize() {
|
||||||
|
HashMap<String, Object> serializedGroup = new LinkedHashMap<>();
|
||||||
|
List<String> commands = new ArrayList<>(this.commands);
|
||||||
|
List<String> subCommands = new ArrayList<>(this.subCommands);
|
||||||
|
serializedGroup.put("commands", commands);
|
||||||
|
serializedGroup.put("subcommands", subCommands);
|
||||||
|
return serializedGroup;
|
||||||
|
}
|
||||||
|
}
|
||||||
+8
-3
@@ -1,4 +1,4 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
public enum CWPermission {
|
public enum CWPermission {
|
||||||
|
|
||||||
@@ -19,9 +19,14 @@ public enum CWPermission {
|
|||||||
/**
|
/**
|
||||||
* Allows to check specific group permission
|
* Allows to check specific group permission
|
||||||
*
|
*
|
||||||
|
* @param configCache
|
||||||
|
* @param groupId
|
||||||
|
* @return
|
||||||
*/
|
*/
|
||||||
public static String getGroupPermission(String groupId) {
|
public static String getGroupPermission(ConfigCache configCache, String groupId) {
|
||||||
return "commandwhitelist.group." + groupId;
|
if (configCache.getGroupList().containsKey(groupId))
|
||||||
|
return configCache.getGroupList().get(groupId).getPermission();
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+29
-8
@@ -1,4 +1,4 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
||||||
|
|
||||||
@@ -10,13 +10,28 @@ import java.util.List;
|
|||||||
|
|
||||||
public class CommandUtil {
|
public class CommandUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
public static List<String> filterCommandList(Collection<String> allCommands, Collection<String> allowedCommands) {
|
* Filters blocked command suggestions from provided collection of strings
|
||||||
List<String> filteredCommands = new ArrayList<>();
|
*
|
||||||
|
* @param buffer Command buffer
|
||||||
|
* @param suggestions Full suggestions list
|
||||||
|
* @param blockedSubCommands Subcommands to filter out
|
||||||
return filteredCommands;
|
* @return Filtered list of suggestions
|
||||||
|
*/
|
||||||
|
public static List<String> filterSuggestions(String buffer, Collection<String> suggestions, Collection<String> blockedSubCommands) {
|
||||||
|
if (buffer.startsWith("/"))
|
||||||
|
buffer = buffer.substring(1);
|
||||||
|
List<String> suggestionsList = new ArrayList<>(suggestions);
|
||||||
|
if (suggestions.isEmpty() || blockedSubCommands.isEmpty()) return suggestionsList;
|
||||||
|
for (String s : blockedSubCommands) {
|
||||||
|
String scommand = cutLastArgument(s);
|
||||||
|
if (buffer.startsWith(scommand)) {
|
||||||
|
String slast = getLastArgument(s);
|
||||||
|
while (suggestionsList.contains(slast))
|
||||||
|
suggestionsList.remove(slast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return suggestionsList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +80,12 @@ public class CommandUtil {
|
|||||||
parent.mkdir();
|
parent.mkdir();
|
||||||
if (!file.exists())
|
if (!file.exists())
|
||||||
file.createNewFile();
|
file.createNewFile();
|
||||||
|
} catch (IOException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
try {
|
||||||
ConfigFile dumpFile = ConfigFile.loadConfig(file);
|
ConfigFile dumpFile = ConfigFile.loadConfig(file);
|
||||||
dumpFile.set("commands", serverCommands);
|
dumpFile.set("commands", serverCommands);
|
||||||
dumpFile.save();
|
dumpFile.save();
|
||||||
+25
-7
@@ -1,4 +1,4 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
||||||
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
|
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
|
||||||
@@ -7,7 +7,7 @@ import java.io.File;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
public class CWConfig {
|
public class ConfigCache {
|
||||||
|
|
||||||
private final File configFile;
|
private final File configFile;
|
||||||
private ConfigFile config;
|
private ConfigFile config;
|
||||||
@@ -19,12 +19,16 @@ public class CWConfig {
|
|||||||
public boolean useProtocolLib = false;
|
public boolean useProtocolLib = false;
|
||||||
public boolean debug = false;
|
public boolean debug = false;
|
||||||
|
|
||||||
public CWConfig(File configFile, boolean canDoProtocolLib, Object logger) {
|
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) {
|
||||||
this.configFile = configFile;
|
this.configFile = configFile;
|
||||||
this.canDoProtocolLib = canDoProtocolLib;
|
this.canDoProtocolLib = canDoProtocolLib;
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
|
|
||||||
|
try {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reloadConfig() {
|
public boolean reloadConfig() {
|
||||||
@@ -33,11 +37,13 @@ public class CWConfig {
|
|||||||
try {
|
try {
|
||||||
config = ConfigFile.loadConfig(configFile);
|
config = ConfigFile.loadConfig(configFile);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(e);
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
config.addDefault("messages.prefix", "CommandWhitelist > ");
|
config.addDefault("messages.prefix", "CommandWhitelist > ");
|
||||||
config.addDefault("messages.command_denied", "No such command.");
|
config.addDefault("messages.command_denied", "No such command.");
|
||||||
|
config.addDefault("messages.subcommand_denied", "You cannot use this subcommand");
|
||||||
config.addDefault("messages.no_permission", "<red>You don't have permission to do this.");
|
config.addDefault("messages.no_permission", "<red>You don't have permission to do this.");
|
||||||
config.addDefault("messages.no_such_subcommand", "<red>No subcommand by that name.");
|
config.addDefault("messages.no_such_subcommand", "<red>No subcommand by that name.");
|
||||||
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
|
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
|
||||||
@@ -78,8 +84,12 @@ public class CWConfig {
|
|||||||
defaultCommands.add("tpaccept");
|
defaultCommands.add("tpaccept");
|
||||||
defaultCommands.add("tpdeny");
|
defaultCommands.add("tpdeny");
|
||||||
defaultCommands.add("warp");
|
defaultCommands.add("warp");
|
||||||
|
List<String> defaultSubcommands = new ArrayList<>();
|
||||||
|
defaultSubcommands.add("help about");
|
||||||
|
|
||||||
config.addDefault("groups.default", new CWGroup("default", defaultCommands).serialize());
|
String defaultCustomCommandDeniedMessage = "";
|
||||||
|
|
||||||
|
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix");
|
prefix = config.getString("messages.prefix");
|
||||||
command_denied = config.getString("messages.command_denied");
|
command_denied = config.getString("messages.command_denied");
|
||||||
@@ -133,8 +143,16 @@ public class CWConfig {
|
|||||||
if (commands.contains(cmd)) continue;
|
if (commands.contains(cmd)) continue;
|
||||||
commands.add(cmd);
|
commands.add(cmd);
|
||||||
}
|
}
|
||||||
|
List<String> subCommands = new ArrayList<>();
|
||||||
return new CWGroup(id, commands);
|
for (String subCmd : section.getStringList(id + ".subcommands")) {
|
||||||
|
if (!subCmd.contains(" ")) {
|
||||||
|
warn("CommandWhitelist - \"" + subCmd + "\" is not a subcommand. Skipping it.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
subCommands.add(subCmd);
|
||||||
|
}
|
||||||
|
String customCommandDeniedMessage = section.getString(id + ".custom_command_denied_message");
|
||||||
|
return new CWGroup(id, commands, subCommands, customCommandDeniedMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveCWGroup(String id, CWGroup group) {
|
public void saveCWGroup(String id, CWGroup group) {
|
||||||
+14
-11
@@ -1,7 +1,7 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common.commands;
|
package eu.endermite.commandwhitelist.common.commands;
|
||||||
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWGroup;
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWConfig;
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.format.NamedTextColor;
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
@@ -14,20 +14,20 @@ public class CWCommand {
|
|||||||
|
|
||||||
public static MiniMessage miniMessage = MiniMessage.miniMessage();
|
public static MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
public static boolean addToWhitelist(CWConfig CWConfig, String command, String group) {
|
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
CWGroup cwGroup = CWConfig.getGroupList().get(group);
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
if (cwGroup == null) return false;
|
if (cwGroup == null) return false;
|
||||||
cwGroup.addCommand(command);
|
cwGroup.addCommand(command);
|
||||||
CWConfig.saveCWGroup(group, cwGroup);
|
configCache.saveCWGroup(group, cwGroup);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean removeFromWhitelist(CWConfig CWConfig, String command, String group) {
|
public static boolean removeFromWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
CWGroup cwGroup = CWConfig.getGroupList().get(group);
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
if (cwGroup == null)
|
if (cwGroup == null)
|
||||||
return false;
|
return false;
|
||||||
cwGroup.removeCommand(command);
|
cwGroup.removeCommand(command);
|
||||||
CWConfig.saveCWGroup(group, cwGroup);
|
configCache.saveCWGroup(group, cwGroup);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -57,7 +57,7 @@ public class CWCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static List<String> commandSuggestions(
|
public static List<String> commandSuggestions(
|
||||||
CWConfig config,
|
ConfigCache config,
|
||||||
Collection<String> serverCommands,
|
Collection<String> serverCommands,
|
||||||
String[] args, boolean reloadPerm,
|
String[] args, boolean reloadPerm,
|
||||||
boolean adminPerm,
|
boolean adminPerm,
|
||||||
@@ -104,7 +104,10 @@ public class CWCommand {
|
|||||||
if (!adminPerm) return list;
|
if (!adminPerm) return list;
|
||||||
CWGroup group = config.getGroupList().get(args[1]);
|
CWGroup group = config.getGroupList().get(args[1]);
|
||||||
if (group == null) return list;
|
if (group == null) return list;
|
||||||
// TODO
|
for (String s : group.getCommands()) {
|
||||||
|
if (s.startsWith(args[2]))
|
||||||
|
list.add(s);
|
||||||
|
}
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Velocity</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Velocity</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<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>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>minecraft-libraries</id>
|
||||||
|
<url>https://libraries.minecraft.net/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>spongepowered-repo</id>
|
||||||
|
<url>https://repo.spongepowered.org/maven</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.velocitypowered</groupId>
|
||||||
|
<artifactId>velocity-api</artifactId>
|
||||||
|
<version>3.1.2-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-velocity</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+145
@@ -0,0 +1,145 @@
|
|||||||
|
package eu.endermite.commandwhitelist.velocity;
|
||||||
|
|
||||||
|
import com.google.inject.Injector;
|
||||||
|
import com.mojang.brigadier.Command;
|
||||||
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
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.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 org.bstats.charts.SimplePie;
|
||||||
|
import org.bstats.velocity.Metrics;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class CommandWhitelistVelocity {
|
||||||
|
|
||||||
|
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,
|
||||||
|
Injector injector
|
||||||
|
) {
|
||||||
|
this.server = server;
|
||||||
|
this.folder = folder;
|
||||||
|
this.logger = logger;
|
||||||
|
this.metricsFactory = metricsFactory;
|
||||||
|
this.injector = injector;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadConfig() {
|
||||||
|
if (configCache == null)
|
||||||
|
configCache = new ConfigCache(folder.resolve("config.yml").toFile(), false, logger);
|
||||||
|
else
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int reloadConfig(CommandSource source) {
|
||||||
|
server.getScheduler().buildTask(this, () -> {
|
||||||
|
reloadConfig();
|
||||||
|
source.sendMessage(CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||||
|
}).schedule();
|
||||||
|
return Command.SINGLE_SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||||
|
reloadConfig();
|
||||||
|
injector.getInstance(VelocityMainCommand.class).register();
|
||||||
|
Metrics metrics = metricsFactory.make(this, 8704);
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
@SuppressWarnings("UnstableApiUsage")
|
||||||
|
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||||
|
Player player = event.getPlayer();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
HashSet<String> allowedCommands = getCommands(player);
|
||||||
|
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||||
|
server.getCommandManager().hasCommand(commandNode.getName())
|
||||||
|
&& !allowedCommands.contains(commandNode.getName())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onUserCommandExecuteEvent(CommandExecuteEvent event) {
|
||||||
|
if (!(event.getCommandSource() instanceof Player)) return;
|
||||||
|
Player player = (Player) event.getCommandSource();
|
||||||
|
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
// Workaround for velocity executing "/ command" as valid command
|
||||||
|
String command = event.getCommand().trim();
|
||||||
|
|
||||||
|
HashSet<String> allowedCommands = getCommands(player);
|
||||||
|
String label = CommandUtil.getCommandLabel(command);
|
||||||
|
if (server.getCommandManager().hasCommand(label) && !allowedCommands.contains(label))
|
||||||
|
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||||
|
}
|
||||||
|
|
||||||
|
public ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Velocity Player
|
||||||
|
* @return commands available to the 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()) {
|
||||||
|
CWGroup group = s.getValue();
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(group.getCommands());
|
||||||
|
else if (player.hasPermission(group.getPermission()))
|
||||||
|
commandList.addAll(group.getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Velocity Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public HashSet<String> getSuggestions(Player player, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> suggestionList = new HashSet<>();
|
||||||
|
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;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList<String> getServerCommands() {
|
||||||
|
return new ArrayList<>(server.getCommandManager().getAliases());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+143
@@ -0,0 +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.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.nio.file.Path;
|
||||||
|
|
||||||
|
public final class VelocityMainCommand {
|
||||||
|
@Inject
|
||||||
|
private CommandManager commandManager;
|
||||||
|
@Inject
|
||||||
|
private CommandWhitelistVelocity plugin;
|
||||||
|
@Inject
|
||||||
|
@DataDirectory
|
||||||
|
private Path dataDirectory;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"id": "commandwhitelist",
|
||||||
|
"name": "CommandWhitelist",
|
||||||
|
"version": "${project.version}",
|
||||||
|
"description": "You decide what commands players can use or tab complete on your server!",
|
||||||
|
"authors": ["YouHaveTrouble"],
|
||||||
|
"dependencies": [],
|
||||||
|
"main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
||||||
|
}
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
# User-specific stuff
|
||||||
|
.idea/
|
||||||
|
|
||||||
|
*.iml
|
||||||
|
*.ipr
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
*~
|
||||||
|
|
||||||
|
# temporary files which can be created if a process still has a handle open of a deleted file
|
||||||
|
.fuse_hidden*
|
||||||
|
|
||||||
|
# KDE directory preferences
|
||||||
|
.directory
|
||||||
|
|
||||||
|
# Linux trash folder which might appear on any partition or disk
|
||||||
|
.Trash-*
|
||||||
|
|
||||||
|
# .nfs files are created when an open file is removed but is still being accessed
|
||||||
|
.nfs*
|
||||||
|
|
||||||
|
# General
|
||||||
|
.DS_Store
|
||||||
|
.AppleDouble
|
||||||
|
.LSOverride
|
||||||
|
|
||||||
|
# Icon must end with two \r
|
||||||
|
Icon
|
||||||
|
|
||||||
|
# Thumbnails
|
||||||
|
._*
|
||||||
|
|
||||||
|
# Files that might appear in the root of a volume
|
||||||
|
.DocumentRevisions-V100
|
||||||
|
.fseventsd
|
||||||
|
.Spotlight-V100
|
||||||
|
.TemporaryItems
|
||||||
|
.Trashes
|
||||||
|
.VolumeIcon.icns
|
||||||
|
.com.apple.timemachine.donotpresent
|
||||||
|
|
||||||
|
# Directories potentially created on remote AFP share
|
||||||
|
.AppleDB
|
||||||
|
.AppleDesktop
|
||||||
|
Network Trash Folder
|
||||||
|
Temporary Items
|
||||||
|
.apdisk
|
||||||
|
|
||||||
|
# Windows thumbnail cache files
|
||||||
|
Thumbs.db
|
||||||
|
Thumbs.db:encryptable
|
||||||
|
ehthumbs.db
|
||||||
|
ehthumbs_vista.db
|
||||||
|
|
||||||
|
# Dump file
|
||||||
|
*.stackdump
|
||||||
|
|
||||||
|
# Folder config file
|
||||||
|
[Dd]esktop.ini
|
||||||
|
|
||||||
|
# Recycle Bin used on file shares
|
||||||
|
$RECYCLE.BIN/
|
||||||
|
|
||||||
|
# Windows Installer files
|
||||||
|
*.cab
|
||||||
|
*.msi
|
||||||
|
*.msix
|
||||||
|
*.msm
|
||||||
|
*.msp
|
||||||
|
|
||||||
|
# Windows shortcuts
|
||||||
|
*.lnk
|
||||||
|
|
||||||
|
target/
|
||||||
|
|
||||||
|
pom.xml.tag
|
||||||
|
pom.xml.releaseBackup
|
||||||
|
pom.xml.versionsBackup
|
||||||
|
pom.xml.next
|
||||||
|
|
||||||
|
release.properties
|
||||||
|
dependency-reduced-pom.xml
|
||||||
|
buildNumber.properties
|
||||||
|
.mvn/timing.properties
|
||||||
|
.mvn/wrapper/maven-wrapper.jar
|
||||||
|
.flattened-pom.xml
|
||||||
|
|
||||||
|
# Common working directory
|
||||||
|
run/
|
||||||
@@ -0,0 +1,113 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<parent>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<version>2.8.2</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<artifactId>Waterfall</artifactId>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
<name>CommandWhitelist-Waterfall</name>
|
||||||
|
|
||||||
|
<description>You decide what commands players can use or tab complete on your server!</description>
|
||||||
|
<properties>
|
||||||
|
<java.version>1.8</java.version>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
|
<url>youhavetrouble.me</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>${java.version}</source>
|
||||||
|
<target>${java.version}</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-shade-plugin</artifactId>
|
||||||
|
<version>3.2.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>shade</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
|
<finalName>${project.name}-${project.parent.version}</finalName>
|
||||||
|
<relocations>
|
||||||
|
<relocation>
|
||||||
|
<pattern>org.bstats</pattern>
|
||||||
|
<shadedPattern>eu.endermite.bstats</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>net.kyori</pattern>
|
||||||
|
<shadedPattern>eu.endermite</shadedPattern>
|
||||||
|
</relocation>
|
||||||
|
</relocations>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>sonatype</id>
|
||||||
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>${project.parent.version}</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
|
<artifactId>waterfall-api</artifactId>
|
||||||
|
<version>1.17-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||||
|
<version>4.1.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
|
<version>4.10.1</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.bstats</groupId>
|
||||||
|
<artifactId>bstats-bungeecord</artifactId>
|
||||||
|
<version>3.0.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+132
@@ -0,0 +1,132 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.command.BungeeMainCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
|
import org.bstats.bungeecord.Metrics;
|
||||||
|
import org.bstats.charts.SimplePie;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public final class CommandWhitelistWaterfall extends Plugin {
|
||||||
|
|
||||||
|
private static CommandWhitelistWaterfall plugin;
|
||||||
|
private static ConfigCache configCache;
|
||||||
|
private static BungeeAudiences audiences;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onEnable() {
|
||||||
|
plugin = this;
|
||||||
|
getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName());
|
||||||
|
loadConfig();
|
||||||
|
audiences = BungeeAudiences.create(this);
|
||||||
|
Metrics metrics = new Metrics(this, 8704);
|
||||||
|
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
|
||||||
|
try {
|
||||||
|
Class.forName("io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent");
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Waterfall"));
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
metrics.addCustomChart(new SimplePie("proxy", () -> "Bungee"));
|
||||||
|
getLogger().severe("Bungee command completion blocker requires Waterfall other Waterfall fork.");
|
||||||
|
}
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new BungeeTabcompleteListener());
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelistWaterfall getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BungeeAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
if (configCache == null)
|
||||||
|
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false, getLogger());
|
||||||
|
else
|
||||||
|
configCache.reloadConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfigAsync(CommandSender sender) {
|
||||||
|
getProxy().getScheduler().runAsync(this, () -> {
|
||||||
|
loadConfig();
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bungee Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(ProxiedPlayer player) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission(s.getValue().getPermission()))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
}
|
||||||
|
return commandList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bungee Player
|
||||||
|
* @return subcommands unavailable for the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getSuggestions(ProxiedPlayer player) {
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
HashSet<String> suggestionList = new HashSet<>();
|
||||||
|
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;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Command denied message. Will use custom if command exists in any group.
|
||||||
|
*/
|
||||||
|
public static String getCommandDeniedMessage(String command) {
|
||||||
|
String commandDeniedMessage = configCache.command_denied;
|
||||||
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
|
for (CWGroup group : groups.values()) {
|
||||||
|
if (group.getCommands().contains(command)) {
|
||||||
|
if (group.getCommandDeniedMessage() == null || group.getCommandDeniedMessage().isEmpty()) continue;
|
||||||
|
commandDeniedMessage = group.getCommandDeniedMessage();
|
||||||
|
break; // get first message we find
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return commandDeniedMessage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ArrayList<String> getServerCommands() {
|
||||||
|
ArrayList<String> serverCommands = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
||||||
|
serverCommands.add(command.getValue().getName());
|
||||||
|
}
|
||||||
|
return serverCommands;
|
||||||
|
}
|
||||||
|
}
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.command;
|
||||||
|
|
||||||
|
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.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BungeeMainCommand extends Command implements TabExecutor {
|
||||||
|
|
||||||
|
public BungeeMainCommand(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
|
||||||
|
String label = getName();
|
||||||
|
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
|
||||||
|
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||||
|
|
||||||
|
if (args.length == 0) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender);
|
||||||
|
return;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(configCache, args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.added_to_whitelist));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
|
return;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(configCache, args[2], args[1]))
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.removed_from_whitelist));
|
||||||
|
else
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
|
return;
|
||||||
|
case DUMP:
|
||||||
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Dumping all available commands to a file..."));
|
||||||
|
if (CommandUtil.dumpAllBukkitCommands(CommandWhitelistWaterfall.getServerCommands(), new File("plugins/CommandWhitelist/command_dump.yml"))) {
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Commands dumped to command_dump.yml"));
|
||||||
|
} else {
|
||||||
|
audiences.sender(sender).sendMessage(Component.text("Failed to save the file."));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
return CWCommand.commandSuggestions(
|
||||||
|
CommandWhitelistWaterfall.getConfigCache(),
|
||||||
|
CommandWhitelistWaterfall.getServerCommands(),
|
||||||
|
args,
|
||||||
|
sender.hasPermission(CWPermission.RELOAD.permission()),
|
||||||
|
sender.hasPermission(CWPermission.ADMIN.permission()),
|
||||||
|
CWCommand.ImplementationType.WATERFALL
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
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.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class BungeeChatEventListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onChatEvent(net.md_5.bungee.api.event.ChatEvent event) {
|
||||||
|
if (event.isCancelled()) return;
|
||||||
|
if (!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||||
|
if (!event.isProxyCommand()) return;
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
|
||||||
|
String command = event.getMessage().toLowerCase();
|
||||||
|
if (command.startsWith("/"))
|
||||||
|
command = command.substring(1);
|
||||||
|
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
|
||||||
|
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||||
|
|
||||||
|
String label = CommandUtil.getCommandLabel(command);
|
||||||
|
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)));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player);
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (command.startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(configCache.prefix + configCache.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
public class BungeeTabcompleteListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
|
||||||
|
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
if (event.getSuggestions().isEmpty()) return;
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
CommandUtil.filterSuggestions(
|
||||||
|
event.getCursor(),
|
||||||
|
event.getSuggestions(),
|
||||||
|
CommandWhitelistWaterfall.getSuggestions(player)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class WaterfallDefineCommandsListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
|
||||||
|
if (event.getReceiver() instanceof ProxiedPlayer) {
|
||||||
|
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||||
|
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||||
|
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||||
|
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->
|
||||||
|
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
||||||
|
.stream()
|
||||||
|
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
||||||
|
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
||||||
|
event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
name: CommandWhitelist
|
||||||
|
author: YouHaveTrouble
|
||||||
|
version: ${project.version}
|
||||||
|
main: eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall
|
||||||
|
description: You decide what commands players can use or tab complete on your server!
|
||||||
@@ -6,15 +6,21 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>3.0.0</version>
|
<version>2.8.2</version>
|
||||||
|
<modules>
|
||||||
|
<module>CommandWhitelistCommon</module>
|
||||||
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
<module>CommandWhitelistVelocity</module>
|
||||||
|
<module>CommandWhitelistWaterfall</module>
|
||||||
|
</modules>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
<description>Control what commands players can use</description>
|
|
||||||
|
|
||||||
|
<description>Control what commands players can use</description>
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<java.version>1.8</java.version>
|
||||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
<website>https://youhavetrouble.me</website>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
@@ -41,16 +47,6 @@
|
|||||||
<configuration>
|
<configuration>
|
||||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||||
<finalName>${project.name}-${project.version}</finalName>
|
<finalName>${project.name}-${project.version}</finalName>
|
||||||
<relocations>
|
|
||||||
<relocation>
|
|
||||||
<pattern>net.kyori</pattern>
|
|
||||||
<shadedPattern>me.youhavetrouble</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
<relocation>
|
|
||||||
<pattern>com.github.thatsmusic99</pattern>
|
|
||||||
<shadedPattern>me.youhavetrouble</shadedPattern>
|
|
||||||
</relocation>
|
|
||||||
</relocations>
|
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
@@ -65,76 +61,18 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>pluginwiki-repo</id>
|
|
||||||
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
|
||||||
<id>velocitypowered-repo</id>
|
|
||||||
<url>https://repo.velocitypowered.com/releases/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>papermc</id>
|
|
||||||
<url>https://papermc.io/repo/repository/maven-public/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
|
||||||
<id>dmulloy2-repo</id>
|
|
||||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
|
||||||
</repository>
|
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
|
||||||
<groupId>com.github.thatsmusic99</groupId>
|
|
||||||
<artifactId>ConfigurationMaster-API</artifactId>
|
|
||||||
<version>v2.0.0-BETA-6</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.kyori</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>adventure-api</artifactId>
|
<artifactId>adventure-api</artifactId>
|
||||||
<version>4.13.1</version>
|
<version>4.11.0</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.kyori</groupId>
|
|
||||||
<artifactId>adventure-platform-bukkit</artifactId>
|
|
||||||
<version>4.2.0</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>net.kyori</groupId>
|
|
||||||
<artifactId>adventure-text-minimessage</artifactId>
|
|
||||||
<version>4.13.1</version>
|
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>3.1.2-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.papermc.paper</groupId>
|
|
||||||
<artifactId>paper-api</artifactId>
|
|
||||||
<version>1.19-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.waterfallmc</groupId>
|
|
||||||
<artifactId>waterfall-api</artifactId>
|
|
||||||
<version>1.19-R0.1-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
|
||||||
<artifactId>ProtocolLib</artifactId>
|
|
||||||
<version>5.0.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
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.
|
||||||
|
|
||||||
<h1>WARNING: This is an experimental branch, literally everything here is subject to change</h1>
|
|
||||||
|
|
||||||
[](https://www.codefactor.io/repository/github/youhavetrouble/commandwhitelist)
|
[](https://www.codefactor.io/repository/github/youhavetrouble/commandwhitelist)
|
||||||
[](https://github.com/YouHaveTrouble/CommandWhitelist/releases)
|
[](https://github.com/YouHaveTrouble/CommandWhitelist/releases)
|
||||||
[](https://discord.gg/j8KK5dGBps)
|
[](https://discord.gg/j8KK5dGBps)
|
||||||
@@ -17,6 +15,7 @@ precisely what commands players can see and use.
|
|||||||
<li>Overwrite default "no such command" message with your branding
|
<li>Overwrite default "no such command" message with your branding
|
||||||
<li>Block tab completion</li>
|
<li>Block tab completion</li>
|
||||||
<li>Block command execution</li>
|
<li>Block command execution</li>
|
||||||
|
<li>Block completion and execution of specified subcommands</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<b>Compatible versions</b>: 1.13+
|
<b>Compatible versions</b>: 1.13+
|
||||||
|
|||||||
@@ -1,60 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.bukkit;
|
|
||||||
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.listeners.CommandExecuteListener;
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.listeners.CommandSendListener;
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.listeners.CommandTabCompleteListener;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWConfig;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.commands.CWCommand;
|
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.concurrent.CompletableFuture;
|
|
||||||
|
|
||||||
public class CommandWhitelistBukkit extends JavaPlugin {
|
|
||||||
|
|
||||||
private CWConfig CWConfig;
|
|
||||||
private BukkitAudiences audiences;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
reloadPluginConfig();
|
|
||||||
audiences = BukkitAudiences.create(this);
|
|
||||||
getServer().getPluginManager().registerEvents(new CommandSendListener(this), this);
|
|
||||||
getServer().getPluginManager().registerEvents(new CommandExecuteListener(this), this);
|
|
||||||
getServer().getPluginManager().registerEvents(new CommandTabCompleteListener(this), this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void reloadPluginConfig() {
|
|
||||||
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
|
||||||
if (CWConfig != null) {
|
|
||||||
CWConfig.reloadConfig();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
CWConfig = new CWConfig(configFile, true, getSLF4JLogger());
|
|
||||||
} catch (NoSuchMethodError e) {
|
|
||||||
CWConfig = new CWConfig(configFile, true, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public CompletableFuture<Void> reloadPluginConfig(CommandSender sender) {
|
|
||||||
return CompletableFuture.runAsync(() -> {
|
|
||||||
reloadPluginConfig();
|
|
||||||
try {
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
p.updateCommands();
|
|
||||||
}
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
audiences.sender(sender).sendMessage(CWCommand.miniMessage.deserialize(CWConfig.prefix + CWConfig.config_reloaded));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public CWConfig getCWConfig() {
|
|
||||||
return CWConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.bukkit.listeners;
|
|
||||||
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWCommandEntry;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPermission;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPlayer;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class CommandExecuteListener implements Listener {
|
|
||||||
|
|
||||||
private final CommandWhitelistBukkit plugin;
|
|
||||||
|
|
||||||
public CommandExecuteListener(CommandWhitelistBukkit plugin ) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
|
||||||
public void onCommandPreProcess(PlayerCommandPreprocessEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
|
||||||
CWPlayer cwPlayer = new CWPlayer(player);
|
|
||||||
for (CWCommandEntry entry : cwPlayer.getCommands(plugin.getCWConfig())) {
|
|
||||||
if (entry.matches(event.getMessage())) return;
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-39
@@ -1,39 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.bukkit.listeners;
|
|
||||||
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWCommandEntry;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPermission;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPlayer;
|
|
||||||
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.PlayerCommandSendEvent;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
public class CommandSendListener implements Listener {
|
|
||||||
|
|
||||||
private final CommandWhitelistBukkit plugin;
|
|
||||||
|
|
||||||
public CommandSendListener(CommandWhitelistBukkit plugin) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST)
|
|
||||||
public void onCommandSend(PlayerCommandSendEvent event) {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
|
||||||
Iterator<String> iterator = event.getCommands().iterator();
|
|
||||||
CWPlayer cwPlayer = new CWPlayer(player);
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String command = iterator.next();
|
|
||||||
for (CWCommandEntry entry : cwPlayer.getCommands(plugin.getCWConfig())) {
|
|
||||||
if (entry.argumentMatches(command, 0)) continue;
|
|
||||||
iterator.remove();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-69
@@ -1,69 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.bukkit.listeners;
|
|
||||||
|
|
||||||
import me.youhavetrouble.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWCommandEntry;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPermission;
|
|
||||||
import me.youhavetrouble.commandwhitelist.common.CWPlayer;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import org.bukkit.event.server.TabCompleteEvent;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CommandTabCompleteListener implements Listener {
|
|
||||||
|
|
||||||
private final CommandWhitelistBukkit plugin;
|
|
||||||
|
|
||||||
public CommandTabCompleteListener(CommandWhitelistBukkit plugin ) {
|
|
||||||
this.plugin = plugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
|
|
||||||
public void onCommandTabComplete(TabCompleteEvent event) {
|
|
||||||
if (!(event.getSender() instanceof Player)) return;
|
|
||||||
Player player = (Player) event.getSender();
|
|
||||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
|
||||||
String buffer = event.getBuffer();
|
|
||||||
|
|
||||||
if ((buffer.split(" ").length == 1 && !buffer.endsWith(" ")) || !buffer.startsWith("/")) {
|
|
||||||
plugin.getCWConfig().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (sus packet)");
|
|
||||||
event.setCancelled(true);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (event.getCompletions().isEmpty()) return;
|
|
||||||
|
|
||||||
String[] split = buffer.split(" ");
|
|
||||||
if (split.length == 0) return;
|
|
||||||
String[] splitWithoutLastArg = new String[split.length - 1];
|
|
||||||
System.arraycopy(split, 0, splitWithoutLastArg, 0, splitWithoutLastArg.length);
|
|
||||||
String commandWithoutLastArg = String.join(" ", splitWithoutLastArg);
|
|
||||||
|
|
||||||
CWPlayer cwPlayer = new CWPlayer(player);
|
|
||||||
List<CWCommandEntry> validCompletions = new ArrayList<>();
|
|
||||||
for (CWCommandEntry entry : cwPlayer.getCommands(plugin.getCWConfig())) {
|
|
||||||
if (!entry.partiallyMatches(commandWithoutLastArg)) continue;
|
|
||||||
validCompletions.add(entry);
|
|
||||||
}
|
|
||||||
|
|
||||||
int index = split.length - 1;
|
|
||||||
|
|
||||||
List<String> completions = event.getCompletions();
|
|
||||||
Iterator<String> iterator = completions.iterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
String completion = iterator.next();
|
|
||||||
for (CWCommandEntry entry : validCompletions) {
|
|
||||||
if (entry.argumentMatches(completion, index)) continue;
|
|
||||||
iterator.remove();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCompletions(completions);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,83 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class CWCommandEntry {
|
|
||||||
|
|
||||||
private final String rawEntry;
|
|
||||||
private final List<Pattern> parts;
|
|
||||||
|
|
||||||
protected CWCommandEntry(String command) {
|
|
||||||
this.rawEntry = command;
|
|
||||||
String[] parts = command.split(" ");
|
|
||||||
this.parts = new ArrayList<>(parts.length);
|
|
||||||
for (String part : parts) {
|
|
||||||
Pattern pattern = Pattern.compile(part);
|
|
||||||
this.parts.add(pattern);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the command parts.
|
|
||||||
* @return command parts
|
|
||||||
*/
|
|
||||||
public List<Pattern> getParts() {
|
|
||||||
return Collections.unmodifiableList(parts);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the raw command entry as given in the constructor.
|
|
||||||
* @return raw command entry
|
|
||||||
*/
|
|
||||||
public String getRawEntry() {
|
|
||||||
return rawEntry;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a full command input matches this command entry. Input is a match if all entry slices match the
|
|
||||||
* corresponding command slices, even if there are more command slices than entry slices.
|
|
||||||
* @param command full command input
|
|
||||||
* @return true if the command matches this command entry
|
|
||||||
*/
|
|
||||||
public boolean matches(String command) {
|
|
||||||
if (command == null) return false;
|
|
||||||
if (command.startsWith("/")) command = command.substring(1); // Remove leading slash (if present)
|
|
||||||
String[] parts = command.split(" ");
|
|
||||||
if (parts.length < this.parts.size()) return false;
|
|
||||||
for (int i = 0; i < this.parts.size(); i++) {
|
|
||||||
if (!argumentMatches(parts[i], i)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a command input partially matches this command entry.
|
|
||||||
* @param command command input
|
|
||||||
* @return true if the command partially matches this command entry
|
|
||||||
*/
|
|
||||||
public boolean partiallyMatches(String command) {
|
|
||||||
if (command == null) return false;
|
|
||||||
if (command.startsWith("/")) command = command.substring(1); // Remove leading slash (if present)
|
|
||||||
String[] parts = command.split(" ");
|
|
||||||
for (int i = 0; i < this.parts.size() || i < parts.length; i++) {
|
|
||||||
if (!argumentMatches(parts[i], i)) return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if a command argument matches this command entry.
|
|
||||||
* @param argument command argument
|
|
||||||
* @param index argument index
|
|
||||||
* @return true if the argument matches this command entry
|
|
||||||
*/
|
|
||||||
public boolean argumentMatches(String argument, int index) {
|
|
||||||
if (index < 0 || index >= parts.size()) return false;
|
|
||||||
return parts.get(index).matcher(argument).matches();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
public class CWGroup {
|
|
||||||
|
|
||||||
private final String id;
|
|
||||||
private final HashSet<CWCommandEntry> commands = new HashSet<>();
|
|
||||||
|
|
||||||
public CWGroup(String id, Collection<String> commands) {
|
|
||||||
this.id = id;
|
|
||||||
for (String command : commands) {
|
|
||||||
this.commands.add(new CWCommandEntry(command));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPermission() {
|
|
||||||
return "commandwhitelist.group." + id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<CWCommandEntry> getCommands() {
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addCommand(String command) {
|
|
||||||
this.commands.add(new CWCommandEntry(command));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeCommand(String command) {
|
|
||||||
commands.removeIf(cwCommandEntry -> cwCommandEntry.getRawEntry().equals(command));
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, Object> serialize() {
|
|
||||||
HashMap<String, Object> serializedGroup = new LinkedHashMap<>();
|
|
||||||
List<String> commands = new ArrayList<>();
|
|
||||||
for (CWCommandEntry command : this.commands) {
|
|
||||||
commands.add(command.getRawEntry());
|
|
||||||
}
|
|
||||||
serializedGroup.put("commands", commands);
|
|
||||||
return serializedGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents a player on any supported platform.
|
|
||||||
*/
|
|
||||||
public class CWPlayer {
|
|
||||||
|
|
||||||
private org.bukkit.entity.Player bukkitPlayer;
|
|
||||||
private com.velocitypowered.api.proxy.Player velocityPlayer;
|
|
||||||
private net.md_5.bungee.api.connection.ProxiedPlayer waterfallPlayer;
|
|
||||||
|
|
||||||
public CWPlayer(org.bukkit.entity.Player player) {
|
|
||||||
this.bukkitPlayer = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CWPlayer(com.velocitypowered.api.proxy.Player player) {
|
|
||||||
this.velocityPlayer = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CWPlayer(net.md_5.bungee.api.connection.ProxiedPlayer player) {
|
|
||||||
this.waterfallPlayer = player;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Checks if this player has a permission.
|
|
||||||
* @param permission Permission to check
|
|
||||||
* @return Whether this player has the permission
|
|
||||||
*/
|
|
||||||
public boolean hasPermission(String permission) {
|
|
||||||
if (bukkitPlayer != null) return bukkitPlayer.hasPermission(permission);
|
|
||||||
if (velocityPlayer != null) return velocityPlayer.hasPermission(permission);
|
|
||||||
if (waterfallPlayer != null) return waterfallPlayer.hasPermission(permission);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get the commands that this player can use.
|
|
||||||
* @param CWConfig Current configuration cache
|
|
||||||
* @return Set of commands that this player can use
|
|
||||||
*/
|
|
||||||
public Set<CWCommandEntry> getCommands(CWConfig CWConfig) {
|
|
||||||
HashSet<CWCommandEntry> commands = new HashSet<>();
|
|
||||||
Map<String, CWGroup> groups = CWConfig.getGroupList();
|
|
||||||
for (Map.Entry<String, CWGroup> groupEntry : groups.entrySet()) {
|
|
||||||
CWGroup group = groupEntry.getValue();
|
|
||||||
String groupId = groupEntry.getKey();
|
|
||||||
if (groupId.equalsIgnoreCase("default")) commands.addAll(group.getCommands());
|
|
||||||
else if (hasPermission(group.getPermission())) commands.addAll(group.getCommands());
|
|
||||||
}
|
|
||||||
return commands;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
-13
@@ -1,13 +0,0 @@
|
|||||||
package me.youhavetrouble.commandwhitelist.common.commands;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
|
|
||||||
public interface CWCommandInterface {
|
|
||||||
|
|
||||||
void execute(String[] args);
|
|
||||||
|
|
||||||
Collection<String> tabComplete(String[] args);
|
|
||||||
|
|
||||||
String getPermission();
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
groups:
|
|
||||||
default:
|
|
||||||
commands:
|
|
||||||
- "spawn"
|
|
||||||
- "help version"
|
|
||||||
Reference in New Issue
Block a user