mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-23 09:37:50 +01:00
Add 1.13+ spawn egg provider
Not sure how necessary this is, but I've done it anyway
This commit is contained in:
parent
773979cb37
commit
04feed8524
@ -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();
|
||||
|
@ -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";
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user