From 75eaf34127174719573695b2073405874c4e574b Mon Sep 17 00:00:00 2001 From: Kiran Hart Date: Sat, 21 Mar 2020 17:29:42 -0400 Subject: [PATCH] Added spawn command to spawn X amount of stacked mobs. --- .../ultimatestacker/UltimateStacker.java | 8 +- .../commands/CommandSpawn.java | 89 +++++++++++++++++++ 2 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/songoda/ultimatestacker/commands/CommandSpawn.java diff --git a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java index 40afc80..12a3844 100644 --- a/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java +++ b/src/main/java/com/songoda/ultimatestacker/UltimateStacker.java @@ -14,12 +14,7 @@ import com.songoda.core.gui.GuiManager; import com.songoda.core.hooks.HologramManager; import com.songoda.core.hooks.WorldGuardHook; import com.songoda.core.utils.TextUtils; -import com.songoda.ultimatestacker.commands.CommandConvert; -import com.songoda.ultimatestacker.commands.CommandGiveSpawner; -import com.songoda.ultimatestacker.commands.CommandReload; -import com.songoda.ultimatestacker.commands.CommandRemoveAll; -import com.songoda.ultimatestacker.commands.CommandSettings; -import com.songoda.ultimatestacker.commands.CommandUltimateStacker; +import com.songoda.ultimatestacker.commands.*; import com.songoda.ultimatestacker.database.DataManager; import com.songoda.ultimatestacker.database.migrations._1_InitialMigration; import com.songoda.ultimatestacker.entity.EntityStack; @@ -120,6 +115,7 @@ public class UltimateStacker extends SongodaPlugin { .addSubCommand(new CommandRemoveAll()) .addSubCommand(new CommandReload()) .addSubCommand(new CommandGiveSpawner()) + .addSubCommand(new CommandSpawn()) .addSubCommand(new CommandConvert(guiManager)); this.entityUtils = new EntityUtils(); diff --git a/src/main/java/com/songoda/ultimatestacker/commands/CommandSpawn.java b/src/main/java/com/songoda/ultimatestacker/commands/CommandSpawn.java new file mode 100644 index 0000000..fc84581 --- /dev/null +++ b/src/main/java/com/songoda/ultimatestacker/commands/CommandSpawn.java @@ -0,0 +1,89 @@ +package com.songoda.ultimatestacker.commands; + +import com.songoda.core.commands.AbstractCommand; +import com.songoda.ultimatestacker.UltimateStacker; +import com.songoda.ultimatestacker.entity.EntityStack; +import com.songoda.ultimatestacker.utils.Methods; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Entity; +import org.bukkit.entity.EntityType; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; + +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + +/** + * The current file has been created by Kiran Hart + * Date Created: 3/21/2020 + * Time Created: 1:02 PM + */ +public class CommandSpawn extends AbstractCommand { + + UltimateStacker instance; + + public CommandSpawn() { + super(true, "spawn"); + instance = UltimateStacker.getInstance(); + } + + @Override + protected ReturnType runCommand(CommandSender sender, String... args) { + Player p = (Player) sender; + + if (args.length < 2) return ReturnType.SYNTAX_ERROR; + + EntityType type = null; + for (EntityType types : EntityType.values()) { + String input = args[0].toUpperCase().replace("_", "").replace(" ", ""); + String compare = types.name().toUpperCase().replace("_", "").replace(" ", ""); + if (input.equals(compare)) + type = types; + } + + if (type == null) { + instance.getLocale().newMessage("&7The entity &6" + args[0] + " &7does not exist. Try one of these:").sendPrefixedMessage(sender); + StringBuilder list = new StringBuilder(); + + for (EntityType types : EntityType.values()) { + 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 { + Entity entity = p.getWorld().spawnEntity(p.getLocation(), type); + EntityStack stack = instance.getEntityStackManager().addStack(entity.getUniqueId(), (Methods.isInt(args[1])) ? Integer.parseInt(args[1]) : 1); + instance.getStackingTask().attemptSplit(stack, (LivingEntity) entity); + } + + return ReturnType.SUCCESS; + } + + @Override + protected List onTab(CommandSender sender, String... args) { + if (args.length == 1) { + 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 == 2) { + return Arrays.asList("1", "2", "3", "4", "5"); + } + return null; + } + + @Override + public String getPermissionNode() { + return "ultimatestacker.admin"; + } + + @Override + public String getSyntax() { + return "/us spawn "; + } + + @Override + public String getDescription() { + return "Spawns a stack of the specified entity at your location."; + } +}