mirror of
https://github.com/YouHaveTrouble/CommandWhitelist.git
synced 2026-08-28 00:56:45 +00:00
Validate tab completion requests before exposing command suggestions (#113)
* validate the requested command before exposing argument completions * fix waterfall tab completion filtering * some formatting basic idea formatting wont be bad
This commit is contained in:
+20
-4
@@ -7,19 +7,35 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BungeeTabcompleteListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onTabcomplete(net.md_5.bungee.api.event.TabCompleteEvent event) {
|
||||
if (!(event.getReceiver() instanceof ProxiedPlayer)) return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getReceiver();
|
||||
if (event.getSuggestions().isEmpty()) return;
|
||||
if (!(event.getSender() instanceof ProxiedPlayer)) return;
|
||||
ProxiedPlayer player = (ProxiedPlayer) event.getSender();
|
||||
if (player.hasPermission(CWPermission.BYPASS.permission())) return;
|
||||
CommandUtil.filterSuggestions(
|
||||
|
||||
String cursor = event.getCursor();
|
||||
int commandEnd = cursor.indexOf(' ');
|
||||
if (commandEnd >= 0 && cursor.charAt(0) == '/') {
|
||||
String command = cursor.substring(1, commandEnd).toLowerCase();
|
||||
if (CommandWhitelistWaterfall.getPlugin().getProxy().getPluginManager().isExecutableCommand(command, player)
|
||||
&& !CommandWhitelistWaterfall.getCommands(player).contains(command)) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (event.getSuggestions().isEmpty()) return;
|
||||
|
||||
List<String> suggestions = CommandUtil.filterSuggestions(
|
||||
event.getCursor(),
|
||||
event.getSuggestions(),
|
||||
CommandWhitelistWaterfall.getSuggestions(player)
|
||||
);
|
||||
event.getSuggestions().clear();
|
||||
event.getSuggestions().addAll(suggestions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user