From c1e2f23f94711bb42c17b29a9eb7c6ad4ceff4f4 Mon Sep 17 00:00:00 2001 From: Pierre Maurice Schwang Date: Fri, 12 Apr 2024 20:55:58 +0200 Subject: [PATCH] Fix error on adapting custom entities / entity types (#2674) chore/fix: entity type adaption, more in line with upstream --- .../bukkit/adapter/IBukkitAdapter.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java index 29162b607..9792f9344 100644 --- a/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java +++ b/worldedit-bukkit/src/main/java/com/fastasyncworldedit/bukkit/adapter/IBukkitAdapter.java @@ -31,6 +31,8 @@ import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; import org.bukkit.Bukkit; import org.bukkit.Material; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.TreeType; import org.bukkit.block.Biome; import org.bukkit.block.data.BlockData; @@ -186,10 +188,12 @@ public interface IBukkitAdapter { } default org.bukkit.entity.EntityType adapt(EntityType entityType) { - if (!entityType.getId().startsWith("minecraft:")) { - throw new IllegalArgumentException("Bukkit only supports vanilla entities"); + NamespacedKey entityKey = NamespacedKey.fromString(entityType.toString()); + if (entityKey == null) { + throw new IllegalArgumentException("Entity key '" + entityType + "' does not map to Bukkit"); } - return org.bukkit.entity.EntityType.fromName(entityType.getId().substring(10).toLowerCase(Locale.ROOT)); + + return Registry.ENTITY_TYPE.get(entityKey); } /** @@ -343,7 +347,7 @@ public interface IBukkitAdapter { * @return WorldEdit EntityType */ default EntityType adapt(org.bukkit.entity.EntityType entityType) { - return EntityTypes.get(entityType.getName().toLowerCase(Locale.ROOT)); + return EntityTypes.get(entityType.getKey().toString()); } /**