mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2ede673f52 | |||
| de4124aa73 | |||
| cd3ee4b214 | |||
| ea54ae3175 | |||
| c36ac056d5 | |||
| 7186c4de6c | |||
| dfa254f263 | |||
| e80629d708 | |||
| f41bfa7cd1 | |||
| 5af0cdef84 | |||
| e232953f11 | |||
| e8b284db69 | |||
| ed1024c9e7 | |||
| 153ad5f983 | |||
| 9e5b5b5fc7 | |||
| 67ca2c2458 | |||
| 99f7c245da | |||
| cd4c41f1f2 | |||
| 8a86568ce9 | |||
| b08234d268 | |||
| 2c7a089fae | |||
| 41ff6d9d3e | |||
| 9e13c7b2f1 | |||
| 0716514787 | |||
| 428ee93996 | |||
| 8b45057544 |
+1
-1
@@ -1,6 +1,6 @@
|
||||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
github: YouHaveTrouble
|
||||
patreon: # Replace with a single Patreon username
|
||||
open_collective: # Replace with a single Open Collective username
|
||||
ko_fi: YouHaveTrouble
|
||||
|
||||
@@ -1,113 +0,0 @@
|
||||
# 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/
|
||||
@@ -1,129 +0,0 @@
|
||||
<?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.3.0</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.17.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-platform-bukkit</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>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>4.6.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>
|
||||
-154
@@ -1,154 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.bukkit;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
||||
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.bukkit.listeners.protocollib.PacketCommandSendListener;
|
||||
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.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
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);
|
||||
getServer().getPluginManager().registerEvents(new PlayerCommandSendListener(), this);
|
||||
} else {
|
||||
PacketCommandPreProcessListener.protocol(this);
|
||||
PacketCommandSendListener.protocol(this);
|
||||
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
||||
}
|
||||
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);
|
||||
|
||||
PluginCommand command = getCommand("commandwhitelist");
|
||||
if (command != null) {
|
||||
MainCommandExecutor executor = new MainCommandExecutor();
|
||||
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);
|
||||
}
|
||||
}
|
||||
else
|
||||
configCache.reloadConfig();
|
||||
}
|
||||
|
||||
public void reloadPluginConfig(CommandSender sender) {
|
||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||
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;
|
||||
}
|
||||
}
|
||||
-91
@@ -1,91 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.command;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.help.HelpTopic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
public class MainCommandExecutor 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 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) {
|
||||
List<String> serverCommands;
|
||||
try {
|
||||
serverCommands = 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());
|
||||
}
|
||||
serverCommands = new ArrayList<>(commands);
|
||||
}
|
||||
return CWCommand.commandSuggestions(CommandWhitelistBukkit.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.BUKKIT);
|
||||
}
|
||||
}
|
||||
-26
@@ -1,26 +0,0 @@
|
||||
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.endsWith(" ") && buffer.split(" ").length == 1) event.setCancelled(true);
|
||||
if (event.getCompletions().isEmpty()) return;
|
||||
event.setCompletions(CommandUtil.filterSuggestions(buffer, event.getCompletions(), CommandWhitelistBukkit.getSuggestions(player)));
|
||||
}
|
||||
|
||||
}
|
||||
-41
@@ -1,41 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
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("commandwhitelist.bypass")) return;
|
||||
String label = CommandUtil.getCommandLabel(event.getMessage().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);
|
||||
for (String bannedSubCommand : bannedSubCommands) {
|
||||
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||
event.setCancelled(true);
|
||||
audiences.player(player).sendMessage(CWCommand.miniMessage.deserialize(config.prefix + config.subcommand_denied));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
-20
@@ -1,20 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
-37
@@ -1,37 +0,0 @@
|
||||
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.endsWith(" ") && buffer.split(" ").length == 1) {
|
||||
CommandWhitelistBukkit.getConfigCache().debug("Actively prevented "+event.getSender().getName()+"'s tab completion (/[tab] packet)");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
if (event.getCompletions().isEmpty()) {
|
||||
CommandWhitelistBukkit.getConfigCache().debug("Tab completion not provided");
|
||||
return;
|
||||
}
|
||||
event.setCompletions(
|
||||
CommandUtil.filterSuggestions(
|
||||
buffer,
|
||||
event.getCompletions(),
|
||||
CommandWhitelistBukkit.getSuggestions(player)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
-58
@@ -1,58 +0,0 @@
|
||||
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 label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
-40
@@ -1,40 +0,0 @@
|
||||
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 com.mojang.brigadier.tree.RootCommandNode;
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.HashSet;
|
||||
|
||||
public class PacketCommandSendListener {
|
||||
|
||||
public static void protocol(CommandWhitelistBukkit plugin) {
|
||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
||||
commandSendListener(protocolManager, plugin);
|
||||
}
|
||||
|
||||
public static void commandSendListener(ProtocolManager protocolManager, Plugin plugin) {
|
||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.COMMANDS) {
|
||||
@Override
|
||||
public void onPacketSending(PacketEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (event.isPlayerTemporary()) return;
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||
PacketContainer packet = event.getPacket();
|
||||
RootCommandNode<?> node = (RootCommandNode<?>) packet.getModifier().getValues().get(0);
|
||||
node.getChildren().removeIf((cmd) -> !commandList.contains(cmd.getName()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
<?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.3.0</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-1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.velocitypowered</groupId>
|
||||
<artifactId>velocity-api</artifactId>
|
||||
<version>1.1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-text-minimessage</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
<artifactId>paper-api</artifactId>
|
||||
<version>1.17.1-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
@@ -1,65 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
# 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/
|
||||
@@ -1,101 +0,0 @@
|
||||
<?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.3.0</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>
|
||||
</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>
|
||||
-132
@@ -1,132 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.velocity;
|
||||
|
||||
import com.velocitypowered.api.command.CommandMeta;
|
||||
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.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
import org.bstats.charts.SimplePie;
|
||||
import org.bstats.velocity.Metrics;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class CommandWhitelistVelocity {
|
||||
|
||||
private static CommandWhitelistVelocity plugin;
|
||||
private static ProxyServer server;
|
||||
private static ConfigCache configCache;
|
||||
private static Path folder;
|
||||
private static Logger logger;
|
||||
private final Metrics.Factory metricsFactory;
|
||||
|
||||
@Inject
|
||||
public CommandWhitelistVelocity(ProxyServer server, Logger logger, @DataDirectory final Path folder, Metrics.Factory metricsFactory) {
|
||||
CommandWhitelistVelocity.server = server;
|
||||
CommandWhitelistVelocity.folder = folder;
|
||||
CommandWhitelistVelocity.plugin = this;
|
||||
CommandWhitelistVelocity.logger = logger;
|
||||
this.metricsFactory = metricsFactory;
|
||||
|
||||
}
|
||||
|
||||
private static void reloadConfig() {
|
||||
if (configCache == null)
|
||||
configCache = new ConfigCache(new File(String.valueOf(folder), "config.yml"), false, logger);
|
||||
else
|
||||
configCache.reloadConfig();
|
||||
}
|
||||
|
||||
public static void reloadConfig(CommandSource source) {
|
||||
server.getScheduler().buildTask(plugin, () -> {
|
||||
reloadConfig();
|
||||
source.sendMessage(Identity.nil(), CWCommand.miniMessage.deserialize(getConfigCache().prefix + getConfigCache().config_reloaded));
|
||||
}).schedule();
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onProxyInitialization(ProxyInitializeEvent event) {
|
||||
reloadConfig();
|
||||
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
|
||||
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
|
||||
Metrics metrics = metricsFactory.make(this, 8704);
|
||||
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||
server.getCommandManager().hasCommand(commandNode.getName())
|
||||
&& !allowedCommands.contains(commandNode.getName())
|
||||
);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onUserCommandExecuteEvent(com.velocitypowered.api.event.command.CommandExecuteEvent event) {
|
||||
if (!(event.getCommandSource() instanceof Player)) return;
|
||||
Player player = (Player) event.getCommandSource();
|
||||
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
String command = event.getCommand().split(" ")[0];
|
||||
if (server.getCommandManager().hasCommand(command)
|
||||
&& !allowedCommands.contains(command))
|
||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||
}
|
||||
|
||||
public static ConfigCache getConfigCache() {
|
||||
return configCache;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player Velocity Player
|
||||
* @return commands available to the player
|
||||
*/
|
||||
public static 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 static 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;
|
||||
}
|
||||
|
||||
}
|
||||
-83
@@ -1,83 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class VelocityMainCommand implements SimpleCommand {
|
||||
|
||||
@Override
|
||||
public void execute(final Invocation invocation) {
|
||||
CommandSource sender = invocation.source();
|
||||
String[] args = invocation.arguments();
|
||||
String label = invocation.alias();
|
||||
|
||||
if (args.length == 0) {
|
||||
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())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
CommandWhitelistVelocity.reloadConfig(sender);
|
||||
return;
|
||||
case ADD:
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||
else
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||
return;
|
||||
case REMOVE:
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
if (args.length == 3) {
|
||||
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||
else
|
||||
sender.sendMessage(CWCommand.miniMessage.deserialize(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||
} else
|
||||
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||
return;
|
||||
case HELP:
|
||||
default:
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<List<String>> suggestAsync(Invocation invocation) {
|
||||
CommandSource source = invocation.source();
|
||||
String[] args = invocation.arguments();
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
List<String> serverCommands = new ArrayList<>();
|
||||
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.VELOCITY);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
{
|
||||
"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"
|
||||
}
|
||||
@@ -1,113 +0,0 @@
|
||||
# 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/
|
||||
@@ -1,113 +0,0 @@
|
||||
<?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.3.0</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>
|
||||
-125
@@ -1,125 +0,0 @@
|
||||
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.Plugin;
|
||||
import org.bstats.bungeecord.Metrics;
|
||||
import org.bstats.charts.SimplePie;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
-89
@@ -1,89 +0,0 @@
|
||||
package eu.endermite.commandwhitelist.waterfall.command;
|
||||
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
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.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 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) {
|
||||
List<String> serverCommands = new ArrayList<>();
|
||||
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
||||
serverCommands.add(command.getValue().getName());
|
||||
}
|
||||
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()), CWCommand.ImplementationType.WATERFALL);
|
||||
}
|
||||
}
|
||||
-48
@@ -1,48 +0,0 @@
|
||||
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
@@ -1,25 +0,0 @@
|
||||
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
@@ -1,28 +0,0 @@
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
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,21 +6,15 @@
|
||||
|
||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||
<artifactId>CommandWhitelist</artifactId>
|
||||
<version>2.3.0</version>
|
||||
<modules>
|
||||
<module>CommandWhitelistCommon</module>
|
||||
<module>CommandWhitelistBukkit</module>
|
||||
<module>CommandWhitelistVelocity</module>
|
||||
<module>CommandWhitelistWaterfall</module>
|
||||
</modules>
|
||||
<packaging>pom</packaging>
|
||||
<version>3.0.0</version>
|
||||
|
||||
<name>CommandWhitelist</name>
|
||||
|
||||
<description>Control what commands players can use</description>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<website>https://youhavetrouble.me</website>
|
||||
</properties>
|
||||
|
||||
<build>
|
||||
@@ -46,7 +40,17 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<createDependencyReducedPom>false</createDependencyReducedPom>
|
||||
<finalName>${project.name}-${project.parent.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>
|
||||
</execution>
|
||||
</executions>
|
||||
@@ -61,18 +65,76 @@
|
||||
</build>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>pluginwiki-repo</id>
|
||||
<url>https://ci.pluginwiki.us/plugin/repository/everything/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sonatype</id>
|
||||
<url>https://oss.sonatype.org/content/groups/public/</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>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.github.thatsmusic99</groupId>
|
||||
<artifactId>ConfigurationMaster-API</artifactId>
|
||||
<version>v2.0.0-BETA-6</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kyori</groupId>
|
||||
<artifactId>adventure-api</artifactId>
|
||||
<version>4.10.1</version>
|
||||
<version>4.13.1</version>
|
||||
<scope>compile</scope>
|
||||
</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>
|
||||
</project>
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
Command Whitelist is a plugin that allows you to control
|
||||
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://github.com/YouHaveTrouble/CommandWhitelist/releases)
|
||||
[](https://discord.gg/j8KK5dGBps)
|
||||
@@ -15,7 +17,6 @@ precisely what commands players can see and use.
|
||||
<li>Overwrite default "no such command" message with your branding
|
||||
<li>Block tab completion</li>
|
||||
<li>Block command execution</li>
|
||||
<li>Block completion and execution of specified subcommands</li>
|
||||
</ul>
|
||||
|
||||
<b>Compatible versions</b>: 1.13+
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
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
@@ -0,0 +1,33 @@
|
||||
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
@@ -0,0 +1,39 @@
|
||||
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
@@ -0,0 +1,69 @@
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
+12
-21
@@ -1,4 +1,4 @@
|
||||
package eu.endermite.commandwhitelist.common;
|
||||
package me.youhavetrouble.commandwhitelist.common;
|
||||
|
||||
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
||||
import io.github.thatsmusic99.configurationmaster.api.ConfigSection;
|
||||
@@ -7,7 +7,7 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
public class ConfigCache {
|
||||
public class CWConfig {
|
||||
|
||||
private final File configFile;
|
||||
private ConfigFile config;
|
||||
@@ -19,7 +19,7 @@ public class ConfigCache {
|
||||
public boolean useProtocolLib = false;
|
||||
public boolean debug = false;
|
||||
|
||||
public ConfigCache(File configFile, boolean canDoProtocolLib, Object logger) {
|
||||
public CWConfig(File configFile, boolean canDoProtocolLib, Object logger) {
|
||||
this.configFile = configFile;
|
||||
this.canDoProtocolLib = canDoProtocolLib;
|
||||
this.logger = logger;
|
||||
@@ -30,11 +30,14 @@ public class ConfigCache {
|
||||
public boolean reloadConfig() {
|
||||
|
||||
createFiles();
|
||||
config = ConfigFile.loadConfig(configFile);
|
||||
try {
|
||||
config = ConfigFile.loadConfig(configFile);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
config.addDefault("messages.prefix", "CommandWhitelist > ");
|
||||
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_such_subcommand", "<red>No subcommand by that name.");
|
||||
config.addDefault("messages.config_reloaded", "<yellow>Configuration reloaded.");
|
||||
@@ -75,12 +78,8 @@ public class ConfigCache {
|
||||
defaultCommands.add("tpaccept");
|
||||
defaultCommands.add("tpdeny");
|
||||
defaultCommands.add("warp");
|
||||
List<String> defaultSubcommands = new ArrayList<>();
|
||||
defaultSubcommands.add("help about");
|
||||
|
||||
String defaultCustomCommandDeniedMessage = "";
|
||||
|
||||
config.addDefault("groups.default", new CWGroup("default", defaultCommands, defaultSubcommands, defaultCustomCommandDeniedMessage).serialize());
|
||||
config.addDefault("groups.default", new CWGroup("default", defaultCommands).serialize());
|
||||
|
||||
prefix = config.getString("messages.prefix");
|
||||
command_denied = config.getString("messages.command_denied");
|
||||
@@ -106,7 +105,7 @@ public class ConfigCache {
|
||||
try {
|
||||
config.save();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -134,16 +133,8 @@ public class ConfigCache {
|
||||
if (commands.contains(cmd)) continue;
|
||||
commands.add(cmd);
|
||||
}
|
||||
List<String> subCommands = new ArrayList<>();
|
||||
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);
|
||||
|
||||
return new CWGroup(id, commands);
|
||||
}
|
||||
|
||||
public void saveCWGroup(String id, CWGroup group) {
|
||||
@@ -0,0 +1,46 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
+3
-8
@@ -1,4 +1,4 @@
|
||||
package eu.endermite.commandwhitelist.common;
|
||||
package me.youhavetrouble.commandwhitelist.common;
|
||||
|
||||
public enum CWPermission {
|
||||
|
||||
@@ -19,14 +19,9 @@ public enum CWPermission {
|
||||
/**
|
||||
* Allows to check specific group permission
|
||||
*
|
||||
* @param configCache
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
public static String getGroupPermission(ConfigCache configCache, String groupId) {
|
||||
if (configCache.getGroupList().containsKey(groupId))
|
||||
return configCache.getGroupList().get(groupId).getPermission();
|
||||
return null;
|
||||
public static String getGroupPermission(String groupId) {
|
||||
return "commandwhitelist.group." + groupId;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
+34
-23
@@ -1,33 +1,22 @@
|
||||
package eu.endermite.commandwhitelist.common;
|
||||
package me.youhavetrouble.commandwhitelist.common;
|
||||
|
||||
import io.github.thatsmusic99.configurationmaster.api.ConfigFile;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CommandUtil {
|
||||
|
||||
/**
|
||||
* Filters blocked command suggestions from provided collection of strings
|
||||
*
|
||||
* @param buffer Command buffer
|
||||
* @param suggestions Full suggestions list
|
||||
* @param blockedSubCommands Subcommands to filter out
|
||||
* @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;
|
||||
|
||||
public static List<String> filterCommandList(Collection<String> allCommands, Collection<String> allowedCommands) {
|
||||
List<String> filteredCommands = new ArrayList<>();
|
||||
|
||||
|
||||
|
||||
return filteredCommands;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -63,4 +52,26 @@ public class CommandUtil {
|
||||
return parts[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Dumps command list to a file
|
||||
*
|
||||
* @param serverCommands Commands to dump
|
||||
* @return True on successful file save
|
||||
*/
|
||||
public static boolean dumpAllBukkitCommands(ArrayList<String> serverCommands, File file) {
|
||||
try {
|
||||
File parent = new File(file.getParent());
|
||||
if (!parent.exists())
|
||||
parent.mkdir();
|
||||
if (!file.exists())
|
||||
file.createNewFile();
|
||||
ConfigFile dumpFile = ConfigFile.loadConfig(file);
|
||||
dumpFile.set("commands", serverCommands);
|
||||
dumpFile.save();
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
+27
-38
@@ -1,66 +1,55 @@
|
||||
package eu.endermite.commandwhitelist.common.commands;
|
||||
package me.youhavetrouble.commandwhitelist.common.commands;
|
||||
|
||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import me.youhavetrouble.commandwhitelist.common.CWGroup;
|
||||
import me.youhavetrouble.commandwhitelist.common.CWConfig;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
import net.kyori.adventure.text.minimessage.tag.standard.StandardTags;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CWCommand {
|
||||
|
||||
public static MiniMessage miniMessage = MiniMessage.builder().tags(
|
||||
TagResolver.builder()
|
||||
.resolver(StandardTags.color())
|
||||
.resolver(StandardTags.decorations())
|
||||
.resolver(StandardTags.gradient())
|
||||
.resolver(StandardTags.font())
|
||||
.resolver(StandardTags.reset())
|
||||
.resolver(StandardTags.rainbow())
|
||||
.resolver(StandardTags.translatable())
|
||||
.build()
|
||||
).build();
|
||||
public static MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||
|
||||
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||
public static boolean addToWhitelist(CWConfig CWConfig, String command, String group) {
|
||||
CWGroup cwGroup = CWConfig.getGroupList().get(group);
|
||||
if (cwGroup == null) return false;
|
||||
cwGroup.addCommand(command);
|
||||
configCache.saveCWGroup(group, cwGroup);
|
||||
CWConfig.saveCWGroup(group, cwGroup);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean removeFromWhitelist(ConfigCache configCache, String command, String group) {
|
||||
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||
public static boolean removeFromWhitelist(CWConfig CWConfig, String command, String group) {
|
||||
CWGroup cwGroup = CWConfig.getGroupList().get(group);
|
||||
if (cwGroup == null)
|
||||
return false;
|
||||
cwGroup.removeCommand(command);
|
||||
configCache.saveCWGroup(group, cwGroup);
|
||||
CWConfig.saveCWGroup(group, cwGroup);
|
||||
return true;
|
||||
}
|
||||
|
||||
public static Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
|
||||
Component component = miniMessage.deserialize("<rainbow><bold>CommandWhitelist by YouHaveTrouble</bold>")
|
||||
.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " help").color(NamedTextColor.AQUA).append(Component.text(" - Displays this message").color(NamedTextColor.BLUE)));
|
||||
final TextComponent.Builder builder = Component.text();
|
||||
builder.append(miniMessage.deserialize("<rainbow><bold>CommandWhitelist by YouHaveTrouble</bold>"), Component.newline());
|
||||
builder.append(Component.text(baseCommand + " help", NamedTextColor.AQUA), Component.text(" - Displays this message", NamedTextColor.BLUE));
|
||||
if (showReloadCommand) {
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " reload").color(NamedTextColor.AQUA).append(Component.text(" - Reloads plugin configuration").color(NamedTextColor.BLUE)));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " reload", NamedTextColor.AQUA), Component.text(" - Reloads plugin configuration", NamedTextColor.BLUE));
|
||||
}
|
||||
if (showAdminCommands) {
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " add <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Add a command to selected permission group").color(NamedTextColor.BLUE)));
|
||||
component = component.append(Component.newline());
|
||||
component = component.append(Component.text(baseCommand + " remove <group> <command>").color(NamedTextColor.AQUA).append(Component.text(" - Removes a command from selected permission group").color(NamedTextColor.BLUE)));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " add <group> <command>", NamedTextColor.AQUA), Component.text(" - Add a command to selected permission group", NamedTextColor.BLUE));
|
||||
builder.append(Component.newline());
|
||||
builder.append(Component.text(baseCommand + " remove <group> <command>", NamedTextColor.AQUA), Component.text(" - Removes a command from selected permission group", NamedTextColor.BLUE));
|
||||
}
|
||||
return component;
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
public enum CommandType {
|
||||
ADD, REMOVE, HELP, RELOAD
|
||||
ADD, REMOVE, HELP, RELOAD, DUMP
|
||||
}
|
||||
|
||||
public enum ImplementationType {
|
||||
@@ -68,7 +57,7 @@ public class CWCommand {
|
||||
}
|
||||
|
||||
public static List<String> commandSuggestions(
|
||||
ConfigCache config,
|
||||
CWConfig config,
|
||||
Collection<String> serverCommands,
|
||||
String[] args, boolean reloadPerm,
|
||||
boolean adminPerm,
|
||||
@@ -85,6 +74,7 @@ public class CWCommand {
|
||||
if (adminPerm) {
|
||||
list.add("add");
|
||||
list.add("remove");
|
||||
list.add("dump");
|
||||
}
|
||||
}
|
||||
return list;
|
||||
@@ -97,6 +87,8 @@ public class CWCommand {
|
||||
list.add("add");
|
||||
if ("remove".startsWith(args[0]) && adminPerm)
|
||||
list.add("remove");
|
||||
if ("dump".startsWith(args[0]) && adminPerm)
|
||||
list.add("dump");
|
||||
return list;
|
||||
case 2:
|
||||
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
||||
@@ -112,10 +104,7 @@ public class CWCommand {
|
||||
if (!adminPerm) return list;
|
||||
CWGroup group = config.getGroupList().get(args[1]);
|
||||
if (group == null) return list;
|
||||
for (String s : group.getCommands()) {
|
||||
if (s.startsWith(args[2]))
|
||||
list.add(s);
|
||||
}
|
||||
// TODO
|
||||
return list;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package me.youhavetrouble.commandwhitelist.common.commands;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface CWCommandInterface {
|
||||
|
||||
void execute(String[] args);
|
||||
|
||||
Collection<String> tabComplete(String[] args);
|
||||
|
||||
String getPermission();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
groups:
|
||||
default:
|
||||
commands:
|
||||
- "spawn"
|
||||
- "help version"
|
||||
+7
-6
@@ -1,13 +1,14 @@
|
||||
name: CommandWhitelist
|
||||
prefix: CommandWhitelist
|
||||
name: "${project.name}"
|
||||
version: ${project.version}
|
||||
api-version: 1.13
|
||||
main: eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit
|
||||
authors: [YouHaveTrouble]
|
||||
website: youhavetrouble.me
|
||||
main: "${project.groupId}.bukkit.CommandWhitelistBukkit"
|
||||
authors:
|
||||
- "YouHaveTrouble"
|
||||
website: "${project.url}"
|
||||
folia-supported: true
|
||||
softdepend:
|
||||
- ProtocolLib
|
||||
description: Control what commands players can use
|
||||
description: "${project.description}"
|
||||
commands:
|
||||
commandwhitelist:
|
||||
aliases:
|
||||
Reference in New Issue
Block a user