diff --git a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGiveSpawner.java similarity index 64% rename from src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java rename to src/main/java/com/songoda/ultimatestacker/command/commands/CommandGiveSpawner.java index 444b064..2061677 100644 --- a/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGive.java +++ b/src/main/java/com/songoda/ultimatestacker/command/commands/CommandGiveSpawner.java @@ -9,15 +9,20 @@ import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; -public class CommandGive extends AbstractCommand { +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; - public CommandGive(AbstractCommand abstractCommand) { - super("givespawner", abstractCommand, false); +public class CommandGiveSpawner extends AbstractCommand { + + public CommandGiveSpawner(AbstractCommand abstractCommand) { + super(abstractCommand, false, "givespawner"); } @Override protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) { - if (args.length != 4) return ReturnType.SYNTAX_ERROR; + if (args.length < 3) return ReturnType.SYNTAX_ERROR; if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) { sender.sendMessage("Not a player..."); @@ -37,12 +42,13 @@ public class CommandGive extends AbstractCommand { StringBuilder list = new StringBuilder(); for (EntityType types : EntityType.values()) { - list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6"); + if (types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR")) + list.append(types.name().toUpperCase().replace(" ", "_")).append("&7, &6"); } sender.sendMessage(Methods.formatText("&6" + list)); } else { - int amt = Integer.parseInt(args[3]); + int amt = args.length == 4 ? Integer.parseInt(args[3]) : 1; ItemStack itemStack = Methods.getSpawnerItem(type, amt); if (!args[1].trim().toLowerCase().equals("all")) { Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer(); @@ -62,6 +68,23 @@ public class CommandGive extends AbstractCommand { return ReturnType.SUCCESS; } + @Override + protected List onTab(UltimateStacker instance, CommandSender sender, String... args) { + if (args.length == 2) { + List players = new ArrayList<>(); + players.add("all"); + players.addAll(Bukkit.getOnlinePlayers().stream().map(Player::getName).collect(Collectors.toList())); + return players; + } else if (args.length == 3) { + return Arrays.stream(EntityType.values()) + .filter(types -> types.isSpawnable() && types.isAlive() && !types.toString().contains("ARMOR")) + .map(Enum::name).collect(Collectors.toList()); + } else if (args.length == 4) { + return Arrays.asList("1", "2", "3", "4", "5"); + } + return null; + } + @Override public String getPermissionNode() { return "ultimatestacker.admin"; @@ -69,7 +92,7 @@ public class CommandGive extends AbstractCommand { @Override public String getSyntax() { - return "/us givespawner "; + return "/us givespawner [size]"; } @Override