4
4
import com .google .inject .Injector ;
5
5
import com .mojang .brigadier .Command ;
6
6
import com .velocitypowered .api .command .CommandSource ;
7
+ import com .velocitypowered .api .event .PostOrder ;
7
8
import com .velocitypowered .api .event .Subscribe ;
8
9
import com .velocitypowered .api .event .command .CommandExecuteEvent ;
9
10
import com .velocitypowered .api .event .command .PlayerAvailableCommandsEvent ;
11
+ import com .velocitypowered .api .event .player .TabCompleteEvent ;
10
12
import com .velocitypowered .api .event .proxy .ProxyInitializeEvent ;
11
13
import com .velocitypowered .api .plugin .annotation .DataDirectory ;
12
14
import com .velocitypowered .api .proxy .Player ;
22
24
import org .slf4j .Logger ;
23
25
24
26
import 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 .*;
29
28
30
29
public class CommandWhitelistVelocity {
31
30
@@ -74,7 +73,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) {
74
73
metrics .addCustomChart (new SimplePie ("proxy" , () -> "Velocity" ));
75
74
}
76
75
77
- @ Subscribe
76
+ @ Subscribe ( order = PostOrder . LAST )
78
77
@ SuppressWarnings ("UnstableApiUsage" )
79
78
public void onUserCommandSendEvent (PlayerAvailableCommandsEvent event ) {
80
79
Player player = event .getPlayer ();
@@ -95,11 +94,45 @@ public void onUserCommandExecuteEvent(CommandExecuteEvent event) {
95
94
96
95
// Workaround for velocity executing "/ command" as valid command
97
96
String command = event .getCommand ().trim ();
97
+ if (command .startsWith ("/" )) command = command .substring (1 );
98
98
99
99
HashSet <String > allowedCommands = getCommands (player );
100
100
String label = CommandUtil .getCommandLabel (command );
101
- if (server .getCommandManager ().hasCommand (label ) && !allowedCommands .contains (label ))
101
+ if (server .getCommandManager ().hasCommand (label ) && !allowedCommands .contains (label )) {
102
102
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 );
103
136
}
104
137
105
138
public ConfigCache getConfigCache () {
0 commit comments