TotalFreedomMod/src/main/java/me/totalfreedom/totalfreedommod/command/Command_spawnmob.java
Paldiu 5c0f77c7c5 Removal of Lombok
Lombok implementation removal.

I have also gone through and replaced things with inline methods and variables, lambdas, and simplified loops down, removed unnecessary guard clauses, and overall cleaned up every single class. This took a long time, please do remember to follow proper naming conventions, don't include unnecessary guard clauses, follow exception rules and comment rules, and please PLEASE remember to use the DIAMOND OPERATOR rather than just inferring RAW TYPES!!!

Thank you!!
2020-12-25 14:46:43 -05:00

88 lines
2.6 KiB
Java

package me.totalfreedom.totalfreedommod.command;
import java.util.List;
import me.totalfreedom.totalfreedommod.rank.Rank;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.EnumUtils;
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)
@CommandParameters(description = "Spawns the specified entity.", usage = "/<command> <entitytype> [amount]", aliases = "spawnentity")
public class Command_spawnmob extends FreedomCommand
{
@Override
public 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)
{
return false;
}
EntityType type = null;
for (EntityType loop : EntityType.values())
{
if (loop != null && loop.name().equalsIgnoreCase(args[0]))
{
type = loop;
break;
}
}
if (type == null)
{
msg("Unknown entity type: " + args[0], ChatColor.RED);
return true;
}
if (!type.isSpawnable() || !type.isAlive())
{
msg("Can not spawn entity type: " + type.name().toLowerCase());
return true;
}
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;
}
}
if (amount > 10 || amount < 1)
{
msg("Invalid amount: " + args[1] + ". Must be 1-10.", ChatColor.RED);
return true;
}
Location l = playerSender.getTargetBlock(null, 30).getLocation().add(0, 1, 0);
World w = playerSender.getWorld();
msg("Spawning " + amount + " " + type.name().toLowerCase() + (amount > 1 ? "s." : "."));
for (int i = 0; i < amount; i++)
{
w.spawnEntity(l, type);
}
return true;
}
}