made perms enum

added some missing stuff
This commit is contained in:
YouHaveTrouble
2021-07-06 14:48:44 +02:00
parent 55fdf0c076
commit fc26393dcf
16 changed files with 190 additions and 126 deletions
@@ -4,6 +4,7 @@ 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.BungeeTabcompleteListener;
import eu.endermite.commandwhitelist.waterfall.listeners.WaterfallDefineCommandsListener;
import net.kyori.adventure.platform.bungeecord.BungeeAudiences;
import net.kyori.adventure.text.minimessage.MiniMessage;
@@ -36,9 +37,9 @@ public final class CommandWhitelistWaterfall extends Plugin {
Class.forName("io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent");
this.getProxy().getPluginManager().registerListener(this, new WaterfallDefineCommandsListener());
} catch (ClassNotFoundException e) {
getLogger().severe(ChatColor.DARK_RED+"Bungee tab completion blocker requires Waterfall other Waterfall fork.");
getLogger().severe(ChatColor.DARK_RED+"Bungee command completion blocker requires Waterfall other Waterfall fork.");
}
this.getProxy().getPluginManager().registerListener(this, new BungeeTabcompleteListener());
getProxy().getPluginManager().registerCommand(this, new BungeeMainCommand("bcw"));
Metrics metrics = new Metrics(this, 8704);
@@ -96,8 +97,7 @@ public final class CommandWhitelistWaterfall extends Plugin {
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
if (s.getKey().equalsIgnoreCase("default"))
suggestionList.addAll(s.getValue().getSubCommands());
if (player.hasPermission("commandwhitelist.group." + s.getKey()))
continue;
if (player.hasPermission(s.getValue().getPermission())) continue;
suggestionList.addAll(s.getValue().getSubCommands());
}
return suggestionList;
@@ -1,5 +1,6 @@
package eu.endermite.commandwhitelist.waterfall.command;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.common.commands.CWCommand;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
@@ -23,7 +24,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
if (args.length == 0) {
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
return;
}
@@ -31,14 +32,14 @@ public class BungeeMainCommand extends Command implements TabExecutor {
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
switch (commandType) {
case RELOAD:
if (!sender.hasPermission("commandwhitelist.reload")) {
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistWaterfall.getConfigCache().prefix + configCache.no_permission));
return;
}
CommandWhitelistWaterfall.getPlugin().loadConfigAsync(sender);
return;
case ADD:
if (!sender.hasPermission("commandwhitelist.admin")) {
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.no_permission));
return;
}
@@ -51,7 +52,7 @@ public class BungeeMainCommand extends Command implements TabExecutor {
audiences.sender(sender).sendMessage(Component.text("/"+label+" add <group> <command>"));
return;
case REMOVE:
if (!sender.hasPermission("commandwhitelist.admin")) {
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.no_permission));
return;
}
@@ -65,11 +66,11 @@ public class BungeeMainCommand extends Command implements TabExecutor {
return;
case HELP:
default:
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
}
} catch (IllegalArgumentException e) {
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
}
return;
}
@@ -1,5 +1,6 @@
package eu.endermite.commandwhitelist.waterfall.listeners;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.common.ConfigCache;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
@@ -15,16 +16,15 @@ 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;
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;
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
String command = event.getMessage().toLowerCase();
if (command.startsWith("/"))
command = command.substring(1);
ConfigCache configCache = CommandWhitelistWaterfall.getConfigCache();
BungeeAudiences audiences = CommandWhitelistWaterfall.getAudiences();
@@ -38,7 +38,7 @@ public class BungeeChatEventListener implements Listener {
HashSet<String> bannedSubCommands = CommandWhitelistWaterfall.getSuggestions(player);
for (String bannedSubCommand : bannedSubCommands) {
if (command.toLowerCase().substring(1).startsWith(bannedSubCommand)) {
if (command.startsWith(bannedSubCommand)) {
event.setCancelled(true);
audiences.player(player).sendMessage(MiniMessage.markdown().parse(configCache.prefix + configCache.subcommand_denied));
return;
@@ -0,0 +1,27 @@
package eu.endermite.commandwhitelist.waterfall.listeners;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.common.CommandUtil;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler;
public class BungeeTabcompleteListener implements Listener {
@EventHandler
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
CommandUtil.filterSuggestions(
event.getCursor(),
event.getSuggestions(),
CommandWhitelistWaterfall.getSuggestions(player)
);
}
}
@@ -1,5 +1,6 @@
package eu.endermite.commandwhitelist.waterfall.listeners;
import eu.endermite.commandwhitelist.common.CWPermission;
import eu.endermite.commandwhitelist.waterfall.CommandWhitelistWaterfall;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;
@@ -14,7 +15,7 @@ public class WaterfallDefineCommandsListener implements Listener {
public void onProxyDefineCommandsEvent(io.github.waterfallmc.waterfall.event.ProxyDefineCommandsEvent event) {
if (event.getReceiver() instanceof ProxiedPlayer) {
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
if (player.hasPermission("commandwhitelist.bypass"))
if (player.hasPermission(CWPermission.BYPASS.permission()))
return;
HashMap<String, Command> commandHashMap = new HashMap<>();
CommandWhitelistWaterfall.getCommands(player).forEach(cmdName ->