From 49e7fefe5fdcec96f6c0d92a0f5c38b7ca319bcc Mon Sep 17 00:00:00 2001 From: SBDeveloper Date: Fri, 29 Jul 2022 14:34:51 +0200 Subject: [PATCH] Fixed getEntity() NMS exception, closes #2 --- .../mapreflectionapi/api/MapWrapper.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java index 7e48ea9..4a85872 100644 --- a/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java +++ b/src/main/java/tech/sbdevelopment/mapreflectionapi/api/MapWrapper.java @@ -239,14 +239,17 @@ public class MapWrapper { @Override public ItemFrame getItemFrameById(World world, int entityId) { Object worldHandle = ReflectionUtil.getHandle(world); - Object nmsEntity = ReflectionUtil.callMethod(worldHandle, ReflectionUtil.supports(18) ? "a" : "getEntity"); + Object nmsEntity = ReflectionUtil.callMethod(worldHandle, ReflectionUtil.supports(18) ? "a" : "getEntity", entityId); if (nmsEntity == null) return null; - if (!ReflectionUtil.supports(17)) { - nmsEntity = ReflectionUtil.callMethod(nmsEntity, "getBukkitEntity"); - } + Object craftEntity = ReflectionUtil.callMethod(nmsEntity, "getBukkitEntity"); + if (craftEntity == null) return null; - if (nmsEntity instanceof ItemFrame) return (ItemFrame) nmsEntity; + Class itemFrameClass = ReflectionUtil.getNMSClass("world.entity.decoration", "EntityItemFrame"); + if (itemFrameClass == null) return null; + + if (craftEntity.getClass().isAssignableFrom(itemFrameClass)) + return (ItemFrame) itemFrameClass.cast(craftEntity); return null; }