cleanup code

This commit is contained in:
kforbro
2021-10-26 12:52:40 +03:00
parent d43bde0750
commit cd3d527119
8 changed files with 27 additions and 21 deletions
@@ -1,7 +1,10 @@
package eu.endermite.commandwhitelist.bukkit;
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
import eu.endermite.commandwhitelist.bukkit.listeners.*;
import eu.endermite.commandwhitelist.bukkit.listeners.AsyncTabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandSendListener;
import eu.endermite.commandwhitelist.bukkit.listeners.TabCompleteBlockerListener;
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandPreProcessListener;
import eu.endermite.commandwhitelist.bukkit.listeners.protocollib.PacketCommandSendListener;
import eu.endermite.commandwhitelist.common.CWGroup;
@@ -20,7 +23,6 @@ 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 {
@@ -10,7 +10,7 @@ public class CWGroup {
public CWGroup(String id, Collection<String> commands, Collection<String> subCommands, String custom_command_denied_message) {
this.id = id;
this.permission = "commandwhitelist.group."+id;
this.permission = "commandwhitelist.group." + id;
this.commands.addAll(commands);
this.custom_command_denied_message = custom_command_denied_message;
this.subCommands.addAll(subCommands);
@@ -24,9 +24,13 @@ public class CWGroup {
return permission;
}
public HashSet<String> getCommands() { return commands; }
public HashSet<String> getCommands() {
return commands;
}
public String getCustomCommandDeniedMessage() { return custom_command_denied_message; }
public String getCustomCommandDeniedMessage() {
return custom_command_denied_message;
}
public void addCommand(String command) {
commands.add(command);
@@ -18,6 +18,7 @@ public enum CWPermission {
/**
* Allows to check specific group permission
*
* @param configCache
* @param groupId
* @return
@@ -55,7 +55,7 @@ public class CommandWhitelistVelocity {
public static void reloadConfig(CommandSource source) {
server.getScheduler().buildTask(plugin, () -> {
reloadConfig();
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix+getConfigCache().config_reloaded));
source.sendMessage(Identity.nil(), CWCommand.miniMessage.parse(getConfigCache().prefix + getConfigCache().config_reloaded));
}).schedule();
}
@@ -65,7 +65,7 @@ public class CommandWhitelistVelocity {
CommandMeta commandMeta = server.getCommandManager().metaBuilder("vcw").build();
server.getCommandManager().register(commandMeta, new VelocityMainCommand());
Metrics metrics = metricsFactory.make(this, 8704);
metrics.addCustomChart(new SimplePie("proxy", ()-> "Velocity"));
metrics.addCustomChart(new SimplePie("proxy", () -> "Velocity"));
}
@Subscribe
@@ -74,7 +74,7 @@ public class CommandWhitelistVelocity {
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
event.getRootNode().getChildren().removeIf((commandNode) ->
server.getCommandManager().hasCommand(commandNode.getName())
server.getCommandManager().hasCommand(commandNode.getName())
&& !allowedCommands.contains(commandNode.getName())
);
}
@@ -1,9 +1,9 @@
{
"id":"commandwhitelist",
"name":"CommandWhitelist",
"version":"${project.version}",
"description":"You decide what commands players can use or tab complete on your server!",
"authors":["YouHaveTrouble"],
"dependencies":[],
"main":"eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
"id": "commandwhitelist",
"name": "CommandWhitelist",
"version": "${project.version}",
"description": "You decide what commands players can use or tab complete on your server!",
"authors": ["YouHaveTrouble"],
"dependencies": [],
"main": "eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity"
}
@@ -8,7 +8,6 @@ import eu.endermite.commandwhitelist.waterfall.listeners.BungeeChatEventListener
import eu.endermite.commandwhitelist.waterfall.listeners.BungeeTabcompleteListener;
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.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;
@@ -30,7 +29,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
@Override
public void onEnable() {
plugin = this;
getLogger().info("Running on "+ ChatColor.DARK_AQUA+getProxy().getName());
getLogger().info("Running on " + ChatColor.DARK_AQUA + getProxy().getName());
loadConfig();
audiences = BungeeAudiences.create(this);
Metrics metrics = new Metrics(this, 8704);
@@ -53,6 +52,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
public static CommandWhitelistWaterfall getPlugin() {
return plugin;
}
public static ConfigCache getConfigCache() {
return configCache;
}
@@ -52,7 +52,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
} else
audiences.sender(sender).sendMessage(Component.text("/"+label+" add <group> <command>"));
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
return;
case REMOVE:
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
@@ -65,7 +65,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
else
audiences.sender(sender).sendMessage(CWCommand.miniMessage.parse(configCache.prefix + configCache.group_doesnt_exist));
} else
audiences.sender(sender).sendMessage(Component.text("/"+label+" remove <group> <command>"));
audiences.sender(sender).sendMessage(Component.text("/" + label + " remove <group> <command>"));
return;
case HELP:
default:
@@ -84,6 +84,6 @@ public class BungeeMainCommand extends Command implements TabExecutor {
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
serverCommands.add(command.getValue().getName());
}
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission()));
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()));
}
}
@@ -6,7 +6,6 @@ import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.text.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;