From 27345ecb20c7a6c76ba6fed2eed2aa3eacb1c3cc Mon Sep 17 00:00:00 2001 From: Alexander Date: Thu, 9 Oct 2025 04:55:00 +0100 Subject: [PATCH] Remove SpawnEggUtils This tends to get neglected. The only method that's used by outside code was getSpawnEgg() which is available on Bukkit's item factory class. This utility class has been obviated and thus can be removed. --- .../mc/civmodcore/CivModCorePlugin.java | 2 - .../inventory/items/SpawnEggUtils.java | 153 ------------------ .../hacks/CreeperDiscHack.java | 1 - .../hacks/basic/ArthropodEggHack.java | 9 +- 4 files changed, 7 insertions(+), 158 deletions(-) delete mode 100644 plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/SpawnEggUtils.java diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java index 6ea4735d0..206ebc4f4 100644 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java +++ b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/CivModCorePlugin.java @@ -11,7 +11,6 @@ import vg.civcraft.mc.civmodcore.dao.DatabaseCredentials; import vg.civcraft.mc.civmodcore.dao.ManagedDatasource; import vg.civcraft.mc.civmodcore.inventory.gui.ClickableInventoryListener; import vg.civcraft.mc.civmodcore.inventory.items.EnchantUtils; -import vg.civcraft.mc.civmodcore.inventory.items.SpawnEggUtils; import vg.civcraft.mc.civmodcore.players.PlayerNames; import vg.civcraft.mc.civmodcore.players.scoreboard.bottom.BottomLineAPI; import vg.civcraft.mc.civmodcore.players.scoreboard.side.ScoreBoardAPI; @@ -81,7 +80,6 @@ public class CivModCorePlugin extends ACivMod { this.commands.registerCommand(new ChunkMetaCommand()); // Load APIs EnchantUtils.loadEnchantAbbreviations(); - SpawnEggUtils.init(); BottomLineAPI.init(); this.skinCache = new SkinCache(this, this.config.getSkinCacheThreads()); diff --git a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/SpawnEggUtils.java b/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/SpawnEggUtils.java deleted file mode 100644 index 80658a16a..000000000 --- a/plugins/civmodcore-paper/src/main/java/vg/civcraft/mc/civmodcore/inventory/items/SpawnEggUtils.java +++ /dev/null @@ -1,153 +0,0 @@ -package vg.civcraft.mc.civmodcore.inventory.items; - -import com.google.common.collect.BiMap; -import com.google.common.collect.ImmutableBiMap; -import java.util.HashSet; -import java.util.Set; -import java.util.stream.Collectors; -import org.apache.commons.collections4.CollectionUtils; -import org.bukkit.Material; -import org.bukkit.entity.EntityType; -import org.jetbrains.annotations.Nullable; -import vg.civcraft.mc.civmodcore.utilities.CivLogger; - -/** - * Class of static APIs for Spawn Eggs. - */ -public final class SpawnEggUtils { - - private static final BiMap SPAWN_EGGS = ImmutableBiMap.builder() - .put(Material.AXOLOTL_SPAWN_EGG, EntityType.AXOLOTL) - .put(Material.ALLAY_SPAWN_EGG, EntityType.ALLAY) - .put(Material.BAT_SPAWN_EGG, EntityType.BAT) - .put(Material.BEE_SPAWN_EGG, EntityType.BEE) - .put(Material.BLAZE_SPAWN_EGG, EntityType.BLAZE) - .put(Material.BREEZE_SPAWN_EGG, EntityType.BREEZE) - .put(Material.CAT_SPAWN_EGG, EntityType.CAT) - .put(Material.CAMEL_SPAWN_EGG, EntityType.CAMEL) - .put(Material.CAVE_SPIDER_SPAWN_EGG, EntityType.CAVE_SPIDER) - .put(Material.CHICKEN_SPAWN_EGG, EntityType.CHICKEN) - .put(Material.COD_SPAWN_EGG, EntityType.COD) - .put(Material.COW_SPAWN_EGG, EntityType.COW) - .put(Material.CREEPER_SPAWN_EGG, EntityType.CREEPER) - .put(Material.DOLPHIN_SPAWN_EGG, EntityType.DOLPHIN) - .put(Material.DONKEY_SPAWN_EGG, EntityType.DONKEY) - .put(Material.DROWNED_SPAWN_EGG, EntityType.DROWNED) - .put(Material.ELDER_GUARDIAN_SPAWN_EGG, EntityType.ELDER_GUARDIAN) - .put(Material.ENDERMAN_SPAWN_EGG, EntityType.ENDERMAN) - .put(Material.ENDERMITE_SPAWN_EGG, EntityType.ENDERMITE) - .put(Material.ENDER_DRAGON_SPAWN_EGG, EntityType.ENDER_DRAGON) - .put(Material.EVOKER_SPAWN_EGG, EntityType.EVOKER) - .put(Material.FOX_SPAWN_EGG, EntityType.FOX) - .put(Material.FROG_SPAWN_EGG, EntityType.FROG) - .put(Material.GHAST_SPAWN_EGG, EntityType.GHAST) - .put(Material.GLOW_SQUID_SPAWN_EGG, EntityType.GLOW_SQUID) - .put(Material.GOAT_SPAWN_EGG, EntityType.GOAT) - .put(Material.GUARDIAN_SPAWN_EGG, EntityType.GUARDIAN) - .put(Material.HOGLIN_SPAWN_EGG, EntityType.HOGLIN) - .put(Material.HORSE_SPAWN_EGG, EntityType.HORSE) - .put(Material.HUSK_SPAWN_EGG, EntityType.HUSK) - .put(Material.IRON_GOLEM_SPAWN_EGG, EntityType.IRON_GOLEM) - .put(Material.LLAMA_SPAWN_EGG, EntityType.LLAMA) - .put(Material.MAGMA_CUBE_SPAWN_EGG, EntityType.MAGMA_CUBE) - .put(Material.MOOSHROOM_SPAWN_EGG, EntityType.MOOSHROOM) - .put(Material.MULE_SPAWN_EGG, EntityType.MULE) - .put(Material.OCELOT_SPAWN_EGG, EntityType.OCELOT) - .put(Material.PANDA_SPAWN_EGG, EntityType.PANDA) - .put(Material.PARROT_SPAWN_EGG, EntityType.PARROT) - .put(Material.PHANTOM_SPAWN_EGG, EntityType.PHANTOM) - .put(Material.PIG_SPAWN_EGG, EntityType.PIG) - .put(Material.PIGLIN_BRUTE_SPAWN_EGG, EntityType.PIGLIN_BRUTE) - .put(Material.PIGLIN_SPAWN_EGG, EntityType.PIGLIN) - .put(Material.PILLAGER_SPAWN_EGG, EntityType.PILLAGER) - .put(Material.POLAR_BEAR_SPAWN_EGG, EntityType.POLAR_BEAR) - .put(Material.PUFFERFISH_SPAWN_EGG, EntityType.PUFFERFISH) - .put(Material.RABBIT_SPAWN_EGG, EntityType.RABBIT) - .put(Material.RAVAGER_SPAWN_EGG, EntityType.RAVAGER) - .put(Material.SALMON_SPAWN_EGG, EntityType.SALMON) - .put(Material.SHEEP_SPAWN_EGG, EntityType.SHEEP) - .put(Material.SHULKER_SPAWN_EGG, EntityType.SHULKER) - .put(Material.SILVERFISH_SPAWN_EGG, EntityType.SILVERFISH) - .put(Material.SKELETON_HORSE_SPAWN_EGG, EntityType.SKELETON_HORSE) - .put(Material.SKELETON_SPAWN_EGG, EntityType.SKELETON) - .put(Material.SLIME_SPAWN_EGG, EntityType.SLIME) - .put(Material.SNIFFER_SPAWN_EGG, EntityType.SNIFFER) - .put(Material.SNOW_GOLEM_SPAWN_EGG, EntityType.SNOW_GOLEM) - .put(Material.SPIDER_SPAWN_EGG, EntityType.SPIDER) - .put(Material.SQUID_SPAWN_EGG, EntityType.SQUID) - .put(Material.STRAY_SPAWN_EGG, EntityType.STRAY) - .put(Material.STRIDER_SPAWN_EGG, EntityType.STRIDER) - .put(Material.TADPOLE_SPAWN_EGG, EntityType.TADPOLE) - .put(Material.TRADER_LLAMA_SPAWN_EGG, EntityType.TRADER_LLAMA) - .put(Material.TROPICAL_FISH_SPAWN_EGG, EntityType.TROPICAL_FISH) - .put(Material.TURTLE_SPAWN_EGG, EntityType.TURTLE) - .put(Material.VEX_SPAWN_EGG, EntityType.VEX) - .put(Material.VILLAGER_SPAWN_EGG, EntityType.VILLAGER) - .put(Material.VINDICATOR_SPAWN_EGG, EntityType.VINDICATOR) - .put(Material.WANDERING_TRADER_SPAWN_EGG, EntityType.WANDERING_TRADER) - .put(Material.WARDEN_SPAWN_EGG, EntityType.WARDEN) - .put(Material.WITCH_SPAWN_EGG, EntityType.WITCH) - .put(Material.WITHER_SKELETON_SPAWN_EGG, EntityType.WITHER_SKELETON) - .put(Material.WITHER_SPAWN_EGG, EntityType.WITHER) - .put(Material.WOLF_SPAWN_EGG, EntityType.WOLF) - .put(Material.ZOGLIN_SPAWN_EGG, EntityType.ZOGLIN) - .put(Material.ZOMBIE_SPAWN_EGG, EntityType.ZOMBIE) - .put(Material.ZOMBIE_HORSE_SPAWN_EGG, EntityType.ZOMBIE_HORSE) - .put(Material.ZOMBIFIED_PIGLIN_SPAWN_EGG, EntityType.ZOMBIFIED_PIGLIN) - .put(Material.ZOMBIE_VILLAGER_SPAWN_EGG, EntityType.ZOMBIE_VILLAGER) - .build(); - - public static void init() { - final var logger = CivLogger.getLogger(SpawnEggUtils.class); - // Determine if there's any enchants missing names - final Set missing = new HashSet<>(); - CollectionUtils.addAll(missing, Material.values()); - missing.removeIf(material -> !material.name().endsWith("_SPAWN_EGG") || SPAWN_EGGS.containsKey(material)); - if (!missing.isEmpty()) { - logger.warning("The following spawn eggs are missing: " + - missing.stream().map(Enum::name).collect(Collectors.joining(",")) + "."); - } - } - - /** - * Tests if a material is that of a spawn egg. - * - * @param material The material to test. - * @return Returns true if the material is that of a spawn egg. - */ - public static boolean isSpawnEgg(final Material material) { - if (material == null) { - return false; - } - return SPAWN_EGGS.containsKey(material); - } - - /** - * Gets the spawned entity type for a spawn egg. - * - * @param material The material, must be a spawn egg otherwise it's a guaranteed null. - * @return Returns the entity type that will be spawned from the spawn egg, or null. - */ - @Nullable - public static EntityType getEntityType(final Material material) { - if (material == null) { - return null; - } - return SPAWN_EGGS.get(material); - } - - /** - * Gets the spawn egg material from an entity type. - * - * @param type The type of entity to match to the spawn egg. - * @return Returns a spawn egg material, or null. - */ - @Nullable - public static Material getSpawnEgg(final EntityType type) { - if (type == null) { - return null; - } - return SPAWN_EGGS.inverse().get(type); - } - -} diff --git a/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/CreeperDiscHack.java b/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/CreeperDiscHack.java index babdc9f3d..96c50ce91 100644 --- a/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/CreeperDiscHack.java +++ b/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/CreeperDiscHack.java @@ -12,7 +12,6 @@ import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; -import vg.civcraft.mc.civmodcore.inventory.items.SpawnEggUtils; import java.util.Iterator; import java.util.List; diff --git a/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/basic/ArthropodEggHack.java b/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/basic/ArthropodEggHack.java index 156a3a2d4..19084f612 100644 --- a/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/basic/ArthropodEggHack.java +++ b/plugins/simpleadminhacks-paper/src/main/java/com/programmerdan/minecraft/simpleadminhacks/hacks/basic/ArthropodEggHack.java @@ -6,13 +6,14 @@ import com.programmerdan.minecraft.simpleadminhacks.framework.BasicHackConfig; import com.programmerdan.minecraft.simpleadminhacks.framework.autoload.AutoLoad; import java.util.List; import java.util.Map; +import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.enchantments.Enchantment; import org.bukkit.entity.Ageable; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.entity.EntityDeathEvent; import org.bukkit.inventory.ItemStack; -import vg.civcraft.mc.civmodcore.inventory.items.SpawnEggUtils; public class ArthropodEggHack extends BasicHack { @@ -73,7 +74,11 @@ public class ArthropodEggHack extends BasicHack { // Check if egg should be spawned if (randomNum < targetPercentage) { - ItemStack item = new ItemStack(SpawnEggUtils.getSpawnEgg(event.getEntityType()), 1); + final Material spawnEggMaterial = Bukkit.getItemFactory().getSpawnEgg(event.getEntityType()); + if (spawnEggMaterial == null) { + return; + } + ItemStack item = ItemStack.of(spawnEggMaterial, 1); if (removeDrops) { event.getDrops().clear(); event.setDroppedExp(0);