diff --git a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java index 0276cbf..f25fb24 100644 --- a/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java +++ b/src/main/java/org/geysermc/globallinkserver/GlobalLinkServer.java @@ -44,6 +44,7 @@ public class GlobalLinkServer extends JavaPlugin implements Listener { public static Logger LOGGER; public static LinkManager linkManager; public static Config config; + public static List permittedCommands; public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA) .append(Component.text("`/link`", NamedTextColor.GREEN)) @@ -135,7 +136,6 @@ public void onEnable() { LOGGER.info("Started Global Linking plugin!"); } - // TODO does not remove commands @EventHandler public void onCommands(PlayerCommandSendEvent event) { Collection toRemove = new ArrayList<>(); @@ -156,6 +156,23 @@ public void onCommands(PlayerCommandSendEvent event) { } event.getCommands().removeAll(toRemove); + permittedCommands = event.getCommands().stream().toList(); + } + + @EventHandler + public void preCommand(PlayerCommandPreprocessEvent event) { + if (event.getPlayer().isOp()) { + return; + } + + String command = event.getMessage(); + if (command.startsWith("/")) { + command = command.substring(1); + } + + if (!permittedCommands.contains(command)) { + event.setCancelled(true); + } } @EventHandler