From 0b9f9d74ba954d0eeb25096fe104d95493a4f2a1 Mon Sep 17 00:00:00 2001 From: ayunami2000 Date: Wed, 6 Apr 2022 19:42:47 -0400 Subject: [PATCH] add /mp, and refine /rd to only non-mobs by default awesome --- .../dev/plex/command/impl/EntityWipeCMD.java | 9 +-- .../dev/plex/command/impl/MobPurgeCMD.java | 56 ++++++++++++++ src/main/resources/config.yml | 76 ++++++++++++++++++- src/main/resources/messages.yml | 5 +- 4 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 src/main/java/dev/plex/command/impl/MobPurgeCMD.java diff --git a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java index 8d3e8ef..c49b687 100644 --- a/src/main/java/dev/plex/command/impl/EntityWipeCMD.java +++ b/src/main/java/dev/plex/command/impl/EntityWipeCMD.java @@ -23,7 +23,7 @@ import java.util.LinkedList; import java.util.List; @CommandPermissions(level = Rank.ADMIN, 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 = "/ [name | -a]", aliases = "ew,rd") +@CommandParameters(name = "entitywipe", description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/ [name]", aliases = "ew,rd") public class EntityWipeCMD extends PlexCommand { @Override @@ -62,12 +62,7 @@ public class EntityWipeCMD extends PlexCommand entity.teleportAsync(loc); entity.remove(); - if (!entityCounts.containsKey(type)) - { - entityCounts.put(type,0); - } - - entityCounts.put(type,entityCounts.get(type)+1); + entityCounts.put(type,entityCounts.getOrDefault(type, 0) + 1); } } } diff --git a/src/main/java/dev/plex/command/impl/MobPurgeCMD.java b/src/main/java/dev/plex/command/impl/MobPurgeCMD.java new file mode 100644 index 0000000..c20c629 --- /dev/null +++ b/src/main/java/dev/plex/command/impl/MobPurgeCMD.java @@ -0,0 +1,56 @@ +package dev.plex.command.impl; + +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.source.RequiredCommandSource; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; +import net.kyori.adventure.text.Component; +import org.bukkit.Bukkit; +import org.bukkit.Location; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.*; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.HashMap; + +@CommandPermissions(level = Rank.ADMIN, permission = "plex.mobpurge", source = RequiredCommandSource.ANY) +@CommandParameters(name = "mobpurge", description = "Purge all mobs.", usage = "/", aliases = "mp") +public class MobPurgeCMD extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, @NotNull String[] args) + { + HashMap entityCounts = new HashMap<>(); + + for (World world : Bukkit.getWorlds()) + { + for (Entity entity : world.getEntities()) + { + if (entity instanceof Mob) + { + String type = entity.getType().name(); + + Location loc = entity.getLocation(); + loc.setY(-500); + entity.teleportAsync(loc); + entity.remove(); + + entityCounts.put(type,entityCounts.getOrDefault(type, 0) + 1); + } + } + } + + int entityCount = entityCounts.values().stream().mapToInt(a -> a).sum(); + + PlexUtils.broadcast(messageComponent("removedMobs", sender.getName(), entityCount)); + + entityCounts.forEach((entityName, numRemoved) -> { + sender.sendMessage(messageComponent("removedEntitiesOfType", sender.getName(), numRemoved, entityName)); + }); + return null; + } +} \ No newline at end of file diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 3fc8551..2e4117a 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -64,8 +64,82 @@ global_gamerules: # Mob limiter/Entity wiping config # All entities listed here will NOT be wiped upon wiping entities +# By default this includes all mobs, as the mobpurge command can be used to purge mobs. entitywipe_list: - - "item_frame" + - "ITEM_FRAME" + - "AXOLOTL" + - "BAT" + - "BEE" + - "BLAZE" + - "CAT" + - "CAVE_SPIDER" + - "CHICKEN" + - "COD" + - "COW" + - "CREEPER" + - "DOLPHIN" + - "DONKEY" + - "DROWNED" + - "ELDER_GUARDIAN" + - "ENDER_DRAGON" + - "ENDERMAN" + - "ENDERMITE" + - "EVOKER" + - "FOX" + - "GHAST" + - "GIANT" + - "GLOW_SQUID" + - "GOAT" + - "GUARDIAN" + - "HOGLIN" + - "HORSE" + - "HUSK" + - "ILLUSIONER" + - "IRON_GOLEM" + - "LLAMA" + - "MAGMA_CUBE" + - "MULE" + - "MUSHROOM_COW" + - "OCELOT" + - "PANDA" + - "PARROT" + - "PHANTOM" + - "PIG" + - "PIGLIN" + - "PIGLIN_BRUTE" + - "PILLAGER" + - "POLAR_BEAR" + - "RABBIT" + - "RAVAGER" + - "SALMON" + - "SHEEP" + - "SHULKER" + - "SILVERFISH" + - "SKELETON" + - "SKELETON_HORSE" + - "SLIME" + - "SNOWMAN" + - "SPIDER" + - "SQUID" + - "STRAY" + - "STRIDER" + - "TRADER_LLAMA" + - "TROPICAL_FISH" + - "TURTLE" + - "VEX" + - "VILLAGER" + - "VINDICATOR" + - "WANDERING_TRADER" + - "WITCH" + - "WITHER" + - "WITHER_SKELETON" + - "WOLF" + - "ZOGLIN" + - "ZOMBIE" + - "ZOMBIE_HORSE" + - "ZOMBIE_VILLAGER" + - "ZOMBIFIED_PIGLIN" + - "PUFFERFISH" worlds: flatlands: diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 1cf9793..a6f6b5d 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -156,4 +156,7 @@ removedEntitiesOfTypes: "{0} - Removed {1} entities of type(s) {2}" removedEntitiesOfType: "Removed {1} {2}" # 0 - Entity type that is invalid invalidEntityType: "Notice: Entity type {0} is invalid!" -noRemovedEntities: "No entities were removed." \ No newline at end of file +noRemovedEntities: "No entities were removed." +# 0 - The command sender +# 1 - Number of mobs removed +removedMobs: "{0} - Removed {1} mobs" \ No newline at end of file