PedroJM96 / SuperLobbyDeluxe

Customize many functions and features of the server lobby in a powerful and free for all.
17 stars 14 forks source link

Disable TabComplete not working properly. #24

Closed CasieBarie closed 11 months ago

CasieBarie commented 1 year ago

Hello, Recently I noticed the 'Disable TabComplete' hides all the commands while you have some commands whitelisted. While looking through the source code I found the problem!

e.getCommands().clear();
e.getCommands().addAll(filter); 

You are using this to first clear the commands and then add back the whitelisted ones. But Bukkit doesn't allow you to add back commands. You can only remove them.

To fix this you have to add all the commands in a list except the whitelisted ones. Then you just remove them.

Example:

ArrayList<String> toRemove = new ArrayList<>();
List<String> whitelist = plugin.config.getStringList("disable-tab-complete.whitelist");
for(String command : e.getCommands()) {
    if(!whitelist.contains("/" + command)) {
        toRemove.add(command);
    }
}
e.getCommands().removeAll(toRemove);

I hope this helps to fix the problem. Have a nice day!

CasieBarie commented 11 months ago

This is also fix for #20

PedroJM96 commented 11 months ago

Fixed in the next version, thanks for the code