mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-05-12 06:26:57 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 097b541a1f | |||
| 5f447e07b6 | |||
| b5e12655f9 | |||
| 14f15aa754 | |||
| 017011fad0 |
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-ALPHA-2</version>
|
<version>2.0-ALPHA-3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Bukkit</artifactId>
|
<artifactId>Bukkit</artifactId>
|
||||||
|
|||||||
+8
-4
@@ -1,10 +1,7 @@
|
|||||||
package eu.endermite.commandwhitelist.bukkit;
|
package eu.endermite.commandwhitelist.bukkit;
|
||||||
|
|
||||||
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
import eu.endermite.commandwhitelist.bukkit.command.MainCommandExecutor;
|
||||||
import eu.endermite.commandwhitelist.bukkit.listeners.PacketCommandPreProcessListener;
|
import eu.endermite.commandwhitelist.bukkit.listeners.*;
|
||||||
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.CWGroup;
|
||||||
import eu.endermite.commandwhitelist.common.ConfigCache;
|
import eu.endermite.commandwhitelist.common.ConfigCache;
|
||||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||||
@@ -21,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class CommandWhitelistBukkit extends JavaPlugin {
|
public class CommandWhitelistBukkit extends JavaPlugin {
|
||||||
@@ -46,7 +44,13 @@ public class CommandWhitelistBukkit extends JavaPlugin {
|
|||||||
PacketCommandPreProcessListener.protocol(this);
|
PacketCommandPreProcessListener.protocol(this);
|
||||||
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
getLogger().info(ChatColor.AQUA + "Using ProtocolLib for command filter!");
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
// Use paper's async tab completions if possible
|
||||||
|
Class.forName("com.destroystokyo.paper.event.server.AsyncTabCompleteEvent");
|
||||||
|
getServer().getPluginManager().registerEvents(new AsyncTabCompleteBlockerListener(), this);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
getServer().getPluginManager().registerEvents(new TabCompleteBlockerListener(), this);
|
||||||
|
}
|
||||||
|
|
||||||
PluginCommand command = getCommand("commandwhitelist");
|
PluginCommand command = getCommand("commandwhitelist");
|
||||||
if (command != null) {
|
if (command != null) {
|
||||||
|
|||||||
-1
@@ -26,7 +26,6 @@ public class MainCommandExecutor implements TabExecutor {
|
|||||||
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
audiences.sender(sender).sendMessage(CWCommand.helpComponent(label, sender.hasPermission(CWPermission.RELOAD.permission()), sender.hasPermission(CWPermission.ADMIN.permission())));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
CWCommand.CommandType commandType = CWCommand.CommandType.valueOf(args[0].toUpperCase());
|
||||||
switch (commandType) {
|
switch (commandType) {
|
||||||
|
|||||||
+29
@@ -0,0 +1,29 @@
|
|||||||
|
package eu.endermite.commandwhitelist.bukkit.listeners;
|
||||||
|
|
||||||
|
import com.destroystokyo.paper.event.server.AsyncTabCompleteEvent;
|
||||||
|
import eu.endermite.commandwhitelist.bukkit.CommandWhitelistBukkit;
|
||||||
|
import eu.endermite.commandwhitelist.common.CWPermission;
|
||||||
|
import eu.endermite.commandwhitelist.common.CommandUtil;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.EventPriority;
|
||||||
|
import org.bukkit.event.Listener;
|
||||||
|
|
||||||
|
public class AsyncTabCompleteBlockerListener implements Listener {
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.NORMAL)
|
||||||
|
public void onCommandTabComplete(AsyncTabCompleteEvent 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(),
|
||||||
|
event.getCompletions(),
|
||||||
|
CommandWhitelistBukkit.getSuggestions(player)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
event.setHandled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-ALPHA-2</version>
|
<version>2.0-ALPHA-3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Common</artifactId>
|
<artifactId>Common</artifactId>
|
||||||
|
|||||||
+15
-15
@@ -16,8 +16,7 @@ public class CWCommand {
|
|||||||
|
|
||||||
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
public static boolean addToWhitelist(ConfigCache configCache, String command, String group) {
|
||||||
CWGroup cwGroup = configCache.getGroupList().get(group);
|
CWGroup cwGroup = configCache.getGroupList().get(group);
|
||||||
if (cwGroup == null)
|
if (cwGroup == null) return false;
|
||||||
return false;
|
|
||||||
cwGroup.addCommand(command);
|
cwGroup.addCommand(command);
|
||||||
configCache.saveCWGroup(group, cwGroup);
|
configCache.saveCWGroup(group, cwGroup);
|
||||||
return true;
|
return true;
|
||||||
@@ -36,16 +35,16 @@ public class CWCommand {
|
|||||||
Component component = MiniMessage.markdown().parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
|
Component component = MiniMessage.markdown().parse("<rainbow><bold>CommandWhitelist by YouHaveTrouble")
|
||||||
.append(Component.newline());
|
.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("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"))));
|
component = component.append(Component.text("/" + baseCommand + " help").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Displays this message"))));
|
||||||
if (showReloadCommand) {
|
if (showReloadCommand) {
|
||||||
component = component.append(Component.newline());
|
component = component.append(Component.newline());
|
||||||
component = component.append(Component.text("/"+baseCommand+" reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
|
component = component.append(Component.text("/" + baseCommand + " reload").color(NamedTextColor.AQUA).hoverEvent(HoverEvent.showText(Component.text("Reloads plugin configuration"))));
|
||||||
}
|
}
|
||||||
if (showAdminCommands) {
|
if (showAdminCommands) {
|
||||||
component = component.append(Component.newline());
|
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.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.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"))));
|
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;
|
return component;
|
||||||
}
|
}
|
||||||
@@ -57,6 +56,7 @@ public class CWCommand {
|
|||||||
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
|
public static List<String> commandSuggestions(ConfigCache config, Collection<String> serverCommands, String[] args, boolean reloadPerm, boolean adminPerm) {
|
||||||
List<String> list = new ArrayList<>();
|
List<String> list = new ArrayList<>();
|
||||||
switch (args.length) {
|
switch (args.length) {
|
||||||
|
case 0:
|
||||||
case 1:
|
case 1:
|
||||||
if ("reload".startsWith(args[0]) && reloadPerm)
|
if ("reload".startsWith(args[0]) && reloadPerm)
|
||||||
list.add("reload");
|
list.add("reload");
|
||||||
@@ -77,27 +77,27 @@ public class CWCommand {
|
|||||||
case 3:
|
case 3:
|
||||||
if (args[0].equalsIgnoreCase("remove")) {
|
if (args[0].equalsIgnoreCase("remove")) {
|
||||||
if (!adminPerm) return list;
|
if (!adminPerm) return list;
|
||||||
try {
|
CWGroup group = config.getGroupList().get(args[1]);
|
||||||
for (String s : config.getGroupList().get(args[1]).getCommands()) {
|
if (group == null) return list;
|
||||||
|
for (String s : group.getCommands()) {
|
||||||
if (s.startsWith(args[2]))
|
if (s.startsWith(args[2]))
|
||||||
list.add(s);
|
list.add(s);
|
||||||
}
|
}
|
||||||
} catch (NullPointerException ignored) {
|
|
||||||
}
|
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
if (args[0].equalsIgnoreCase("add")) {
|
if (args[0].equalsIgnoreCase("add")) {
|
||||||
if (!adminPerm) return list;
|
if (!adminPerm) return list;
|
||||||
|
CWGroup group = config.getGroupList().get(args[1]);
|
||||||
|
if (group == null) return list;
|
||||||
for (String cmd : serverCommands) {
|
for (String cmd : serverCommands) {
|
||||||
if (!cmd.startsWith("/")) continue;
|
if (cmd.startsWith("/"))
|
||||||
|
cmd = cmd.substring(1);
|
||||||
if (cmd.contains(":")) {
|
if (cmd.contains(":")) {
|
||||||
String[] cmdSplit = cmd.split(":");
|
String[] cmdSplit = cmd.split(":");
|
||||||
if (cmdSplit.length < 2) continue;
|
if (cmdSplit.length < 2) continue;
|
||||||
cmd = cmd.split(":")[1];
|
cmd = cmdSplit[1];
|
||||||
}
|
}
|
||||||
cmd = cmd.replace("/", "");
|
if (group.getCommands().contains(cmd)) continue;
|
||||||
if (config.getGroupList().get(args[1]) == null) continue;
|
|
||||||
if (config.getGroupList().get(args[1]).getCommands().contains(cmd)) continue;
|
|
||||||
if (cmd.startsWith(args[2]))
|
if (cmd.startsWith(args[2]))
|
||||||
list.add(cmd);
|
list.add(cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-ALPHA-2</version>
|
<version>2.0-ALPHA-3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Velocity</artifactId>
|
<artifactId>Velocity</artifactId>
|
||||||
@@ -82,7 +82,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.velocitypowered</groupId>
|
<groupId>com.velocitypowered</groupId>
|
||||||
<artifactId>velocity-api</artifactId>
|
<artifactId>velocity-api</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>3.0.0</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
+4
-3
@@ -105,10 +105,11 @@ public class CommandWhitelistVelocity {
|
|||||||
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
HashMap<String, CWGroup> groups = configCache.getGroupList();
|
||||||
HashSet<String> commandList = new HashSet<>();
|
HashSet<String> commandList = new HashSet<>();
|
||||||
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
for (Map.Entry<String, CWGroup> s : groups.entrySet()) {
|
||||||
|
CWGroup group = s.getValue();
|
||||||
if (s.getKey().equalsIgnoreCase("default"))
|
if (s.getKey().equalsIgnoreCase("default"))
|
||||||
commandList.addAll(s.getValue().getCommands());
|
commandList.addAll(group.getCommands());
|
||||||
else if (player.hasPermission(s.getValue().getPermission()))
|
else if (player.hasPermission(group.getPermission()))
|
||||||
commandList.addAll(s.getValue().getCommands());
|
commandList.addAll(group.getCommands());
|
||||||
}
|
}
|
||||||
return commandList;
|
return commandList;
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-12
@@ -42,11 +42,11 @@ public class VelocityMainCommand implements SimpleCommand {
|
|||||||
}
|
}
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
if (CWCommand.addToWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist));
|
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().added_to_whitelist, args[2], args[1])));
|
||||||
else
|
else
|
||||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
|
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
} else
|
} else
|
||||||
sender.sendMessage(Component.text("/"+label+" add <group> <command>"));
|
sender.sendMessage(Component.text("/" + label + " add <group> <command>"));
|
||||||
return;
|
return;
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
if (!sender.hasPermission(CWPermission.ADMIN.permission())) {
|
||||||
@@ -55,11 +55,11 @@ public class VelocityMainCommand implements SimpleCommand {
|
|||||||
}
|
}
|
||||||
if (args.length == 3) {
|
if (args.length == 3) {
|
||||||
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
if (CWCommand.removeFromWhitelist(CommandWhitelistVelocity.getConfigCache(), args[2], args[1]))
|
||||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist));
|
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().removed_from_whitelist, args[2], args[1])));
|
||||||
else
|
else
|
||||||
sender.sendMessage(MiniMessage.markdown().parse(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist));
|
sender.sendMessage(MiniMessage.markdown().parse(String.format(CommandWhitelistVelocity.getConfigCache().prefix + CommandWhitelistVelocity.getConfigCache().group_doesnt_exist, args[1])));
|
||||||
} else
|
} else
|
||||||
sender.sendMessage(Component.text("/"+label+" remove <group> <command>"));
|
sender.sendMessage(Component.text("/" + label + " remove <group> <command>"));
|
||||||
return;
|
return;
|
||||||
case HELP:
|
case HELP:
|
||||||
default:
|
default:
|
||||||
@@ -77,12 +77,8 @@ public class VelocityMainCommand implements SimpleCommand {
|
|||||||
CommandSource source = invocation.source();
|
CommandSource source = invocation.source();
|
||||||
String[] args = invocation.arguments();
|
String[] args = invocation.arguments();
|
||||||
return CompletableFuture.supplyAsync(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
List<String> suggestions = new ArrayList<>();
|
List<String> serverCommands = new ArrayList<>();
|
||||||
if (args.length == 1) {
|
return CWCommand.commandSuggestions(CommandWhitelistVelocity.getConfigCache(), serverCommands, args, source.hasPermission(CWPermission.RELOAD.permission()), source.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
if (source.hasPermission(CWPermission.RELOAD.permission()) && "reload".startsWith(args[0]))
|
|
||||||
suggestions.add("reload");
|
|
||||||
}
|
|
||||||
return suggestions;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-ALPHA-2</version>
|
<version>2.0-ALPHA-3</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<artifactId>Waterfall</artifactId>
|
<artifactId>Waterfall</artifactId>
|
||||||
|
|||||||
+9
-1
@@ -11,6 +11,10 @@ import net.md_5.bungee.api.CommandSender;
|
|||||||
import net.md_5.bungee.api.plugin.Command;
|
import net.md_5.bungee.api.plugin.Command;
|
||||||
import net.md_5.bungee.api.plugin.TabExecutor;
|
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 class BungeeMainCommand extends Command implements TabExecutor {
|
||||||
|
|
||||||
public BungeeMainCommand(String name) {
|
public BungeeMainCommand(String name) {
|
||||||
@@ -77,6 +81,10 @@ public class BungeeMainCommand extends Command implements TabExecutor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
public Iterable<String> onTabComplete(CommandSender sender, String[] args) {
|
||||||
return null;
|
List<String> serverCommands = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Command> command : CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().getCommands()) {
|
||||||
|
serverCommands.add(command.getValue().getName());
|
||||||
|
}
|
||||||
|
return CWCommand.commandSuggestions(CommandWhitelistWaterfall.getConfigCache(), serverCommands, args, sender.hasPermission(CWPermission.RELOAD.permission()),sender.hasPermission(CWPermission.ADMIN.permission()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>eu.endermite.commandwhitelist</groupId>
|
<groupId>eu.endermite.commandwhitelist</groupId>
|
||||||
<artifactId>CommandWhitelist</artifactId>
|
<artifactId>CommandWhitelist</artifactId>
|
||||||
<version>2.0-ALPHA-2</version>
|
<version>2.0-ALPHA-3</version>
|
||||||
<modules>
|
<modules>
|
||||||
<module>CommandWhitelistCommon</module>
|
<module>CommandWhitelistCommon</module>
|
||||||
<module>CommandWhitelistBukkit</module>
|
<module>CommandWhitelistBukkit</module>
|
||||||
|
|||||||
Reference in New Issue
Block a user