fully embrace the stream api

This commit is contained in:
ThatDashiell
2020-08-15 10:43:44 -04:00
parent 3d01859958
commit b29fcd81eb
@@ -6,10 +6,8 @@ import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command; import net.md_5.bungee.api.plugin.Command;
import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.event.EventHandler; import net.md_5.bungee.event.EventHandler;
import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class BungeeTabCompleteListener implements Listener { public class BungeeTabCompleteListener implements Listener {
@@ -23,21 +21,17 @@ public class BungeeTabCompleteListener implements Listener {
return; return;
} }
List<String> commandList = CommandsList.getCommands(player);
HashMap<String, Command> commandHashMap = new HashMap<>(); HashMap<String, Command> commandHashMap = new HashMap<>();
for (String s : commandList) { CommandsList.getCommands(player).forEach(cmdName ->
for (Map.Entry<String, Command> command : CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()) { CommandWhitelistBungee.getPlugin().getProxy().getPluginManager().getCommands()
if (s.equalsIgnoreCase(command.getValue().getName())) { .stream()
commandHashMap.put(command.getKey(), command.getValue()); .filter(commandEntry -> cmdName.equalsIgnoreCase(commandEntry.getValue().getName()))
} .forEach(commandEntry -> commandHashMap.put(commandEntry.getKey(), commandEntry.getValue())));
}
}
event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd)); event.getCommands().values().removeIf((cmd) -> !commandHashMap.containsValue(cmd));
} }
} }
} }