mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
reorganize stuff
This commit is contained in:
@@ -0,0 +1,98 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<groupId>eu.endermite.bukkit</groupId>
|
||||||
|
<artifactId>CommandWhitelistBukkit</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>CommandWhitelistBukkit</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>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>papermc-repo</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<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>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.destroystokyo.paper</groupId>
|
||||||
|
<artifactId>paper-api</artifactId>
|
||||||
|
<version>1.16.5-R0.1-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bukkit</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.comphenix.protocol</groupId>
|
||||||
|
<artifactId>ProtocolLib</artifactId>
|
||||||
|
<version>4.6.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+114
@@ -0,0 +1,114 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.listeners.PacketCommandPreProcessListener;
|
||||||
|
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.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.command.MainCommand;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.metrics.BukkitMetrics;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
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);
|
||||||
|
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
||||||
|
}
|
||||||
|
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||||
|
|
||||||
|
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
||||||
|
|
||||||
|
int pluginId = 8705;
|
||||||
|
new BukkitMetrics(this, pluginId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadPluginConfig() {
|
||||||
|
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
||||||
|
configCache = new ConfigCache(configFile, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void reloadPluginConfig(CommandSender sender) {
|
||||||
|
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
||||||
|
reloadPluginConfig();
|
||||||
|
for (Player p : Bukkit.getOnlinePlayers()) {
|
||||||
|
p.updateCommands();
|
||||||
|
}
|
||||||
|
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(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, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission("commandwhitelist.group." + s.getKey()))
|
||||||
|
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, 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("commandwhitelist.group." + s.getKey()))
|
||||||
|
continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
}
|
||||||
+42
@@ -0,0 +1,42 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class BukkitCommandHandler {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bukkit Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(org.bukkit.entity.Player player, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission("commandwhitelist.group." + s.getKey()))
|
||||||
|
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, 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("commandwhitelist.group." + s.getKey()))
|
||||||
|
continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+66
@@ -0,0 +1,66 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class MainCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
// send help
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0]);
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.reload")) {
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
|
||||||
|
return true;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().added_to_whitelist));
|
||||||
|
else
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(Component.text("/cw add <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(CommandWhitelistBukkit.getConfigCache(), args[2], args[1]))
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().removed_from_whitelist));
|
||||||
|
else
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
CommandWhitelistBukkit.getAudiences().sender(sender).sendMessage(Component.text("/cw remove <group> <command>"));
|
||||||
|
return true;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
// send help
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// send help
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
+60
@@ -0,0 +1,60 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
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.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
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("commandwhitelist.bypass"))
|
||||||
|
return;
|
||||||
|
|
||||||
|
ConfigCache configCache = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
|
||||||
|
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||||
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player, configCache.getGroupList());
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.command_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player, configCache.getGroupList());
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (string.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
CommandWhitelistBukkit.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
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());
|
||||||
|
|
||||||
|
ConfigCache configCache = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||||
|
|
||||||
|
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player, configCache.getGroupList());
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
audiences.player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.command_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistBukkit.getSuggestions(player, configCache.getGroupList());
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (event.getMessage().toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||||
|
audiences.player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
@@ -13,7 +13,7 @@ public class PlayerCommandSendListener implements Listener {
|
|||||||
Player player = event.getPlayer();
|
Player player = event.getPlayer();
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player, CommandWhitelistBukkit.getConfigCache().getGroupList());
|
||||||
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+24
@@ -0,0 +1,24 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
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 TabCompleteBlockerListener implements Listener {
|
||||||
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
|
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
||||||
|
if (!(event.getSender() instanceof Player))
|
||||||
|
return;
|
||||||
|
Player player = (Player) event.getSender();
|
||||||
|
event.setCompletions(
|
||||||
|
CommandUtil.filterSuggestions(
|
||||||
|
event.getBuffer(),
|
||||||
|
event.getCompletions(),
|
||||||
|
CommandWhitelistBukkit.getSuggestions(player, CommandWhitelistBukkit.getConfigCache().getGroupList())
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.metrics;
|
package eu.endermite.commandwhitelist.bukkit.metrics;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
<?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">
|
||||||
|
<parent>
|
||||||
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
|
<groupId>eu.endermite</groupId>
|
||||||
|
<version>2.0</version>
|
||||||
|
</parent>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
|
||||||
|
<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>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.yaml/snakeyaml -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.yaml</groupId>
|
||||||
|
<artifactId>snakeyaml</artifactId>
|
||||||
|
<version>1.28</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
||||||
+56
@@ -0,0 +1,56 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common;
|
||||||
|
|
||||||
|
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) {
|
||||||
|
String cmd = buffer.replace(getLastArgument(buffer), "");
|
||||||
|
for (String s : blockedSubCommands) {
|
||||||
|
String slast = getLastArgument(s.toLowerCase());
|
||||||
|
String scommand = s.replace(slast, "");
|
||||||
|
cmd = cmd.replace(getLastArgument(cmd), "");
|
||||||
|
if (cmd.substring(1).startsWith("/" + scommand)) {
|
||||||
|
while (suggestions.contains(slast))
|
||||||
|
suggestions.remove(slast);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new ArrayList<>(suggestions);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command
|
||||||
|
* @return Last argument of the command
|
||||||
|
*/
|
||||||
|
public static String getLastArgument(String cmd) {
|
||||||
|
String[] parts = cmd.split(" ");
|
||||||
|
if (parts.length <= 1)
|
||||||
|
return "";
|
||||||
|
String last = "";
|
||||||
|
for (String part : parts) {
|
||||||
|
last = part;
|
||||||
|
}
|
||||||
|
return last;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param cmd The command
|
||||||
|
* @return Command label
|
||||||
|
*/
|
||||||
|
public static String getCommandLabel(String cmd) {
|
||||||
|
String[] parts = cmd.split(" ");
|
||||||
|
if (parts[0].startsWith("/"))
|
||||||
|
parts[0] = parts[0].substring(1);
|
||||||
|
return parts[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+14
-5
@@ -8,14 +8,18 @@ import java.util.*;
|
|||||||
|
|
||||||
public class ConfigCache {
|
public class ConfigCache {
|
||||||
|
|
||||||
|
private final File configFile;
|
||||||
|
private final boolean canDoProtocolLib;
|
||||||
private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>();
|
private final HashMap<String, CWGroup> groupList = new LinkedHashMap<>();
|
||||||
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
|
public String prefix, command_denied, no_permission, no_such_subcommand, config_reloaded, added_to_whitelist,
|
||||||
removed_from_whitelist, group_doesnt_exist, subcommand_denied;
|
removed_from_whitelist, group_doesnt_exist, subcommand_denied;
|
||||||
public boolean useProtocolLib = false;
|
public boolean useProtocolLib = false;
|
||||||
|
|
||||||
public ConfigCache(File configFile, boolean canDoProtocolLib) {
|
public ConfigCache(File configFile, boolean canDoProtocolLib) {
|
||||||
if (!reloadConfig(configFile, canDoProtocolLib))
|
this.configFile = configFile;
|
||||||
reloadConfig(configFile, canDoProtocolLib);
|
this.canDoProtocolLib = canDoProtocolLib;
|
||||||
|
if (!reloadConfig())
|
||||||
|
reloadConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveDefaultConfig(Map<String, Object> data, File configFile, boolean canDoProtocolLib) {
|
public void saveDefaultConfig(Map<String, Object> data, File configFile, boolean canDoProtocolLib) {
|
||||||
@@ -23,7 +27,7 @@ public class ConfigCache {
|
|||||||
data.put("messages", processMessages());
|
data.put("messages", processMessages());
|
||||||
|
|
||||||
if (canDoProtocolLib) {
|
if (canDoProtocolLib) {
|
||||||
data.put("use_protocollib_to_detect_commands", false);
|
data.put("use_protocollib_to_detect_commands", useProtocolLib);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> defaultCommands = new ArrayList<>();
|
List<String> defaultCommands = new ArrayList<>();
|
||||||
@@ -45,7 +49,12 @@ public class ConfigCache {
|
|||||||
defaultSubcommands.add("help about");
|
defaultSubcommands.add("help about");
|
||||||
|
|
||||||
HashMap<String, Object> groups = new LinkedHashMap<>();
|
HashMap<String, Object> groups = new LinkedHashMap<>();
|
||||||
groups.put("default", new CWGroup("default", defaultCommands, defaultSubcommands).serialize());
|
|
||||||
|
for (CWGroup group : groupList.values()) {
|
||||||
|
groups.put(group.getId(), group.serialize());
|
||||||
|
}
|
||||||
|
|
||||||
|
groups.putIfAbsent("default", new CWGroup("default", defaultCommands, defaultSubcommands).serialize());
|
||||||
|
|
||||||
data.putIfAbsent("groups", groups);
|
data.putIfAbsent("groups", groups);
|
||||||
|
|
||||||
@@ -63,7 +72,7 @@ public class ConfigCache {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean reloadConfig(File configFile, boolean canDoProtocolLib) {
|
public boolean reloadConfig() {
|
||||||
HashMap<String, Object> config = new LinkedHashMap<>();
|
HashMap<String, Object> config = new LinkedHashMap<>();
|
||||||
Yaml yaml = new Yaml();
|
Yaml yaml = new Yaml();
|
||||||
try {
|
try {
|
||||||
+53
@@ -0,0 +1,53 @@
|
|||||||
|
package eu.endermite.commandwhitelist.common.commands;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.event.HoverEvent;
|
||||||
|
import net.kyori.adventure.text.format.NamedTextColor;
|
||||||
|
import net.kyori.adventure.text.format.TextDecoration;
|
||||||
|
|
||||||
|
|
||||||
|
public class CWCommand {
|
||||||
|
|
||||||
|
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
|
if (cwGroup == null)
|
||||||
|
return false;
|
||||||
|
cwGroup.addCommand(command);
|
||||||
|
configCache.reloadConfig();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean removeFromWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
|
if (cwGroup == null)
|
||||||
|
return false;
|
||||||
|
cwGroup.removeCommand(command);
|
||||||
|
configCache.reloadConfig();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Component helpComponent(String baseCommand, boolean showReloadCommand, boolean showAdminCommands) {
|
||||||
|
Component component = Component.text("CommandWhitelist by YouHaveTrouble").decorate(TextDecoration.BOLD).color(NamedTextColor.BLUE)
|
||||||
|
.append(Component.newline());
|
||||||
|
component = component.append(Component.text("Hover over the command to see what it does!").color(NamedTextColor.AQUA)).decoration(TextDecoration.BOLD, false).append(Component.newline());
|
||||||
|
component = component.append(Component.text("/"+baseCommand+" help").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Displays this message"))));
|
||||||
|
if (showReloadCommand) {
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/"+baseCommand+" reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
|
||||||
|
}
|
||||||
|
if (showAdminCommands) {
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/"+baseCommand+" add <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Add a command to selected permission group"))));
|
||||||
|
component = component.append(Component.newline());
|
||||||
|
component = component.append(Component.text("/"+baseCommand+" remove <group> <command>").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Removes a command from selected permission group"))));
|
||||||
|
}
|
||||||
|
return component;
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum CommandType {
|
||||||
|
ADD, REMOVE, HELP, RELOAD
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,103 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelistVelocity</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<source>8</source>
|
||||||
|
<target>8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>CommandWhitelistVelocity</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>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>release</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.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>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>src/main/resources</directory>
|
||||||
|
<filtering>true</filtering>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>velocitypowered-repo</id>
|
||||||
|
<url>https://repo.velocitypowered.com/releases/</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>1.1.0</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+42
-34
@@ -1,6 +1,5 @@
|
|||||||
package eu.endermite.commandwhitelist.velocity;
|
package eu.endermite.commandwhitelist.velocity;
|
||||||
|
|
||||||
import com.moandjiezana.toml.Toml;
|
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
import com.velocitypowered.api.event.Subscribe;
|
import com.velocitypowered.api.event.Subscribe;
|
||||||
@@ -10,25 +9,24 @@ import com.velocitypowered.api.event.proxy.ProxyInitializeEvent;
|
|||||||
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||||
import com.velocitypowered.api.proxy.Player;
|
import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
||||||
import eu.endermite.commandwhitelist.velocity.config.VelocityConfigCache;
|
|
||||||
import net.kyori.adventure.identity.Identity;
|
import net.kyori.adventure.identity.Identity;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.util.List;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class CommandWhitelistVelocity {
|
public class CommandWhitelistVelocity {
|
||||||
|
|
||||||
private static CommandWhitelistVelocity plugin;
|
private static CommandWhitelistVelocity plugin;
|
||||||
private static ProxyServer server;
|
private static ProxyServer server;
|
||||||
private static VelocityConfigCache configCache;
|
private static ConfigCache configCache;
|
||||||
private static Path folder;
|
private static Path folder;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@@ -38,35 +36,14 @@ public class CommandWhitelistVelocity {
|
|||||||
CommandWhitelistVelocity.plugin = this;
|
CommandWhitelistVelocity.plugin = this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Toml loadConfig(Path path) {
|
|
||||||
File folder = path.toFile();
|
|
||||||
File file = new File(folder, "config.toml");
|
|
||||||
if (!file.getParentFile().exists())
|
|
||||||
file.getParentFile().mkdirs();
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
try (InputStream input = CommandWhitelistVelocity.class.getResourceAsStream("/" + file.getName())) {
|
|
||||||
if (input != null) {
|
|
||||||
Files.copy(input, file.toPath());
|
|
||||||
} else {
|
|
||||||
file.createNewFile();
|
|
||||||
}
|
|
||||||
} catch (IOException exception) {
|
|
||||||
exception.printStackTrace();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new Toml().read(file);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void reloadConfig() {
|
private static void reloadConfig() {
|
||||||
configCache = new VelocityConfigCache(loadConfig(folder));
|
configCache = new ConfigCache(new File(String.valueOf(folder), "config.yml"), false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reloadConfig(CommandSource source) {
|
public static void reloadConfig(CommandSource source) {
|
||||||
server.getScheduler().buildTask(plugin, () -> {
|
server.getScheduler().buildTask(plugin, () -> {
|
||||||
reloadConfig();
|
reloadConfig();
|
||||||
source.sendMessage(Identity.nil(), Component.text(getConfigCache().getConfigReloaded()));
|
source.sendMessage(Identity.nil(), Component.text(getConfigCache().config_reloaded));
|
||||||
}).schedule();
|
}).schedule();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,7 +58,7 @@ public class CommandWhitelistVelocity {
|
|||||||
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||||
if (event.getPlayer().hasPermission("commandwhitelist.bypass"))
|
if (event.getPlayer().hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
List<String> allowedCommands = CommandsList.getCommands(event.getPlayer());
|
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(event.getPlayer(), configCache.getGroupList());
|
||||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||||
server.getCommandManager().hasCommand(commandNode.getName())
|
server.getCommandManager().hasCommand(commandNode.getName())
|
||||||
&& !allowedCommands.contains(commandNode.getName())
|
&& !allowedCommands.contains(commandNode.getName())
|
||||||
@@ -97,15 +74,46 @@ public class CommandWhitelistVelocity {
|
|||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
List<String> allowedCommands = CommandsList.getCommands(player);
|
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player, configCache.getGroupList());
|
||||||
String command = event.getCommand().split(" ")[0];
|
String command = event.getCommand().split(" ")[0];
|
||||||
if (server.getCommandManager().hasCommand(command)
|
if (server.getCommandManager().hasCommand(command)
|
||||||
&& !allowedCommands.contains(command))
|
&& !allowedCommands.contains(command))
|
||||||
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
event.setResult(CommandExecuteEvent.CommandResult.forwardToServer());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VelocityConfigCache getConfigCache() {
|
public static ConfigCache getConfigCache() {
|
||||||
return configCache;
|
return configCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Velocity Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(Player player, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission("commandwhitelist.group." + s.getKey()))
|
||||||
|
commandList.addAll(s.getValue().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("commandwhitelist.group." + s.getKey()))
|
||||||
|
continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
+1
-2
@@ -6,7 +6,6 @@ import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
|||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ public class VelocityMainCommand implements SimpleCommand {
|
|||||||
if (source.hasPermission("commandwhitelist.reload")) {
|
if (source.hasPermission("commandwhitelist.reload")) {
|
||||||
CommandWhitelistVelocity.reloadConfig(source);
|
CommandWhitelistVelocity.reloadConfig(source);
|
||||||
} else {
|
} else {
|
||||||
source.sendMessage(Component.text(CommandWhitelistVelocity.getConfigCache().getNoPermission()));
|
source.sendMessage(Component.text(CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"id":"commandwhitelist",
|
"id":"commandwhitelist",
|
||||||
"name":"CommandWhitelist",
|
"name":"CommandWhitelist",
|
||||||
"version":"${project.version}",
|
"version":"${project.version}",
|
||||||
"description":"Control what commands players can use",
|
"description":"You decide what commands players can use or tab complete on your server!",
|
||||||
"authors":["YouHaveTrouble"],
|
"authors":["YouHaveTrouble"],
|
||||||
"dependencies":[],
|
"dependencies":[],
|
||||||
"main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
"main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
<?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>
|
||||||
|
|
||||||
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
|
<artifactId>CommandWhitelistWaterfall</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>CommandWhitelist</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>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<defaultGoal>clean package</defaultGoal>
|
||||||
|
<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>
|
||||||
|
</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>destroystokyo-repo</id>
|
||||||
|
<url>https://repo.destroystokyo.com/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
<repository>
|
||||||
|
<id>papermc</id>
|
||||||
|
<url>https://papermc.io/repo/repository/maven-public/</url>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.waterfallmc</groupId>
|
||||||
|
<artifactId>waterfall-api</artifactId>
|
||||||
|
<version>1.16-R0.5-SNAPSHOT</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>eu.endermite</groupId>
|
||||||
|
<artifactId>Common</artifactId>
|
||||||
|
<version>2.0</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.kyori</groupId>
|
||||||
|
<artifactId>adventure-platform-bungeecord</artifactId>
|
||||||
|
<version>4.0.0-SNAPSHOT</version>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</project>
|
||||||
+106
@@ -0,0 +1,106 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.command.BungeeMainCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.metrics.BungeeMetrics;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
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 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);
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
|
||||||
|
try {
|
||||||
|
Class.forName("io.github.waterfallmc.waterfall.conf.WaterfallConfiguration");
|
||||||
|
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
getLogger().severe(ChatColor.DARK_RED+"Bungee tab completion blocker requires Waterfall other Waterfall fork.");
|
||||||
|
}
|
||||||
|
|
||||||
|
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
|
||||||
|
|
||||||
|
int pluginId = 8704;
|
||||||
|
new BungeeMetrics(this, pluginId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static CommandWhitelistWaterfall getPlugin() {
|
||||||
|
return plugin;
|
||||||
|
}
|
||||||
|
public static ConfigCache getConfigCache() {
|
||||||
|
return configCache;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static BungeeAudiences getAudiences() {
|
||||||
|
return audiences;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfig() {
|
||||||
|
try {
|
||||||
|
if (!getDataFolder().exists()) {
|
||||||
|
getDataFolder().mkdir();
|
||||||
|
}
|
||||||
|
|
||||||
|
configCache = new ConfigCache(new File(getDataFolder(), "config.yml"), false);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadConfigAsync(CommandSender sender) {
|
||||||
|
getProxy().getScheduler().runAsync(this, () -> {
|
||||||
|
loadConfig();
|
||||||
|
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().config_reloaded));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param player Bungee Player
|
||||||
|
* @return commands available to the player
|
||||||
|
*/
|
||||||
|
public static HashSet<String> getCommands(ProxiedPlayer player, HashMap<String, CWGroup> groups) {
|
||||||
|
HashSet<String> commandList = new HashSet<>();
|
||||||
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
|
commandList.addAll(s.getValue().getCommands());
|
||||||
|
else if (player.hasPermission("commandwhitelist.group." + s.getKey()))
|
||||||
|
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) {
|
||||||
|
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("commandwhitelist.group." + s.getKey()))
|
||||||
|
continue;
|
||||||
|
suggestionList.addAll(s.getValue().getSubCommands());
|
||||||
|
}
|
||||||
|
return suggestionList;
|
||||||
|
}
|
||||||
|
}
|
||||||
+74
@@ -0,0 +1,74 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.command;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.text.Component;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
import net.md_5.bungee.api.CommandSender;
|
||||||
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
|
import net.md_5.bungee.api.plugin.TabExecutor;
|
||||||
|
|
||||||
|
public class BungeeMainCommand extends Command implements TabExecutor {
|
||||||
|
|
||||||
|
public BungeeMainCommand(String name) {
|
||||||
|
super(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void execute(CommandSender sender, String[] args) {
|
||||||
|
if (args.length == 0) {
|
||||||
|
// send help
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0]);
|
||||||
|
switch (commandType) {
|
||||||
|
case RELOAD:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.reload")) {
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender);
|
||||||
|
return;
|
||||||
|
case ADD:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.addToWhitelist(CommandWhitelistWaterfall.getConfigCache(), args[2], args[1]))
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().added_to_whitelist));
|
||||||
|
else
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(Component.text("/cw add <group> <command>"));
|
||||||
|
return;
|
||||||
|
case REMOVE:
|
||||||
|
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().no_permission));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (args.length == 3) {
|
||||||
|
if (CWCommand.removeFromWhitelist(CommandWhitelistWaterfall.getConfigCache(), args[2], args[1]))
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().removed_from_whitelist));
|
||||||
|
else
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + CommandWhitelistWaterfall.getConfigCache().group_doesnt_exist));
|
||||||
|
} else
|
||||||
|
CommandWhitelistWaterfall.getAudiences().sender(sender).sendMessage(Component.text("/cw remove <group> <command>"));
|
||||||
|
return;
|
||||||
|
case HELP:
|
||||||
|
default:
|
||||||
|
// send help
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
// send help
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
|
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
|
||||||
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
|
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("commandwhitelist.bypass"))
|
||||||
|
return;
|
||||||
|
String command = event.getMessage().toLowerCase();
|
||||||
|
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
|
||||||
|
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
|
||||||
|
|
||||||
|
String label = CommandUtil.getCommandLabel(command);
|
||||||
|
HashSet<String> commands = CommandWhitelistWaterfall.getCommands(player, configCache.getGroupList());
|
||||||
|
if (!commands.contains(label)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
CommandWhitelistWaterfall.getAudiences().player(player).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.command_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player, configCache.getGroupList());
|
||||||
|
for (String bannedSubCommand : bannedSubCommands) {
|
||||||
|
if (command.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
audiences.player(player).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.subcommand_denied));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-5
@@ -1,7 +1,6 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.listeners;
|
package eu.endermite.commandwhitelist.waterfall.listeners;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
import net.md_5.bungee.api.plugin.Listener;
|
||||||
@@ -18,8 +17,8 @@ public class WaterfallDefineCommandsListener implements Listener {
|
|||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
if (player.hasPermission("commandwhitelist.bypass"))
|
||||||
return;
|
return;
|
||||||
HashMap<String, Command> commandHashMap = new HashMap<>();
|
HashMap<String, Command> commandHashMap = new HashMap<>();
|
||||||
CommandsList.getCommands(player).forEach(cmdName ->
|
CommandWhitelistWaterfall.getCommands(player, CommandWhitelistWaterfall.getConfigCache().getGroupList()).forEach(cmdName ->
|
||||||
CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()
|
CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
.filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
|
||||||
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
.forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.metrics;
|
package eu.endermite.commandwhitelist.waterfall.metrics;
|
||||||
|
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
@@ -6,8 +6,14 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite</groupId>
|
<groupId>eu.endermite</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-SNAPSHOT</version>
|
<version>2.0</version>
|
||||||
<packaging>jar</packaging>
|
<modules>
|
||||||
|
<module>CommandWhitelistCommon</module>
|
||||||
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
<module>CommandWhitelistVelocity</module>
|
||||||
|
<module>CommandWhitelistWaterfall</module>
|
||||||
|
</modules>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
|
||||||
<name>CommandWhitelist</name>
|
<name>CommandWhitelist</name>
|
||||||
|
|
||||||
@@ -54,62 +60,28 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
|
||||||
<id>spigotmc-repo</id>
|
|
||||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
|
||||||
</repository>
|
|
||||||
<repository>
|
<repository>
|
||||||
<id>sonatype</id>
|
<id>sonatype</id>
|
||||||
<url>https://oss.sonatype.org/content/groups/public/</url>
|
<url>https://oss.sonatype.org/content/groups/public/</url>
|
||||||
</repository>
|
</repository>
|
||||||
<repository>
|
<repository>
|
||||||
<id>jitpack.io</id>
|
<id>minecraft-repo</id>
|
||||||
<url>https://jitpack.io</url>
|
<url>https://libraries.minecraft.net/</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>
|
|
||||||
<repository>
|
|
||||||
<id>velocity</id>
|
|
||||||
<url>https://repo.velocitypowered.com/snapshots/</url>
|
|
||||||
</repository>
|
</repository>
|
||||||
</repositories>
|
</repositories>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.spigotmc</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>spigot-api</artifactId>
|
<artifactId>adventure-api</artifactId>
|
||||||
<version>1.16.5-R0.1-SNAPSHOT</version>
|
<version>4.7.0</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>net.md-5</groupId>
|
<groupId>net.kyori</groupId>
|
||||||
<artifactId>bungeecord-api</artifactId>
|
<artifactId>adventure-text-minimessage</artifactId>
|
||||||
<version>1.15-SNAPSHOT</version>
|
<version>4.1.0-SNAPSHOT</version>
|
||||||
<scope>provided</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>io.github.waterfallmc</groupId>
|
|
||||||
<artifactId>waterfall-api</artifactId>
|
|
||||||
<version>1.16-R0.4-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.velocitypowered</groupId>
|
|
||||||
<artifactId>velocity-api</artifactId>
|
|
||||||
<version>1.1.0-SNAPSHOT</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>com.comphenix.protocol</groupId>
|
|
||||||
<artifactId>ProtocolLib</artifactId>
|
|
||||||
<version>4.6.0</version>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
@@ -1,80 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee;
|
|
||||||
|
|
||||||
import com.google.common.io.ByteStreams;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.command.BungeeMainCommand;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.config.BungeeConfigCache;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.listeners.BungeeChatEventListener;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.listeners.WaterfallDefineCommandsListener;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.metrics.BungeeMetrics;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
import net.md_5.bungee.api.CommandSender;
|
|
||||||
import net.md_5.bungee.api.plugin.Plugin;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.OutputStream;
|
|
||||||
|
|
||||||
public final class CommandWhitelistBungee extends Plugin {
|
|
||||||
|
|
||||||
private static CommandWhitelistBungee plugin;
|
|
||||||
private static BungeeConfigCache configCache;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
plugin = this;
|
|
||||||
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
|
|
||||||
loadConfig();
|
|
||||||
this.getProxy().getPluginManager().registerListener(this, new BungeeChatEventListener());
|
|
||||||
try {
|
|
||||||
Class.forName("io.github.waterfallmc.waterfall.conf.WaterfallConfiguration");
|
|
||||||
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
getLogger().severe(ChatColor.DARK_RED+"Bungee tab completion blocker requires Waterfall other Waterfall fork.");
|
|
||||||
}
|
|
||||||
|
|
||||||
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
|
|
||||||
|
|
||||||
int pluginId = 8704;
|
|
||||||
new BungeeMetrics(this, pluginId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandWhitelistBungee getPlugin() {
|
|
||||||
return plugin;
|
|
||||||
}
|
|
||||||
public static BungeeConfigCache getConfigCache() {
|
|
||||||
return configCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfig() {
|
|
||||||
try {
|
|
||||||
if (!getDataFolder().exists()) {
|
|
||||||
getDataFolder().mkdir();
|
|
||||||
}
|
|
||||||
|
|
||||||
File file = new File(getDataFolder(), "config.yml");
|
|
||||||
|
|
||||||
if (!file.exists()) {
|
|
||||||
file.createNewFile();
|
|
||||||
try (InputStream in = getResourceAsStream("bungeeconfig.yml");
|
|
||||||
OutputStream out = new FileOutputStream(file)) {
|
|
||||||
ByteStreams.copy(in, out);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final Configuration config = ConfigurationProvider.getProvider(YamlConfiguration.class).load(file);
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(getDataFolder(), "config.yml"));
|
|
||||||
configCache = new BungeeConfigCache(config);
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void loadConfigAsync(CommandSender sender) {
|
|
||||||
getProxy().getScheduler().runAsync(this, () -> {
|
|
||||||
loadConfig();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getConfigReloaded()));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,127 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.command;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
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) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
CommandWhitelistBungee.getPlugin().loadConfigAsync(sender);
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
}
|
|
||||||
} else if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().addCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelistBungee.getConfigCache().getWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelistBungee.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/bcw add <group> <command>");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoPermission()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().removeCommand(args[2], args[1])) {
|
|
||||||
String msg = String.format(CommandWhitelistBungee.getConfigCache().getRemovedWhitelistedCommand(), args[2], args[1]);
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
} else {
|
|
||||||
String msg = CommandWhitelistBungee.getConfigCache().getNoSuchGroup();
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', msg));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/bcw remove <group> <command>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + CommandWhitelistBungee.getConfigCache().getNoSubCommand()));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/bcw reload &b- Reload bungee plugin configuration"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
|
||||||
List<String> list = new ArrayList<>();
|
|
||||||
if (args.length == 1) {
|
|
||||||
if ("reload".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
list.add("reload");
|
|
||||||
}
|
|
||||||
if ("add".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("add");
|
|
||||||
}
|
|
||||||
if ("remove".startsWith(args[0]) && sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
list.add("remove");
|
|
||||||
}
|
|
||||||
} else if (args.length == 2) {
|
|
||||||
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().startsWith(args[1])) {
|
|
||||||
list.add(s.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (args.length == 3) {
|
|
||||||
if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
try {
|
|
||||||
for (String s : CommandWhitelistBungee.getConfigCache().getPermList().get(args[1])) {
|
|
||||||
if (s.startsWith(args[2])) {
|
|
||||||
list.add(s);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
|
||||||
return list;
|
|
||||||
|
|
||||||
for (Map.Entry<String, Command> command : CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()) {
|
|
||||||
if (command.getKey().startsWith("/"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (CommandWhitelistBungee.getConfigCache().getPermList().get(args[1]).contains(command.getKey()))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
if (command.getKey().startsWith(args[2]))
|
|
||||||
list.add(command.getKey());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,80 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.config;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import net.md_5.bungee.config.Configuration;
|
|
||||||
import net.md_5.bungee.config.ConfigurationProvider;
|
|
||||||
import net.md_5.bungee.config.YamlConfiguration;
|
|
||||||
import java.io.File;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class BungeeConfigCache {
|
|
||||||
|
|
||||||
private final Configuration config;
|
|
||||||
private final HashMap<String, List<String>> permList = new HashMap<>();
|
|
||||||
private final String prefix, commandDenied, noPermission, noSubCommand, configReloaded, whitelistedCommand,
|
|
||||||
removedWhitelistedCommand, noSuchGroup;
|
|
||||||
private List<String> commandDeniedList;
|
|
||||||
|
|
||||||
public BungeeConfigCache(Configuration config) {
|
|
||||||
|
|
||||||
this.config = config;
|
|
||||||
|
|
||||||
prefix = config.getString("messages.prefix");
|
|
||||||
commandDenied = config.getString("messages.command-denied", null);
|
|
||||||
commandDeniedList = config.getStringList("messages.command-denied");
|
|
||||||
noPermission = config.getString("messages.no-permission");
|
|
||||||
noSubCommand = config.getString("messages.no-such-subcommand");
|
|
||||||
configReloaded = config.getString("messages.config-reloaded");
|
|
||||||
whitelistedCommand = config.getString("messages.added-to-whitelist", "&eWhitelisted command &6%s &efor permission &6%s");
|
|
||||||
removedWhitelistedCommand = config.getString("messages.removed-from-whitelist", "&eRemoved command &6%s &efrom permission &6%s");
|
|
||||||
noSuchGroup = config.getString("messages.group-doesnt-exist", "&cGroup %s doesn't exist");
|
|
||||||
|
|
||||||
Collection<String> perms = config.getSection("commands").getKeys();
|
|
||||||
for (String s : perms) {
|
|
||||||
this.permList.put(s, config.getStringList("commands."+s));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public HashMap<String, List<String>> getPermList() {
|
|
||||||
return permList;
|
|
||||||
}
|
|
||||||
public boolean addCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
this.permList.get(group).add(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(CommandWhitelistBungee.getPlugin().getDataFolder(), "config.yml"));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public boolean removeCommand(String command, String group) {
|
|
||||||
try {
|
|
||||||
this.permList.get(group).remove(command);
|
|
||||||
this.config.set("commands."+group, permList.get(group));
|
|
||||||
ConfigurationProvider.getProvider(YamlConfiguration.class).save(config, new File(CommandWhitelistBungee.getPlugin().getDataFolder(), "config.yml"));
|
|
||||||
return true;
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public String getPrefix() {return prefix;}
|
|
||||||
public String getCommandDenied() {return commandDenied;}
|
|
||||||
public List<String> getCommandDeniedList() {
|
|
||||||
return commandDeniedList;
|
|
||||||
}
|
|
||||||
public String getNoPermission() {return noPermission;}
|
|
||||||
public String getNoSubCommand() {return noSubCommand;}
|
|
||||||
public String getConfigReloaded() {return configReloaded;}
|
|
||||||
public String getWhitelistedCommand() {
|
|
||||||
return whitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getRemovedWhitelistedCommand() {
|
|
||||||
return removedWhitelistedCommand;
|
|
||||||
}
|
|
||||||
public String getNoSuchGroup() {
|
|
||||||
return noSuchGroup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-47
@@ -1,47 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.bungee.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import eu.endermite.commandwhitelist.bungee.config.BungeeConfigCache;
|
|
||||||
import net.md_5.bungee.api.ChatColor;
|
|
||||||
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.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
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("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
String command = event.getMessage().toLowerCase();
|
|
||||||
boolean found = false;
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase("/" + comm)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
} else if (command.startsWith("/" + comm + " ")) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
BungeeConfigCache config = CommandWhitelistBungee.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelistBungee.getConfigCache().getPrefix() + config.getCommandDenied()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.common;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class CommandsList {
|
|
||||||
|
|
||||||
public static List<String> getCommands(org.bukkit.entity.Player player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, CWGroup> s : CommandWhitelist.getConfigCache().getGroupList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue().getCommands());
|
|
||||||
else if (player.hasPermission("commandwhitelist.group." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue().getCommands());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getCommands(net.md_5.bungee.api.connection.ProxiedPlayer player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistBungee.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
else if (player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getCommands(com.velocitypowered.api.proxy.Player player) {
|
|
||||||
List<String> commandList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, List<String>> s : CommandWhitelistVelocity.getConfigCache().getPermList().entrySet()) {
|
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
else if (player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
commandList.addAll(s.getValue());
|
|
||||||
}
|
|
||||||
return commandList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static List<String> getSuggestions(org.bukkit.entity.Player player) {
|
|
||||||
List<String> suggestionList = new ArrayList<>();
|
|
||||||
for (Map.Entry<String, CWGroup> s : CommandWhitelist.getConfigCache().getGroupList().entrySet()) {
|
|
||||||
if (player.hasPermission("commandwhitelist.subcommands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
suggestionList.addAll(s.getValue().getSubCommands());
|
|
||||||
}
|
|
||||||
return suggestionList;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getLastArgument(String cmd) {
|
|
||||||
String[] parts = cmd.split(" ");
|
|
||||||
if (parts.length <= 1)
|
|
||||||
return "";
|
|
||||||
String last = "";
|
|
||||||
for (String part : parts) {
|
|
||||||
last = part;
|
|
||||||
}
|
|
||||||
return last;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.command.MainCommand;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.listeners.*;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.metrics.BukkitMetrics;
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class CommandWhitelist extends JavaPlugin {
|
|
||||||
|
|
||||||
private static CommandWhitelist commandWhitelist;
|
|
||||||
private static ConfigCache configCache;
|
|
||||||
private static boolean isLegacy;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEnable() {
|
|
||||||
|
|
||||||
commandWhitelist = 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 {
|
|
||||||
PacketCommandSendListener.protocol(this);
|
|
||||||
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
|
||||||
}
|
|
||||||
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
|
||||||
|
|
||||||
|
|
||||||
getCommand("commandwhitelist").setExecutor(new MainCommand());
|
|
||||||
|
|
||||||
int pluginId = 8705;
|
|
||||||
new BukkitMetrics(this, pluginId);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadPluginConfig() {
|
|
||||||
File configFile = new File("plugins/CommandWhitelist/config.yml");
|
|
||||||
configCache = new ConfigCache(configFile, true);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void reloadPluginConfig(CommandSender sender) {
|
|
||||||
getServer().getScheduler().runTaskAsynchronously(this, () -> {
|
|
||||||
reloadPluginConfig();
|
|
||||||
for (Player p : Bukkit.getOnlinePlayers()) {
|
|
||||||
p.updateCommands();
|
|
||||||
}
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().prefix + CommandWhitelist.getConfigCache().config_reloaded));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static CommandWhitelist getPlugin() {
|
|
||||||
return commandWhitelist;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ConfigCache getConfigCache() {
|
|
||||||
return configCache;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.command;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.command.Command;
|
|
||||||
import org.bukkit.command.CommandExecutor;
|
|
||||||
import org.bukkit.command.CommandSender;
|
|
||||||
|
|
||||||
|
|
||||||
public class MainCommand implements CommandExecutor {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
||||||
if (args.length > 0) {
|
|
||||||
if (args[0].equalsIgnoreCase("reload")) {
|
|
||||||
if (!sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().prefix + CommandWhitelist.getConfigCache().no_permission));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
CommandWhitelist.getPlugin().reloadPluginConfig(sender);
|
|
||||||
|
|
||||||
} else if (args[0].equalsIgnoreCase("add")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().prefix + CommandWhitelist.getConfigCache().no_permission));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/cw add <group> <command>");
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (args[0].equalsIgnoreCase("remove")) {
|
|
||||||
|
|
||||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().prefix + CommandWhitelist.getConfigCache().no_permission));
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (args.length >= 3) {
|
|
||||||
|
|
||||||
} else {
|
|
||||||
sender.sendMessage("/cw remove <group> <command>");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', CommandWhitelist.getConfigCache().prefix + CommandWhitelist.getConfigCache().no_such_subcommand));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&bCommand Whitelist by YouHaveTrouble"));
|
|
||||||
if (sender.hasPermission("commandwhitelist.reload")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw reload &b- Reload plugin configuration"));
|
|
||||||
}
|
|
||||||
if (sender.hasPermission("commandwhitelist.admin")) {
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw add <group> <command> &b- Add command to group"));
|
|
||||||
sender.sendMessage(ChatColor.translateAlternateColorCodes('&', "&9/cw remove <group> <command> &b- Remove command from a group"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
-55
@@ -1,55 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
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.common.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class LegacyPlayerTabChatCompleteListener {
|
|
||||||
|
|
||||||
public static void protocol(CommandWhitelist plugin) {
|
|
||||||
ProtocolManager protocolManager = ProtocolLibrary.getProtocolManager();
|
|
||||||
tabCompleteServerBound(protocolManager, plugin);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void tabCompleteServerBound(ProtocolManager protocolManager, Plugin plugin) {
|
|
||||||
protocolManager.addPacketListener(new PacketAdapter(plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.TAB_COMPLETE) {
|
|
||||||
@Override
|
|
||||||
public void onPacketSending(PacketEvent event) {
|
|
||||||
try {
|
|
||||||
Player player = event.getPlayer();
|
|
||||||
if (player.hasPermission("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
PacketContainer packet = event.getPacket();
|
|
||||||
String[] message = packet.getSpecificModifier(String[].class).read(0);
|
|
||||||
List<String> commandList = CommandsList.getCommands(player);
|
|
||||||
List<String> finalList = new ArrayList<>();
|
|
||||||
int components = 0;
|
|
||||||
for (String cmd : message) {
|
|
||||||
for (String cmdFromList : commandList) {
|
|
||||||
if (cmd.equalsIgnoreCase("/" + cmdFromList) || !cmd.startsWith("/")) {
|
|
||||||
finalList.add(components++, cmd);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String[] toWrite = new String[components];
|
|
||||||
int counter = 0;
|
|
||||||
for (String cmd : finalList) {
|
|
||||||
toWrite[counter++] = cmd;
|
|
||||||
}
|
|
||||||
packet.getSpecificModifier(String[].class).write(0, toWrite);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-68
@@ -1,68 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
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.common.CWGroup;
|
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.plugin.Plugin;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class PacketCommandSendListener {
|
|
||||||
|
|
||||||
public static void protocol(CommandWhitelist 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("commandwhitelist.bypass"))
|
|
||||||
return;
|
|
||||||
String cmd = string.replace("/", "");
|
|
||||||
String[] split = cmd.split("\\s+");
|
|
||||||
String command = split[0].toLowerCase();
|
|
||||||
for (Map.Entry<String, CWGroup> s : CommandWhitelist.getConfigCache().getGroupList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue().getCommands()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase(comm) || command.startsWith(comm + " ")) {
|
|
||||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
|
||||||
if (cmd.startsWith(bannedSubCommand)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.prefix + config.subcommand_denied));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.prefix + config.command_denied));
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-46
@@ -1,46 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
|
||||||
import eu.endermite.commandwhitelist.spigot.CommandWhitelist;
|
|
||||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
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 command = event.getMessage().toLowerCase();
|
|
||||||
for (Map.Entry<String, CWGroup> s : CommandWhitelist.getConfigCache().getGroupList().entrySet()) {
|
|
||||||
if (!player.hasPermission("commandwhitelist.commands." + s.getKey()))
|
|
||||||
continue;
|
|
||||||
for (String comm : s.getValue().getCommands()) {
|
|
||||||
comm = comm.toLowerCase();
|
|
||||||
if (command.equalsIgnoreCase("/" + comm) || command.startsWith("/" + comm + " ")) {
|
|
||||||
String rawCmd = event.getMessage();
|
|
||||||
List<String> bannedSubCommands = CommandsList.getSuggestions(player);
|
|
||||||
for (String bannedSubCommand : bannedSubCommands) {
|
|
||||||
if (rawCmd.startsWith("/"+bannedSubCommand)) {
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.prefix + config.subcommand_denied));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setCancelled(true);
|
|
||||||
ConfigCache config = CommandWhitelist.getConfigCache();
|
|
||||||
player.sendMessage(ChatColor.translateAlternateColorCodes('&', config.prefix + config.command_denied));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
package eu.endermite.commandwhitelist.spigot.listeners;
|
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.common.CommandsList;
|
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
import org.bukkit.event.EventHandler;
|
|
||||||
import org.bukkit.event.EventPriority;
|
|
||||||
import org.bukkit.event.Listener;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TabCompleteBlockerListener implements Listener {
|
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
|
||||||
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
|
||||||
if (!(event.getSender() instanceof Player))
|
|
||||||
return;
|
|
||||||
Player player = (Player) event.getSender();
|
|
||||||
String buffer = event.getBuffer();
|
|
||||||
String cmd = buffer.replace(CommandsList.getLastArgument(buffer), "");
|
|
||||||
List<String> blockedCommands = CommandsList.getSuggestions(player);
|
|
||||||
List<String> suggestions = event.getCompletions();
|
|
||||||
for (String s : blockedCommands) {
|
|
||||||
String slast = CommandsList.getLastArgument(s);
|
|
||||||
String scommand = s.replace(slast, "");
|
|
||||||
cmd = cmd.replace(CommandsList.getLastArgument(cmd), "");
|
|
||||||
if (cmd.startsWith("/" + scommand)) {
|
|
||||||
try {
|
|
||||||
while (suggestions.contains(slast))
|
|
||||||
suggestions.remove(slast);
|
|
||||||
} catch (Exception ignored) {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
event.setCompletions(suggestions);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
name: CommandWhitelistBungee
|
|
||||||
version: ${project.version}
|
|
||||||
main: eu.endermite.commandwhitelist.bungee.CommandWhitelistBungee
|
|
||||||
author: YouHaveTrouble
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
# This is bungeecord version of the config.
|
|
||||||
messages:
|
|
||||||
prefix: "CommandWhitelist > "
|
|
||||||
command-denied: "No such command."
|
|
||||||
no-permission: "&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand: "&cNo subcommand by that name."
|
|
||||||
config-reloaded: "&eConfiguration reloaded."
|
|
||||||
added-to-whitelist: "&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
commands:
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default:
|
|
||||||
- glist
|
|
||||||
- server
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example:
|
|
||||||
- example
|
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
# This is velocity version of the config.
|
|
||||||
[messages]
|
|
||||||
prefix="CommandWhitelist > "
|
|
||||||
command-denied="No such command."
|
|
||||||
subcommand-denied="You cannot use this subcommand"
|
|
||||||
no-permission="&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand="&cNo subcommand by that name."
|
|
||||||
config-reloaded="&eConfiguration reloaded."
|
|
||||||
added-to-whitelist="&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist="&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist="&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
[commands]
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default= [
|
|
||||||
"velocity",
|
|
||||||
"server",
|
|
||||||
]
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example= [
|
|
||||||
"example"
|
|
||||||
]
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
messages:
|
|
||||||
prefix: "CommandWhitelist > "
|
|
||||||
command-denied: "No such command."
|
|
||||||
subcommand-denied: "You cannot use this subcommand"
|
|
||||||
no-permission: "&cYou don't have permission to do this."
|
|
||||||
no-such-subcommand: "&cNo subcommand by that name."
|
|
||||||
config-reloaded: "&eConfiguration reloaded."
|
|
||||||
added-to-whitelist: "&eWhitelisted command &6%s &efor permission &6%s"
|
|
||||||
removed-from-whitelist: "&eRemoved command &6%s &efrom permission &6%s"
|
|
||||||
group-doesnt-exist: "&cGroup doesn't exist or error occured"
|
|
||||||
|
|
||||||
# To cover the 1% of plugins that don't register their commands and/or aliases properly.
|
|
||||||
# Do not enable if you don't have issues with aliased commands.
|
|
||||||
# This requires server restart to take effect.
|
|
||||||
use-protocollib-to-detect-commands: false
|
|
||||||
|
|
||||||
commands:
|
|
||||||
# Permissions that control what commands players can use
|
|
||||||
# you can add unlimited amount of whitelists
|
|
||||||
|
|
||||||
# this will be automatically given to players by default
|
|
||||||
default:
|
|
||||||
- help
|
|
||||||
- spawn
|
|
||||||
- bal
|
|
||||||
- balance
|
|
||||||
- baltop
|
|
||||||
- pay
|
|
||||||
- r
|
|
||||||
- msg
|
|
||||||
- tpa
|
|
||||||
- tpahere
|
|
||||||
- tpaccept
|
|
||||||
- tpdeny
|
|
||||||
- warp
|
|
||||||
# commandwhitelist.commands.example
|
|
||||||
example:
|
|
||||||
- example
|
|
||||||
|
|
||||||
tabcompletions:
|
|
||||||
# This one is working as a blacklist. Player will not be able
|
|
||||||
# to see/use listed subcommands unless they have specified permission
|
|
||||||
# commandwhitelist.subcommands.example
|
|
||||||
example:
|
|
||||||
- help about
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
name: CommandWhitelist
|
|
||||||
prefix: CommandWhitelist
|
|
||||||
version: ${project.version}
|
|
||||||
api-version: 1.13
|
|
||||||
main: eu.endermite.commandwhitelist.spigot.CommandWhitelist
|
|
||||||
authors: [YouHaveTrouble]
|
|
||||||
softdepend:
|
|
||||||
- ProtocolLib
|
|
||||||
description: Control what commands players can use
|
|
||||||
commands:
|
|
||||||
commandwhitelist:
|
|
||||||
aliases:
|
|
||||||
- cw
|
|
||||||
usage: /commandwhitelist [args]
|
|
||||||
permissions:
|
|
||||||
commandwhitelist.reload:
|
|
||||||
default: op
|
|
||||||
commandwhitelist.admin:
|
|
||||||
default: op
|
|
||||||
commandwhitelist.bypass:
|
|
||||||
default: op
|
|
||||||
Reference in New Issue
Block a user