Skip to content

Commit

Permalink
🐛 Fixed entity initialization on 1.20.3
Browse files Browse the repository at this point in the history
  • Loading branch information
SkytAsul committed Nov 28, 2024
1 parent d79fc24 commit 13b1d7d
Showing 1 changed file with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,13 @@ protected static void loadReflection(@NotNull ReflectionAccessor reflection, @No

var entityClass = getNMSClass(reflection, "world.entity", "Entity");
var entityTypesClass = getNMSClass(reflection, "world.entity", "EntityType");

var worldInstance = version.isAfter(1, 21, 3) && cpack != null
? getCraftClass("", "CraftWorld").getDeclaredMethod("getHandle").invoke(Bukkit.getWorlds().get(0))
: null;
Object markerEntity = getNMSClass(reflection, "world.entity", "Marker")
.getConstructor(entityTypesClass, getNMSClass(reflection, "world.level", "Level"))
.newInstance(entityTypesClass.getField("MARKER").get(null), null);
.newInstance(entityTypesClass.getField("MARKER").get(null), worldInstance);

getHandle = cpack == null ? null : getCraftClass("entity", "CraftEntity").getDeclaredMethod("getHandle");
getDataWatcher = entityClass.getMethodInstance("getEntityData");
Expand Down Expand Up @@ -818,7 +822,7 @@ public static void removePacketsHandler(PlayerData playerData) throws Reflective

/* Reflection utils */
private static Class<?> getCraftClass(String craftPackage, String className) throws ClassNotFoundException {
return Class.forName(cpack + craftPackage + "." + className);
return Class.forName(cpack + (craftPackage.isBlank() ? "" : craftPackage + ".") + className);
}

private static @NotNull ClassAccessor getNMSClass(@NotNull ReflectionAccessor reflection, @NotNull String className)
Expand Down

0 comments on commit 13b1d7d

Please sign in to comment.