From 8982c0af295bb4e61135455dcca8bc2be7ae3946 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Fri, 3 Mar 2023 17:19:37 +0100 Subject: [PATCH] Experimental ReflectionFix --- .../com/comphenix/tinyprotocol/Reflection.java | 15 +++++++++++---- .../src/de/steamwar/entity/REntity.java | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java index e4176ad..882c62f 100644 --- a/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java +++ b/SpigotCore_Main/src/com/comphenix/tinyprotocol/Reflection.java @@ -63,6 +63,7 @@ public final class Reflection { * @param value - the new value of the field. */ void set(Object target, Object value); + void setInt(Object target, int value); /** * Determine if the given object has this field. @@ -156,10 +157,16 @@ public final class Reflection { @Override public void set(Object target, Object value) { try { - if(field.getDeclaringClass() == int.class) - field.setInt(target, (int)value); - else - field.set(target, value); + field.set(target, value); + } catch (IllegalAccessException e) { + throw new IllegalArgumentException("Cannot access reflection.", e); + } + } + + @Override + public void setInt(Object target, int value) { + try { + field.setInt(target, value); } catch (IllegalAccessException e) { throw new IllegalArgumentException("Cannot access reflection.", e); } diff --git a/SpigotCore_Main/src/de/steamwar/entity/REntity.java b/SpigotCore_Main/src/de/steamwar/entity/REntity.java index 83dc391..f087e27 100644 --- a/SpigotCore_Main/src/de/steamwar/entity/REntity.java +++ b/SpigotCore_Main/src/de/steamwar/entity/REntity.java @@ -355,7 +355,7 @@ public class REntity { protected Object getDataWatcherPacket(Object... dataWatcherKeyValues) { Object packet = Reflection.newInstance(metadataPacket); - metadataEntity.set(packet, entityId); + metadataEntity.setInt(packet, entityId); ArrayList nativeWatchers = new ArrayList<>(1); for(int i = 0; i < dataWatcherKeyValues.length; i+=2) {