mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2025-07-01 20:46:41 +00:00
yeah
This commit is contained in:
@ -1,26 +1,106 @@
|
||||
package me.totalfreedom.totalfreedommod.command;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import me.totalfreedom.totalfreedommod.util.Groups;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH)
|
||||
@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command>", aliases = "ew,rd")
|
||||
@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [name | -a]", aliases = "ew,rd")
|
||||
public class Command_entitywipe extends FreedomCommand
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
||||
{
|
||||
FUtil.adminAction(sender.getName(), "Removing all server entities", true);
|
||||
int removed = plugin.ew.wipe();
|
||||
msg(removed + " entities removed.");
|
||||
EntityType type = null;
|
||||
String entityName = null;
|
||||
boolean bypassBlacklist = false;
|
||||
if (args.length > 0)
|
||||
{
|
||||
if (args[0].equals("-a"))
|
||||
{
|
||||
bypassBlacklist = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
type = EntityType.valueOf(args[0].toUpperCase());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
msg(args[0] + " is not a valid entity type.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!getAllEntities().contains(type))
|
||||
{
|
||||
msg(FUtil.formatName(type.name()) + " is an entity, however: it is a mob.", ChatColor.RED);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (type != null)
|
||||
{
|
||||
entityName = FUtil.formatName(type.name());
|
||||
}
|
||||
|
||||
FUtil.adminAction(sender.getName(), "Purging all " + (type != null ? entityName + "s" : "entities"), true);
|
||||
int count;
|
||||
if (type != null)
|
||||
{
|
||||
count = plugin.ew.wipeEntities(type);
|
||||
}
|
||||
else
|
||||
{
|
||||
count = plugin.ew.wipeEntities(bypassBlacklist);
|
||||
}
|
||||
msg(count + " " + (type != null ? entityName : "entities") + FUtil.showS(count) + " removed.");
|
||||
return true;
|
||||
}
|
||||
|
||||
public static List<EntityType> getAllEntities()
|
||||
{
|
||||
List<EntityType> entityTypes = new ArrayList<>();
|
||||
for (EntityType entityType : EntityType.values())
|
||||
{
|
||||
if (!Groups.MOB_TYPES.contains(entityType))
|
||||
{
|
||||
entityTypes.add(entityType);
|
||||
}
|
||||
}
|
||||
return entityTypes;
|
||||
}
|
||||
|
||||
public static List<String> getAllEntityNames()
|
||||
{
|
||||
List<String> names = new ArrayList<>();
|
||||
for (EntityType entityType : getAllEntities())
|
||||
{
|
||||
names.add(entityType.name());
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args)
|
||||
{
|
||||
List<String> names = getAllEntityNames();
|
||||
names.add("-a");
|
||||
if (args.length == 1)
|
||||
{
|
||||
return names;
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user