2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2019-01-28 01:49:07 +00:00
|
|
|
import com.sk89q.worldedit.blocks.metadata.MobType;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2016-05-12 19:40:39 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2019-01-28 01:49:07 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.Groups;
|
|
|
|
import org.apache.commons.lang.WordUtils;
|
2013-07-27 21:49:25 +00:00
|
|
|
import org.bukkit.Bukkit;
|
2019-01-28 01:49:07 +00:00
|
|
|
import org.bukkit.ChatColor;
|
2011-10-19 00:37:00 +00:00
|
|
|
import org.bukkit.World;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2018-07-31 07:05:28 +00:00
|
|
|
import org.bukkit.entity.Ambient;
|
|
|
|
import org.bukkit.entity.Creature;
|
|
|
|
import org.bukkit.entity.EnderDragon;
|
|
|
|
import org.bukkit.entity.Entity;
|
2019-01-28 01:49:07 +00:00
|
|
|
import org.bukkit.entity.EntityType;
|
2018-07-31 07:05:28 +00:00
|
|
|
import org.bukkit.entity.Ghast;
|
2019-01-28 01:49:07 +00:00
|
|
|
import org.bukkit.entity.LivingEntity;
|
2018-07-31 07:05:28 +00:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.entity.Slime;
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
2019-01-28 01:49:07 +00:00
|
|
|
@CommandParameters(description = "Purge all mobs in all worlds.", usage = "/<command> [name]", aliases = "mp")
|
2015-11-15 23:32:04 +00:00
|
|
|
public class Command_mobpurge extends FreedomCommand
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2015-11-22 18:26:47 +00:00
|
|
|
|
2011-10-19 00:37:00 +00:00
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2019-01-28 01:49:07 +00:00
|
|
|
EntityType type = null;
|
|
|
|
String mobName = null;
|
|
|
|
if (args.length > 0)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
type = EntityType.valueOf(args[0].toUpperCase());
|
|
|
|
}
|
|
|
|
catch (Exception e)
|
|
|
|
{
|
|
|
|
msg(args[0] + " is not a valid mob type.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!Groups.MOB_TYPES.contains(type))
|
|
|
|
{
|
|
|
|
msg(WordUtils.capitalizeFully(type.name().replace("_", " ")) + " is an entity, however it is not a mob.", ChatColor.RED);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (type != null)
|
|
|
|
{
|
|
|
|
mobName = WordUtils.capitalizeFully(type.name().replace("_", " "));
|
|
|
|
}
|
|
|
|
|
|
|
|
FUtil.adminAction(sender.getName(), "Purging all " + (type != null ? mobName + "s" : "mobs"), true);
|
|
|
|
msg(purgeMobs(type) + " " + (type != null ? mobName : "mob") + "s removed.");
|
2013-07-27 21:49:25 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-10-19 00:37:00 +00:00
|
|
|
|
2019-01-28 01:49:07 +00:00
|
|
|
public static int purgeMobs(EntityType type)
|
2013-07-27 21:49:25 +00:00
|
|
|
{
|
2012-11-24 01:22:52 +00:00
|
|
|
int removed = 0;
|
2013-07-27 21:49:25 +00:00
|
|
|
for (World world : Bukkit.getWorlds())
|
2012-11-24 01:22:52 +00:00
|
|
|
{
|
|
|
|
for (Entity ent : world.getLivingEntities())
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2019-01-28 01:49:07 +00:00
|
|
|
if (ent instanceof LivingEntity && !(ent instanceof Player))
|
2011-10-19 00:37:00 +00:00
|
|
|
{
|
2019-01-28 01:49:07 +00:00
|
|
|
if (type != null && !ent.getType().equals(type))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2012-11-24 01:22:52 +00:00
|
|
|
ent.remove();
|
|
|
|
removed++;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-27 21:49:25 +00:00
|
|
|
return removed;
|
2011-10-19 00:37:00 +00:00
|
|
|
}
|
|
|
|
}
|