Skip to content

Commit

Permalink
only allow using link/unlink/link info commands
Browse files Browse the repository at this point in the history
  • Loading branch information
onebeastchris committed Jan 17, 2025
1 parent e272a97 commit becd093
Showing 1 changed file with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> permittedCommands;

public final static Component LINK_INSTRUCTIONS = Component.text("Run the ").color(NamedTextColor.AQUA)
.append(Component.text("`/link`", NamedTextColor.GREEN))
Expand Down Expand Up @@ -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<String> toRemove = new ArrayList<>();
Expand All @@ -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
Expand Down

0 comments on commit becd093

Please sign in to comment.