From ebf66ce1b01128cb35076e710605fb37856fdddf Mon Sep 17 00:00:00 2001 From: libraryaddict Date: Sat, 30 Nov 2024 11:00:35 +1300 Subject: [PATCH] Fix apparently a long standing issue where getNewEntityId wasn't working in 1.14+ as per #786 --- .../utilities/reflection/v1_17/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_18_1/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_18_2/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_19_R1/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_19_R2/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_19_R3/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_20_R1/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_20_R2/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_20_R3/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_20_R4/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_21_R1/ReflectionManager.java | 3 ++- .../utilities/reflection/v1_21_R2/ReflectionManager.java | 3 ++- .../main/java/me/libraryaddict/disguise/DisguiseAPI.java | 1 + .../disguise/utilities/reflection/ReflectionManager.java | 8 ++++++++ 14 files changed, 33 insertions(+), 12 deletions(-) diff --git a/nms/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java b/nms/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java index 4e6effb7..c262ddea 100644 --- a/nms/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java +++ b/nms/v1_17_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_17/ReflectionManager.java @@ -92,7 +92,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_1/ReflectionManager.java b/nms/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_1/ReflectionManager.java index 7dbf977f..08fbe170 100644 --- a/nms/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_1/ReflectionManager.java +++ b/nms/v1_18_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_1/ReflectionManager.java @@ -92,7 +92,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_18_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_2/ReflectionManager.java b/nms/v1_18_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_2/ReflectionManager.java index 4e4fd74b..bd70cbd6 100644 --- a/nms/v1_18_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_2/ReflectionManager.java +++ b/nms/v1_18_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_18_2/ReflectionManager.java @@ -94,7 +94,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_19_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R1/ReflectionManager.java b/nms/v1_19_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R1/ReflectionManager.java index 0902ed59..2928343f 100644 --- a/nms/v1_19_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R1/ReflectionManager.java +++ b/nms/v1_19_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R1/ReflectionManager.java @@ -93,7 +93,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_19_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R2/ReflectionManager.java b/nms/v1_19_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R2/ReflectionManager.java index 718cf4ce..6edad5a5 100644 --- a/nms/v1_19_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R2/ReflectionManager.java +++ b/nms/v1_19_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R2/ReflectionManager.java @@ -108,7 +108,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_19_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R3/ReflectionManager.java b/nms/v1_19_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R3/ReflectionManager.java index 4d67ae48..5832f02f 100644 --- a/nms/v1_19_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R3/ReflectionManager.java +++ b/nms/v1_19_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_19_R3/ReflectionManager.java @@ -107,7 +107,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_20_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R1/ReflectionManager.java b/nms/v1_20_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R1/ReflectionManager.java index 1e30ffe3..393bbf79 100644 --- a/nms/v1_20_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R1/ReflectionManager.java +++ b/nms/v1_20_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R1/ReflectionManager.java @@ -107,7 +107,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return atomicInteger.incrementAndGet(); } else { - return atomicInteger.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return atomicInteger.get() + 1; } } catch (ReflectiveOperationException e) { e.printStackTrace(); diff --git a/nms/v1_20_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R2/ReflectionManager.java b/nms/v1_20_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R2/ReflectionManager.java index 7f9c1341..51d91f48 100644 --- a/nms/v1_20_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R2/ReflectionManager.java +++ b/nms/v1_20_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R2/ReflectionManager.java @@ -130,7 +130,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return entityCounter.incrementAndGet(); } else { - return entityCounter.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return entityCounter.get() + 1; } } diff --git a/nms/v1_20_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R3/ReflectionManager.java b/nms/v1_20_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R3/ReflectionManager.java index c8cd5617..9d76546c 100644 --- a/nms/v1_20_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R3/ReflectionManager.java +++ b/nms/v1_20_R3/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R3/ReflectionManager.java @@ -130,7 +130,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return entityCounter.incrementAndGet(); } else { - return entityCounter.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return entityCounter.get() + 1; } } diff --git a/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java b/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java index 408957c8..5c4906e7 100644 --- a/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java +++ b/nms/v1_20_R4/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_20_R4/ReflectionManager.java @@ -133,7 +133,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return entityCounter.incrementAndGet(); } else { - return entityCounter.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return entityCounter.get() + 1; } } diff --git a/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java b/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java index ebe335f3..1f0745a6 100644 --- a/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java +++ b/nms/v1_21_R1/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R1/ReflectionManager.java @@ -138,7 +138,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return entityCounter.incrementAndGet(); } else { - return entityCounter.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return entityCounter.get() + 1; } } diff --git a/nms/v1_21_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R2/ReflectionManager.java b/nms/v1_21_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R2/ReflectionManager.java index fa3e78da..4fdcd6c0 100644 --- a/nms/v1_21_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R2/ReflectionManager.java +++ b/nms/v1_21_R2/src/main/java/me/libraryaddict/disguise/utilities/reflection/v1_21_R2/ReflectionManager.java @@ -140,7 +140,8 @@ public class ReflectionManager implements ReflectionManagerAbstract { if (increment) { return entityCounter.incrementAndGet(); } else { - return entityCounter.get(); + // Add 1 as we didn't increment the counter and thus this is currently pointing to the last entity id used + return entityCounter.get() + 1; } } diff --git a/plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java b/plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java index 84c6e719..2f85d185 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/DisguiseAPI.java @@ -269,6 +269,7 @@ public class DisguiseAPI { } int id = ReflectionManager.getNewEntityId(false); + DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise); return id; diff --git a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java index 311aa151..5e688158 100644 --- a/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java +++ b/plugin/src/main/java/me/libraryaddict/disguise/utilities/reflection/ReflectionManager.java @@ -604,6 +604,10 @@ public class ReflectionManager { } public static int getNewEntityId(boolean increment) { + // From earlier versions up to 1.13, entityId = entityCounter++ + // From 1.14 and onwards, entityId = entityCounter.incrementAndGet() + // Obviously, they are very different. + if (nmsReflection != null) { return nmsReflection.getNewEntityId(increment); } @@ -623,6 +627,10 @@ public class ReflectionManager { } } + if (NmsVersion.v1_14.isSupported()) { + return entityCount.intValue() + 1; + } + return entityCount.intValue(); } catch (IllegalAccessException e) { e.printStackTrace();