From 1bf2a818ecfcc3c1d4eb9c84e8487669df560348 Mon Sep 17 00:00:00 2001 From: Paldiu Date: Mon, 25 Apr 2022 13:40:18 -0500 Subject: [PATCH] [Beta] SNAPSHOT {Bug Fix} Patch 0002 - Fixed command completions which still did not return correctly. They should now return correctly. --- .../io/github/simplex/luck/util/LuckCMD.java | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/io/github/simplex/luck/util/LuckCMD.java b/src/main/java/io/github/simplex/luck/util/LuckCMD.java index 3e183d8..8012ba3 100644 --- a/src/main/java/io/github/simplex/luck/util/LuckCMD.java +++ b/src/main/java/io/github/simplex/luck/util/LuckCMD.java @@ -162,9 +162,7 @@ public class LuckCMD extends Command implements TabCompleter { List completions = new ArrayList<>() {{ add("info"); }}; - List playerNames = new ArrayList<>() {{ - Bukkit.getOnlinePlayers().forEach(p -> add(p.getName())); - }}; + List playerNames = Bukkit.getOnlinePlayers().stream().map(Player::getName).toList(); List adminCommands = List.of("set", "reset", "give", "take", "reload"); if ((sender instanceof ConsoleCommandSender) || sender.hasPermission("luck.admin")) { @@ -173,18 +171,24 @@ public class LuckCMD extends Command implements TabCompleter { } if (adminCommands.contains(args[0]) - && sender.hasPermission("luck.admin") - && (args.length == 2)) { - switch (args[0]) { - case "info": - case "reset": - return playerNames.stream().filter(n -> n.startsWith(args[1])).toList(); - case "reload": - return List.of("-m", "-p"); - case "give": - case "take": - case "set": - return List.of("amount"); + && sender.hasPermission("luck.admin")) { + if (args.length == 2) { + switch (args[0]) { + case "info": + case "reset": + return playerNames.stream().filter(n -> n.startsWith(args[1])).toList(); + case "reload": + return List.of("-m", "-p"); + } + } + + if (args.length == 3 && playerNames.contains(args[1])) { + switch (args[0]) { + case "give": + case "take": + case "set": + return List.of("amount"); + } } }