From 04feed8524daa7dfc7a386df05de9f3892ff1ff6 Mon Sep 17 00:00:00 2001 From: md678685 Date: Wed, 15 Aug 2018 17:46:55 +0100 Subject: [PATCH] Add 1.13+ spawn egg provider Not sure how necessary this is, but I've done it anyway --- .../com/earth2me/essentials/Essentials.java | 2 ++ .../nms/flattened/FlatSpawnEggProvider.java | 31 +++++++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 nms/FlattenedProvider/src/net/ess3/nms/flattened/FlatSpawnEggProvider.java diff --git a/Essentials/src/com/earth2me/essentials/Essentials.java b/Essentials/src/com/earth2me/essentials/Essentials.java index f54cb2e0c..eaa0a5dfa 100644 --- a/Essentials/src/com/earth2me/essentials/Essentials.java +++ b/Essentials/src/com/earth2me/essentials/Essentials.java @@ -39,6 +39,7 @@ import net.ess3.nms.PotionMetaProvider; import net.ess3.nms.SpawnEggProvider; import net.ess3.nms.SpawnerProvider; import net.ess3.nms.flattened.FlatItemDbProvider; +import net.ess3.nms.flattened.FlatSpawnEggProvider; import net.ess3.nms.ids.LegacyItemDbProvider; import net.ess3.nms.legacy.LegacyPotionMetaProvider; import net.ess3.nms.refl.ReflSpawnEggProvider; @@ -230,6 +231,7 @@ public class Essentials extends JavaPlugin implements net.ess3.api.IEssentials { ), "mob spawner").getProvider(); spawnEggProvider = new ProviderFactory<>(getLogger(), Arrays.asList( + FlatSpawnEggProvider.class, ReflSpawnEggProvider.class, LegacySpawnEggProvider.class ), "spawn egg").getProvider(); diff --git a/nms/FlattenedProvider/src/net/ess3/nms/flattened/FlatSpawnEggProvider.java b/nms/FlattenedProvider/src/net/ess3/nms/flattened/FlatSpawnEggProvider.java new file mode 100644 index 000000000..5ea4402e0 --- /dev/null +++ b/nms/FlattenedProvider/src/net/ess3/nms/flattened/FlatSpawnEggProvider.java @@ -0,0 +1,31 @@ +package net.ess3.nms.flattened; + +import net.ess3.nms.SpawnEggProvider; +import net.ess3.nms.refl.ReflUtil; +import org.bukkit.Material; +import org.bukkit.entity.EntityType; +import org.bukkit.inventory.ItemStack; + +public class FlatSpawnEggProvider extends SpawnEggProvider { + @Override + public ItemStack createEggItem(EntityType type) throws IllegalArgumentException { + String name = type.name() + "_SPAWN_EGG"; + Material material = Material.valueOf(name); + return new ItemStack(material); + } + + @Override + public EntityType getSpawnedType(ItemStack eggItem) throws IllegalArgumentException { + String materialName = eggItem.getType().name(); + if (materialName.contains("_SPAWN_EGG")) { + return EntityType.valueOf(materialName.replace("_SPAWN_EGG", "")); + } else { + throw new IllegalArgumentException("Not a spawn egg"); + } + } + + @Override + public String getHumanName() { + return "1.13+ flat spawn egg provider"; + } +}