11package me .petterim1 .hiddencommands ;
22
33import org .powernukkitx .event .EventHandler ;
4+ import org .powernukkitx .event .EventPriority ;
45import org .powernukkitx .event .Listener ;
6+ import org .powernukkitx .event .player .PlayerCommandPreprocessEvent ;
57import org .powernukkitx .event .server .PacketSendEvent ;
8+ import org .powernukkitx .lang .CommandOutputContainer ;
69import org .powernukkitx .plugin .PluginBase ;
710import org .cloudburstmc .protocol .bedrock .data .command .CommandData ;
811import org .cloudburstmc .protocol .bedrock .packet .AvailableCommandsPacket ;
12+ import org .powernukkitx .utils .TextFormat ;
913
1014import java .util .ArrayList ;
1115import java .util .List ;
1216
1317public class Main extends PluginBase implements Listener {
1418
1519 private boolean ignoreOPs ;
20+ private boolean block ;
1621 private List <String > hiddenCommands ;
1722
1823 public void onEnable () {
1924 saveDefaultConfig ();
2025 ignoreOPs = getConfig ().getBoolean ("ignoreOPs" );
21- hiddenCommands = getConfig ().getStringList ("hiddenCommands" );
26+ block = getConfig ().getBoolean ("blockCommands" , true );
27+ hiddenCommands = getConfig ().getStringList ("hiddenCommands" ).stream ().map (String ::toLowerCase ).toList ();
28+ if (hiddenCommands .stream ().anyMatch (string -> string .equals ("help" ))) {
29+ getLogger ().alert ("You cannot block /help." );
30+ }
2231 if (!hiddenCommands .isEmpty ()) {
2332 getServer ().getPluginManager ().registerEvents (this , this );
2433 }
@@ -39,4 +48,19 @@ public void onSendCommandData(PacketSendEvent e) {
3948 }
4049 }
4150 }
51+
52+ @ EventHandler (priority = EventPriority .LOW )
53+ public void onCommand (PlayerCommandPreprocessEvent event ) {
54+ if (ignoreOPs && event .getPlayer ().isOp ()) return ;
55+ if (block ) {
56+ String [] parts = event .getMessage ().split ("\\ s+" );
57+ if (parts .length >= 1 ) {
58+ String command = parts [0 ].replaceFirst ("/" , "" ).toLowerCase ();
59+ if (hiddenCommands .contains (command )) {
60+ event .setCancelled ();
61+ event .getPlayer ().sendCommandOutput (new CommandOutputContainer (TextFormat .RED + "%commands.generic.unknown" , new String []{command }, 0 ));
62+ }
63+ }
64+ }
65+ }
4266}
0 commit comments