mirror of
https://github.com/plexusorg/Plex.git
synced 2024-12-22 17:17:37 +00:00
reformat
This commit is contained in:
parent
b168029df1
commit
c9d954d1c0
@ -20,9 +20,11 @@ import java.util.*;
|
|||||||
|
|
||||||
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.entitywipe", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [entity] [radius]", aliases = "ew,rd")
|
@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/<command> [entity] [radius]", aliases = "ew,rd")
|
||||||
public class EntityWipeCMD extends PlexCommand {
|
public class EntityWipeCMD extends PlexCommand
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) {
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||||
|
{
|
||||||
List<String> entityBlacklist = plugin.config.getStringList("entitywipe_list");
|
List<String> entityBlacklist = plugin.config.getStringList("entitywipe_list");
|
||||||
|
|
||||||
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
List<String> entityWhitelist = new LinkedList<>(Arrays.asList(args));
|
||||||
@ -34,7 +36,8 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
PlexLog.debug("using blacklist: " + useBlacklist);
|
PlexLog.debug("using blacklist: " + useBlacklist);
|
||||||
PlexLog.debug("radius specified: " + radiusSpecified);
|
PlexLog.debug("radius specified: " + radiusSpecified);
|
||||||
|
|
||||||
if (radiusSpecified) {
|
if (radiusSpecified)
|
||||||
|
{
|
||||||
radius = parseInt(sender, args[entityWhitelist.size() - 1]); // get the args length as the size of the list
|
radius = parseInt(sender, args[entityWhitelist.size() - 1]); // get the args length as the size of the list
|
||||||
radius *= radius;
|
radius *= radius;
|
||||||
entityWhitelist.remove(entityWhitelist.size() - 1); // remove the radius from the list
|
entityWhitelist.remove(entityWhitelist.size() - 1); // remove the radius from the list
|
||||||
@ -46,7 +49,8 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
entityWhitelist.removeIf(name ->
|
entityWhitelist.removeIf(name ->
|
||||||
{
|
{
|
||||||
boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name()));
|
boolean res = Arrays.stream(entityTypes).noneMatch(entityType -> name.equalsIgnoreCase(entityType.name()));
|
||||||
if (res) {
|
if (res)
|
||||||
|
{
|
||||||
sender.sendMessage(messageComponent("invalidEntityType", name));
|
sender.sendMessage(messageComponent("invalidEntityType", name));
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@ -54,15 +58,21 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
|
|
||||||
HashMap<String, Integer> entityCounts = new HashMap<>();
|
HashMap<String, Integer> entityCounts = new HashMap<>();
|
||||||
|
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds())
|
||||||
for (Entity entity : world.getEntities()) {
|
{
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
for (Entity entity : world.getEntities())
|
||||||
|
{
|
||||||
|
if (entity.getType() != EntityType.PLAYER)
|
||||||
|
{
|
||||||
String type = entity.getType().name();
|
String type = entity.getType().name();
|
||||||
|
|
||||||
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type))) {
|
if (useBlacklist ? entityBlacklist.stream().noneMatch(entityName -> entityName.equalsIgnoreCase(type)) : entityWhitelist.stream().anyMatch(entityName -> entityName.equalsIgnoreCase(type)))
|
||||||
if (radius > 0) {
|
{
|
||||||
|
if (radius > 0)
|
||||||
|
{
|
||||||
PlexLog.debug("we got here, radius is > 0");
|
PlexLog.debug("we got here, radius is > 0");
|
||||||
if (playerSender != null && entity.getWorld() == playerSender.getWorld() && playerSender.getLocation().distanceSquared(entity.getLocation()) > radius) {
|
if (playerSender != null && entity.getWorld() == playerSender.getWorld() && playerSender.getLocation().distanceSquared(entity.getLocation()) > radius)
|
||||||
|
{
|
||||||
PlexLog.debug("continuing");
|
PlexLog.debug("continuing");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -78,10 +88,14 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
|
|
||||||
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum();
|
int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum();
|
||||||
|
|
||||||
if (useBlacklist) {
|
if (useBlacklist)
|
||||||
|
{
|
||||||
PlexUtils.broadcast(messageComponent("removedEntities", sender.getName(), entityCount));
|
PlexUtils.broadcast(messageComponent("removedEntities", sender.getName(), entityCount));
|
||||||
} else {
|
}
|
||||||
if (entityCount == 0) {
|
else
|
||||||
|
{
|
||||||
|
if (entityCount == 0)
|
||||||
|
{
|
||||||
sender.sendMessage(messageComponent("noRemovedEntities"));
|
sender.sendMessage(messageComponent("noRemovedEntities"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -92,11 +106,15 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
|
{
|
||||||
List<String> entities = new ArrayList<>();
|
List<String> entities = new ArrayList<>();
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds())
|
||||||
for (Entity entity : world.getEntities()) {
|
{
|
||||||
if (entity.getType() != EntityType.PLAYER) {
|
for (Entity entity : world.getEntities())
|
||||||
|
{
|
||||||
|
if (entity.getType() != EntityType.PLAYER)
|
||||||
|
{
|
||||||
entities.add(entity.getType().name());
|
entities.add(entity.getType().name());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,22 +122,31 @@ public class EntityWipeCMD extends PlexCommand {
|
|||||||
return entities.stream().toList();
|
return entities.stream().toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Integer parseInt(CommandSender sender, String string) {
|
private Integer parseInt(CommandSender sender, String string)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
return Integer.parseInt(string);
|
return Integer.parseInt(string);
|
||||||
} catch (NumberFormatException ex) {
|
}
|
||||||
|
catch (NumberFormatException ex)
|
||||||
|
{
|
||||||
sender.sendMessage(mmString("<red>" + string + "<red> is not a valid number!"));
|
sender.sendMessage(mmString("<red>" + string + "<red> is not a valid number!"));
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isNumeric(String string) {
|
private boolean isNumeric(String string)
|
||||||
if (string == null) {
|
{
|
||||||
|
if (string == null)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
try {
|
try
|
||||||
|
{
|
||||||
int num = Integer.parseInt(string);
|
int num = Integer.parseInt(string);
|
||||||
} catch (NumberFormatException nfe) {
|
}
|
||||||
|
catch (NumberFormatException nfe)
|
||||||
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -24,39 +24,49 @@ import java.util.Collections;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
@CommandPermissions(permission = "plex.mobpurge", source = RequiredCommandSource.ANY)
|
||||||
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> <mob>", aliases = "mp")
|
@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/<command> [mob]", aliases = "mp")
|
||||||
public class MobPurgeCMD extends PlexCommand {
|
public class MobPurgeCMD extends PlexCommand
|
||||||
|
{
|
||||||
public static final List<EntityType> MOB_TYPES = new ArrayList<>();
|
private final List<EntityType> MOB_TYPES = new ArrayList<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) {
|
protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args)
|
||||||
|
{
|
||||||
EntityType type = null;
|
EntityType type = null;
|
||||||
String mobName = null;
|
String mobName = null;
|
||||||
if (args.length > 0) {
|
if (args.length > 0)
|
||||||
try {
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
type = EntityType.valueOf(args[0].toUpperCase());
|
type = EntityType.valueOf(args[0].toUpperCase());
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
PlexLog.debug("A genius tried and failed removing the following invalid mob: " + args[0].toUpperCase());
|
PlexLog.debug("A genius tried and failed removing the following invalid mob: " + args[0].toUpperCase());
|
||||||
send(sender, messageComponent("notAValidMob"));
|
send(sender, messageComponent("notAValidMob"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!MOB_TYPES.contains(type)) {
|
if (!MOB_TYPES.contains(type))
|
||||||
|
{
|
||||||
PlexLog.debug(Arrays.deepToString(MOB_TYPES.toArray()));
|
PlexLog.debug(Arrays.deepToString(MOB_TYPES.toArray()));
|
||||||
PlexLog.debug("A genius tried to remove a mob that doesn't exist: " + args[0].toUpperCase());
|
PlexLog.debug("A genius tried to remove a mob that doesn't exist: " + args[0].toUpperCase());
|
||||||
sender.sendMessage(messageComponent("notAValidMobButValidEntity"));
|
sender.sendMessage(messageComponent("notAValidMobButValidEntity"));
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type != null) {
|
if (type != null)
|
||||||
|
{
|
||||||
mobName = WordUtils.capitalizeFully(type.name().replace("_", " "));
|
mobName = WordUtils.capitalizeFully(type.name().replace("_", " "));
|
||||||
PlexLog.debug("The args aren't null so the mob is: " + mobName);
|
PlexLog.debug("The args aren't null so the mob is: " + mobName);
|
||||||
}
|
}
|
||||||
int count = purgeMobs(type);
|
int count = purgeMobs(type);
|
||||||
if (type != null) {
|
if (type != null)
|
||||||
|
{
|
||||||
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
|
PlexUtils.broadcast(messageComponent("removedEntitiesOfTypes", sender.getName(), count, mobName));
|
||||||
PlexLog.debug("All " + count + " of " + mobName + " were removed");
|
PlexLog.debug("All " + count + " of " + mobName + " were removed");
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), count));
|
PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), count));
|
||||||
PlexLog.debug("All " + count + " valid mobs were removed");
|
PlexLog.debug("All " + count + " valid mobs were removed");
|
||||||
}
|
}
|
||||||
@ -64,18 +74,22 @@ public class MobPurgeCMD extends PlexCommand {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String multipleS(int count) {
|
private String multipleS(int count)
|
||||||
|
{
|
||||||
return (count == 1 ? "" : "s");
|
return (count == 1 ? "" : "s");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Removes the mobs.
|
private int purgeMobs(EntityType type)
|
||||||
|
{
|
||||||
public int purgeMobs(EntityType type) {
|
|
||||||
int removed = 0;
|
int removed = 0;
|
||||||
for (World world : Bukkit.getWorlds()) {
|
for (World world : Bukkit.getWorlds())
|
||||||
for (Entity entity : world.getLivingEntities()) {
|
{
|
||||||
if (entity instanceof LivingEntity && !(entity instanceof Player)) {
|
for (Entity entity : world.getLivingEntities())
|
||||||
if (type != null && !entity.getType().equals(type)) {
|
{
|
||||||
|
if (entity instanceof LivingEntity && !(entity instanceof Player))
|
||||||
|
{
|
||||||
|
if (type != null && !entity.getType().equals(type))
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
entity.remove();
|
entity.remove();
|
||||||
@ -86,19 +100,21 @@ public class MobPurgeCMD extends PlexCommand {
|
|||||||
return removed;
|
return removed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adds a tab completion for /mp so players stop complaining we (mostly me) nuked all their mobs because a filter for some reason was never added by the REAL plex devs. Go figure. -Alco_Rs11
|
private List<String> getAllMobs()
|
||||||
|
{
|
||||||
public static List<String> getAllMobs() {
|
|
||||||
List<String> mobs = new ArrayList<>();
|
List<String> mobs = new ArrayList<>();
|
||||||
Arrays.stream(EntityType.values()).filter(EntityType::isAlive).filter(EntityType::isSpawnable).forEach(MOB_TYPES::add);
|
Arrays.stream(EntityType.values()).filter(EntityType::isAlive).filter(EntityType::isSpawnable).forEach(MOB_TYPES::add);
|
||||||
for (EntityType entityType : MOB_TYPES) {
|
for (EntityType entityType : MOB_TYPES)
|
||||||
|
{
|
||||||
mobs.add(entityType.name());
|
mobs.add(entityType.name());
|
||||||
}
|
}
|
||||||
return mobs;
|
return mobs;
|
||||||
}
|
}
|
||||||
|
|
||||||
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException {
|
public @NotNull List<String> tabComplete(@NotNull CommandSender sender, @NotNull String alias, @NotNull String[] args) throws IllegalArgumentException
|
||||||
if (args.length == 1) {
|
{
|
||||||
|
if (args.length == 1)
|
||||||
|
{
|
||||||
return getAllMobs();
|
return getAllMobs();
|
||||||
}
|
}
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
|
Loading…
Reference in New Issue
Block a user