Improve the spawnmob command

This commit is contained in:
ZeroEpoch1969 2018-07-12 16:33:02 -07:00
parent f167134a3a
commit 04089973f0
No known key found for this signature in database
GPG Key ID: E0AAB104FB9F8FDF

View File

@ -1,6 +1,7 @@
package me.totalfreedom.totalfreedommod.command; package me.totalfreedom.totalfreedommod.command;
import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.World; import org.bukkit.World;
@ -8,15 +9,25 @@ import org.bukkit.command.Command;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType; import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.apache.commons.lang3.EnumUtils;
import java.util.List;
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME) @CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
@CommandParameters(description = "Spawn a mob", usage = "/<command> <mobtype> [amount]") @CommandParameters(description = "Spawn an entity.", usage = "/<command> <entitytype> [amount]", aliases="spawnentity")
public class Command_spawnmob extends FreedomCommand public class Command_spawnmob extends FreedomCommand
{ {
@Override @Override
protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) protected boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
{ {
if (args.length > 0 && args[0].equalsIgnoreCase("list"))
{
List<EntityType> types = EnumUtils.getEnumList(EntityType.class);
String typeList = StringUtils.join(types, ", ").toLowerCase();
msg(typeList);
return true;
}
if (args.length < 1) if (args.length < 1)
{ {
return false; return false;
@ -25,7 +36,7 @@ public class Command_spawnmob extends FreedomCommand
EntityType type = null; EntityType type = null;
for (EntityType loop : EntityType.values()) for (EntityType loop : EntityType.values())
{ {
if (loop.getName().equalsIgnoreCase(args[0])) if (loop != null && loop.name().equalsIgnoreCase(args[0]))
{ {
type = loop; type = loop;
break; break;
@ -40,7 +51,7 @@ public class Command_spawnmob extends FreedomCommand
if (!type.isSpawnable() || !type.isAlive()) if (!type.isSpawnable() || !type.isAlive())
{ {
msg("Can not spawn entity type: " + type.getName()); msg("Can not spawn entity type: " + type.name().toLowerCase());
return true; return true;
} }
@ -64,9 +75,9 @@ public class Command_spawnmob extends FreedomCommand
return true; return true;
} }
Location l = playerSender.getLocation(); Location l = playerSender.getTargetBlock(null, 30).getLocation().add(0, 1, 0);
World w = playerSender.getWorld(); World w = playerSender.getWorld();
msg("Spawning " + amount + " of " + type.getName()); msg("Spawning " + amount + " " + type.name().toLowerCase() + (amount > 1 ? "s." : "."));
for (int i = 0; i < amount; i++) for (int i = 0; i < amount; i++)
{ {