44import com .google .inject .Injector ;
55import com .mojang .brigadier .Command ;
66import com .velocitypowered .api .command .CommandSource ;
7+ import com .velocitypowered .api .event .PostOrder ;
78import com .velocitypowered .api .event .Subscribe ;
89import com .velocitypowered .api .event .command .CommandExecuteEvent ;
910import com .velocitypowered .api .event .command .PlayerAvailableCommandsEvent ;
11+ import com .velocitypowered .api .event .player .TabCompleteEvent ;
1012import com .velocitypowered .api .event .proxy .ProxyInitializeEvent ;
1113import com .velocitypowered .api .plugin .annotation .DataDirectory ;
1214import com .velocitypowered .api .proxy .Player ;
2224import org .slf4j .Logger ;
2325
2426import java .nio .file .Path ;
25- import java .util .ArrayList ;
26- import java .util .HashMap ;
27- import java .util .HashSet ;
28- import java .util .Map ;
27+ import java .util .*;
2928
3029public class CommandWhitelistVelocity {
3130
@@ -74,7 +73,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
7473 metrics .addCustomChart (new SimplePie ("proxy" , () -> "Velocity" ));
7574 }
7675
77- @ Subscribe
76+ @ Subscribe ( order = PostOrder . LAST )
7877 @ SuppressWarnings ("UnstableApiUsage" )
7978 public void onUserCommandSendEvent (PlayerAvailableCommandsEvent event ) {
8079 Player player = event .getPlayer ();
@@ -95,11 +94,45 @@ public void onUserCommandExecuteEvent(CommandExecuteEvent event) {
9594
9695 // Workaround for velocity executing "/ command" as valid command
9796 String command = event .getCommand ().trim ();
97+ if (command .startsWith ("/" )) command = command .substring (1 );
9898
9999 HashSet <String > allowedCommands = getCommands (player );
100100 String label = CommandUtil .getCommandLabel (command );
101- if (server .getCommandManager ().hasCommand (label ) && !allowedCommands .contains (label ))
101+ if (server .getCommandManager ().hasCommand (label ) && !allowedCommands .contains (label )) {
102102 event .setResult (CommandExecuteEvent .CommandResult .forwardToServer ());
103+ return ;
104+ }
105+
106+ HashSet <String > bannedSubCommands = getSuggestions (player );
107+
108+ for (String bannedSubCommand : bannedSubCommands ) {
109+ if (command .startsWith (bannedSubCommand )) {
110+ event .setResult (CommandExecuteEvent .CommandResult .denied ());
111+ player .sendMessage (CWCommand .miniMessage .deserialize (configCache .prefix + configCache .subcommand_denied ));
112+ return ;
113+ }
114+ }
115+ }
116+
117+ /**
118+ * THIS IS FOR CLIENTS ON 1.12 AND BELOW, NOT GUARANTEED TO WORK, IF IT DOESN'T, PR OF GTFO
119+ */
120+ @ Subscribe
121+ public void onUserTabCompleteEvent (TabCompleteEvent event ) {
122+ Player player = event .getPlayer ();
123+ if (player .hasPermission (CWPermission .BYPASS .permission ())) return ;
124+ String buffer = event .getPartialMessage ();
125+
126+ if (event .getSuggestions ().isEmpty ()) return ;
127+
128+ List <String > newSuggestions = CommandUtil .filterSuggestions (
129+ buffer ,
130+ event .getSuggestions (),
131+ getSuggestions (player )
132+ );
133+
134+ event .getSuggestions ().clear ();
135+ event .getSuggestions ().addAll (newSuggestions );
103136 }
104137
105138 public ConfigCache getConfigCache () {
0 commit comments