mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-11 22:16:57 +00:00
made perms enum
added some missing stuff
This commit is contained in:
+2
-1
@@ -6,6 +6,7 @@ import eu.endermite.commandwhitelist.bukkit.listeners.PlayerCommandPreProcessLis
|
||||
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.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -114,7 +115,7 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
||||
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;
|
||||
|
||||
+12
-73
@@ -1,11 +1,12 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.command;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@@ -22,7 +23,7 @@ public class MainCommandExecutor implements TabExecutor {
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.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 true;
|
||||
}
|
||||
|
||||
@@ -30,14 +31,14 @@ public class MainCommandExecutor 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(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||
return true;
|
||||
}
|
||||
CommandWhitelistBukkit.getPlugin().reloadPluginConfig(sender);
|
||||
return true;
|
||||
case ADD:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||
return true;
|
||||
}
|
||||
@@ -50,7 +51,7 @@ public class MainCommandExecutor implements TabExecutor {
|
||||
audiences.sender(sender).sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||
return true;
|
||||
case REMOVE:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
audiences.sender(sender).sendMessage(MiniMessage.markdown().parse(CommandWhitelistBukkit.getConfigCache().prefix + CommandWhitelistBukkit.getConfigCache().no_permission));
|
||||
return true;
|
||||
}
|
||||
@@ -64,82 +65,20 @@ public class MainCommandExecutor implements TabExecutor {
|
||||
return true;
|
||||
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 true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
|
||||
List<String> list = new ArrayList<>();
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
if (args.length == 1) {
|
||||
if ("reload".startsWith(args[0]) && sender.hasPermission("commandwhitelist.reload")) {
|
||||
list.add("reload");
|
||||
List<String> serverCommands = new ArrayList<>();
|
||||
for (HelpTopic topic : Bukkit.getHelpMap().getHelpTopics()) {
|
||||
serverCommands.add(topic.getName());
|
||||
}
|
||||
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 (String s : config.getGroupList().keySet()) {
|
||||
if (s.startsWith(args[1])) {
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (args.length == 3) {
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (!sender.hasPermission("commandwhitelist.admin"))
|
||||
return list;
|
||||
try {
|
||||
for (String s : config.getGroupList().get(args[1]).getCommands()) {
|
||||
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 (HelpTopic s : CommandWhitelistBukkit.getPlugin().getServer().getHelpMap().getHelpTopics()) {
|
||||
String cmd = s.getName();
|
||||
if (!cmd.startsWith("/"))
|
||||
continue;
|
||||
try {
|
||||
if (cmd.contains(":")) {
|
||||
cmd = cmd.split(":")[1];
|
||||
}
|
||||
} catch (Exception e) {
|
||||
continue;
|
||||
}
|
||||
cmd = cmd.replace("/", "");
|
||||
|
||||
if (config.getGroupList().get(args[1]) == null)
|
||||
continue;
|
||||
|
||||
if (config.getGroupList().get(args[1]).getCommands().contains(cmd))
|
||||
continue;
|
||||
|
||||
if (cmd.startsWith(args[2])) {
|
||||
list.add(cmd);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
return CWCommand.commandSuggestions(CommandWhitelistBukkit.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission()));
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -8,6 +8,7 @@ import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
@@ -31,13 +32,13 @@ public class PacketCommandPreProcessListener {
|
||||
String string = packet.getStrings().read(0);
|
||||
if (!string.startsWith("/")) return;
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
String label = CommandUtil.getCommandLabel(string.toLowerCase());
|
||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||
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;
|
||||
}
|
||||
@@ -46,7 +47,6 @@ public class PacketCommandPreProcessListener {
|
||||
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;
|
||||
}
|
||||
|
||||
+1
-3
@@ -18,13 +18,12 @@ public class PlayerCommandPreProcessListener implements Listener {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
String label = CommandUtil.getCommandLabel(event.getMessage().toLowerCase());
|
||||
|
||||
BukkitAudiences audiences = CommandWhitelistBukkit.getAudiences();
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
|
||||
HashSet<String> commands = CommandWhitelistBukkit.getCommands(player);
|
||||
if (!commands.contains(label)) {
|
||||
event.setCancelled(true);
|
||||
ConfigCache config = CommandWhitelistBukkit.getConfigCache();
|
||||
audiences.player(player).sendMessage(MiniMessage.markdown().parse(config.prefix + config.command_denied));
|
||||
return;
|
||||
}
|
||||
@@ -33,7 +32,6 @@ public class PlayerCommandPreProcessListener implements Listener {
|
||||
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;
|
||||
}
|
||||
|
||||
+2
-1
@@ -1,6 +1,7 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
@@ -12,7 +13,7 @@ public class PlayerCommandSendListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void PlayerCommandSendEvent(org.bukkit.event.player.PlayerCommandSendEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
HashSet<String> commandList = CommandWhitelistBukkit.getCommands(player);
|
||||
event.getCommands().removeIf((cmd) -> !commandList.contains(cmd));
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,6 +1,7 @@
|
||||
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||
|
||||
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
@@ -8,10 +9,11 @@ import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
|
||||
public class TabCompleteBlockerListener implements Listener {
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onCommandTabComplete(org.bukkit.event.server.TabCompleteEvent event) {
|
||||
if (!(event.getSender() instanceof Player)) return;
|
||||
Player player = (Player) event.getSender();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
event.setCompletions(
|
||||
CommandUtil.filterSuggestions(
|
||||
event.getBuffer(),
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
package eu.endermite.commandwhitelist.common;
|
||||
|
||||
public enum CWPermission {
|
||||
|
||||
ADMIN("commandwhitelist.admin"),
|
||||
RELOAD("commandwhitelist.reload"),
|
||||
BYPASS("commandwhitelist.bypass");
|
||||
|
||||
private final String permission;
|
||||
|
||||
CWPermission(String permission) {
|
||||
this.permission = permission;
|
||||
}
|
||||
|
||||
public String permission() {
|
||||
return permission;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows to check specific group permission
|
||||
* @param configCache
|
||||
* @param groupId
|
||||
* @return
|
||||
*/
|
||||
public static String getGroupPermission(ConfigCache configCache, String groupId) {
|
||||
if (configCache.getGroupList().containsKey(groupId))
|
||||
return configCache.getGroupList().get(groupId).getPermission();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+17
-12
@@ -15,15 +15,12 @@ public class CommandUtil {
|
||||
* @return Filtered list of suggestions
|
||||
*/
|
||||
public static List<String> filterSuggestions(String buffer, Collection<String> suggestions, Collection<String> blockedSubCommands) {
|
||||
if (buffer.startsWith("/"))
|
||||
buffer = buffer.substring(1);
|
||||
for (String s : blockedSubCommands) {
|
||||
String slast = getLastArgument(s);
|
||||
String scommand = s.replace(slast, "");
|
||||
String[] cmdSplit = buffer.split(" ");
|
||||
StringBuilder cmdBuilder = new StringBuilder();
|
||||
for (int i = 0; i <= cmdSplit.length - 1; i++)
|
||||
cmdBuilder.append(cmdSplit[i]).append(" ");
|
||||
String cmd = cmdBuilder.toString();
|
||||
if (cmd.startsWith("/" + scommand)) {
|
||||
String scommand = cutLastArgument(s);
|
||||
if (buffer.startsWith(scommand)) {
|
||||
while (suggestions.contains(slast))
|
||||
suggestions.remove(slast);
|
||||
}
|
||||
@@ -37,12 +34,20 @@ public class CommandUtil {
|
||||
*/
|
||||
public static String getLastArgument(String cmd) {
|
||||
String[] parts = cmd.split(" ");
|
||||
if (parts.length <= 1) return "";
|
||||
String last = "";
|
||||
for (String part : parts) {
|
||||
last = part;
|
||||
if (parts.length == 0) return "";
|
||||
return parts[parts.length - 1];
|
||||
}
|
||||
return last;
|
||||
|
||||
/**
|
||||
* @param cmd The command
|
||||
* @return Command without the last argument.
|
||||
*/
|
||||
public static String cutLastArgument(String cmd) {
|
||||
String[] cmdSplit = cmd.split(" ");
|
||||
StringBuilder cmdBuilder = new StringBuilder();
|
||||
for (int i = 0; i <= cmdSplit.length - 2; i++)
|
||||
cmdBuilder.append(cmdSplit[i]).append(" ");
|
||||
return cmdBuilder.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+57
@@ -8,6 +8,10 @@ import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class CWCommand {
|
||||
|
||||
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||
@@ -50,4 +54,57 @@ public class CWCommand {
|
||||
ADD, REMOVE, HELP, RELOAD
|
||||
}
|
||||
|
||||
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
|
||||
List<String> list = new ArrayList<>();
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if ("reload".startsWith(args[0]) && reloadPerm)
|
||||
list.add("reload");
|
||||
if ("add".startsWith(args[0]) && adminPerm)
|
||||
list.add("add");
|
||||
if ("remove".startsWith(args[0]) && adminPerm)
|
||||
list.add("remove");
|
||||
return list;
|
||||
case 2:
|
||||
if (args[0].equalsIgnoreCase("add") || args[0].equalsIgnoreCase("remove")) {
|
||||
if (!adminPerm) return list;
|
||||
for (String s : config.getGroupList().keySet()) {
|
||||
if (s.startsWith(args[1]))
|
||||
list.add(s);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
case 3:
|
||||
if (args[0].equalsIgnoreCase("remove")) {
|
||||
if (!adminPerm) return list;
|
||||
try {
|
||||
for (String s : config.getGroupList().get(args[1]).getCommands()) {
|
||||
if (s.startsWith(args[2]))
|
||||
list.add(s);
|
||||
}
|
||||
} catch (NullPointerException ignored) {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
if (args[0].equalsIgnoreCase("add")) {
|
||||
if (!adminPerm) return list;
|
||||
for (String cmd : serverCommands) {
|
||||
if (!cmd.startsWith("/")) continue;
|
||||
if (cmd.contains(":")) {
|
||||
String[] cmdSplit = cmd.split(":");
|
||||
if (cmdSplit.length < 2) continue;
|
||||
cmd = cmd.split(":")[1];
|
||||
}
|
||||
cmd = cmd.replace("/", "");
|
||||
if (config.getGroupList().get(args[1]) == null) continue;
|
||||
if (config.getGroupList().get(args[1]).getCommands().contains(cmd)) continue;
|
||||
if (cmd.startsWith(args[2]))
|
||||
list.add(cmd);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -10,6 +10,7 @@ import com.velocitypowered.api.plugin.annotation.DataDirectory;
|
||||
import com.velocitypowered.api.proxy.Player;
|
||||
import com.velocitypowered.api.proxy.ProxyServer;
|
||||
import eu.endermite.commandwhitelist.common.CWGroup;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||
import eu.endermite.commandwhitelist.velocity.command.VelocityMainCommand;
|
||||
import net.kyori.adventure.identity.Identity;
|
||||
@@ -71,7 +72,7 @@ public class CommandWhitelistVelocity {
|
||||
@Subscribe
|
||||
public void onUserCommandSendEvent(PlayerAvailableCommandsEvent event) {
|
||||
Player player = event.getPlayer();
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
event.getRootNode().getChildren().removeIf((commandNode) ->
|
||||
server.getCommandManager().hasCommand(commandNode.getName())
|
||||
@@ -84,7 +85,7 @@ public class CommandWhitelistVelocity {
|
||||
if (!(event.getCommandSource() instanceof Player)) return;
|
||||
Player player = (Player) event.getCommandSource();
|
||||
|
||||
if (player.hasPermission("commandwhitelist.bypass")) return;
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
|
||||
HashSet<String> allowedCommands = CommandWhitelistVelocity.getCommands(player);
|
||||
String command = event.getCommand().split(" ")[0];
|
||||
@@ -122,8 +123,7 @@ public class CommandWhitelistVelocity {
|
||||
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;
|
||||
|
||||
+8
-7
@@ -2,6 +2,7 @@ package eu.endermite.commandwhitelist.velocity.command;
|
||||
|
||||
import com.velocitypowered.api.command.CommandSource;
|
||||
import com.velocitypowered.api.command.SimpleCommand;
|
||||
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||
import eu.endermite.commandwhitelist.common.commands.CWCommand;
|
||||
import eu.endermite.commandwhitelist.velocity.CommandWhitelistVelocity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@@ -20,7 +21,7 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
String label = invocation.alias();
|
||||
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -28,14 +29,14 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||
switch (commandType) {
|
||||
case RELOAD:
|
||||
if (!sender.hasPermission("commandwhitelist.reload")) {
|
||||
if (!sender.hasPermission(CWPermission.RELOAD.permission())) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
CommandWhitelistVelocity.reloadConfig(sender);
|
||||
return;
|
||||
case ADD:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
@@ -48,7 +49,7 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
sender.sendMessage(Component.text("/"+label+" add <group> <command>"));
|
||||
return;
|
||||
case REMOVE:
|
||||
if (!sender.hasPermission("commandwhitelist.admin")) {
|
||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().no_permission));
|
||||
return;
|
||||
}
|
||||
@@ -62,11 +63,11 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
return;
|
||||
case HELP:
|
||||
default:
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission("commandwhitelist.reload"), sender.hasPermission("commandwhitelist.admin")));
|
||||
sender.sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||
}
|
||||
return;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class VelocityMainCommand implements SimpleCommand {
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
List<String> suggestions = new ArrayList<>();
|
||||
if (args.length == 1) {
|
||||
if (source.hasPermission("commandwhitelist.reload") && "reload".startsWith(args[0]))
|
||||
if (source.hasPermission(CWPermission.RELOAD.permission()) && "reload".startsWith(args[0]))
|
||||
suggestions.add("reload");
|
||||
}
|
||||
return suggestions;
|
||||
|
||||
+4
-4
@@ -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;
|
||||
|
||||
+7
-6
@@ -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;
|
||||
}
|
||||
|
||||
+9
-9
@@ -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;
|
||||
|
||||
+27
@@ -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)
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+2
-1
@@ -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 ->
|
||||
|
||||
Reference in New Issue
Block a user