2016-05-12 19:40:39 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
|
|
|
|
2018-07-31 07:01:29 +00:00
|
|
|
import java.util.List;
|
2021-12-16 04:46:56 +00:00
|
|
|
|
|
|
|
import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
2016-05-12 19:40:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2019-07-28 06:04:16 +00:00
|
|
|
import org.apache.commons.lang.StringUtils;
|
2020-07-01 03:38:29 +00:00
|
|
|
import org.apache.commons.lang3.EnumUtils;
|
2016-05-12 19:40:39 +00:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
@CommandPermissions(level = Rank.OP, source = SourceType.ONLY_IN_GAME)
|
2020-03-30 23:43:57 +00:00
|
|
|
@CommandParameters(description = "Spawns the specified entity.", usage = "/<command> <entitytype> [amount]", aliases = "spawnentity")
|
2016-05-12 19:40:39 +00:00
|
|
|
public class Command_spawnmob extends FreedomCommand
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
2020-07-01 01:51:06 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2018-07-12 23:33:02 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2016-05-12 19:40:39 +00:00
|
|
|
if (args.length < 1)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
EntityType type = null;
|
|
|
|
for (EntityType loop : EntityType.values())
|
|
|
|
{
|
2018-07-12 23:33:02 +00:00
|
|
|
if (loop != null && loop.name().equalsIgnoreCase(args[0]))
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
type = loop;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type == null)
|
|
|
|
{
|
|
|
|
msg("Unknown entity type: " + args[0], ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!type.isSpawnable() || !type.isAlive())
|
|
|
|
{
|
2018-07-12 23:33:02 +00:00
|
|
|
msg("Can not spawn entity type: " + type.name().toLowerCase());
|
2016-05-12 19:40:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-12-16 04:46:56 +00:00
|
|
|
int max = ConfigEntry.SPAWNMOB_MAX.getInteger();
|
2016-05-12 19:40:39 +00:00
|
|
|
int amount = 1;
|
|
|
|
if (args.length > 1)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
amount = Integer.parseInt(args[1]);
|
|
|
|
}
|
|
|
|
catch (NumberFormatException nfex)
|
|
|
|
{
|
|
|
|
msg("Invalid amount: " + args[1], ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-16 04:46:56 +00:00
|
|
|
if (amount > max || amount < 1)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
2021-12-16 04:46:56 +00:00
|
|
|
msg("Invalid amount: " + args[1] + ". Must be 1-" + max + ".", ChatColor.RED);
|
2016-05-12 19:40:39 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-12-04 00:28:53 +00:00
|
|
|
Location l = playerSender.getTargetBlock(null, 30).getLocation().add(0, 1, 0);
|
2016-05-12 19:40:39 +00:00
|
|
|
World w = playerSender.getWorld();
|
2018-07-12 23:33:02 +00:00
|
|
|
msg("Spawning " + amount + " " + type.name().toLowerCase() + (amount > 1 ? "s." : "."));
|
2016-05-12 19:40:39 +00:00
|
|
|
|
2018-07-11 23:17:00 +00:00
|
|
|
for (int i = 0; i < amount; i++)
|
2016-05-12 19:40:39 +00:00
|
|
|
{
|
|
|
|
w.spawnEntity(l, type);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2020-12-04 00:28:53 +00:00
|
|
|
}
|