Made the spawner size optional & Fixed spawner tyoe suggestions.

This commit is contained in:
Brianna 2019-08-19 11:07:40 -04:00
parent ea027616a4
commit 49aa0e6f30

View File

@ -9,15 +9,20 @@ import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack; 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) { public class CommandGiveSpawner extends AbstractCommand {
super("givespawner", abstractCommand, false);
public CommandGiveSpawner(AbstractCommand abstractCommand) {
super(abstractCommand, false, "givespawner");
} }
@Override @Override
protected ReturnType runCommand(UltimateStacker instance, CommandSender sender, String... args) { 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")) { if (Bukkit.getPlayer(args[1]) == null && !args[1].trim().toLowerCase().equals("all")) {
sender.sendMessage("Not a player..."); sender.sendMessage("Not a player...");
@ -37,12 +42,13 @@ public class CommandGive extends AbstractCommand {
StringBuilder list = new StringBuilder(); StringBuilder list = new StringBuilder();
for (EntityType types : EntityType.values()) { 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)); sender.sendMessage(Methods.formatText("&6" + list));
} else { } else {
int amt = Integer.parseInt(args[3]); int amt = args.length == 4 ? Integer.parseInt(args[3]) : 1;
ItemStack itemStack = Methods.getSpawnerItem(type, amt); ItemStack itemStack = Methods.getSpawnerItem(type, amt);
if (!args[1].trim().toLowerCase().equals("all")) { if (!args[1].trim().toLowerCase().equals("all")) {
Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer(); Player player = Bukkit.getOfflinePlayer(args[1]).getPlayer();
@ -62,6 +68,23 @@ public class CommandGive extends AbstractCommand {
return ReturnType.SUCCESS; return ReturnType.SUCCESS;
} }
@Override
protected List<String> onTab(UltimateStacker instance, CommandSender sender, String... args) {
if (args.length == 2) {
List<String> 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 @Override
public String getPermissionNode() { public String getPermissionNode() {
return "ultimatestacker.admin"; return "ultimatestacker.admin";
@ -69,7 +92,7 @@ public class CommandGive extends AbstractCommand {
@Override @Override
public String getSyntax() { public String getSyntax() {
return "/us givespawner <player/all> <type> <level>"; return "/us givespawner <player/all> <type> [size]";
} }
@Override @Override