SkytAsul / GlowingEntities

An API to easily make Minecraft entities glow. No dependencies, compatible 1.17 -> 1.21.
MIT License
69 stars 10 forks source link

API failing to load on Paper 1.21.3 #26

Closed Pro4D closed 1 day ago

Pro4D commented 5 days ago

When loading the library on a fresh Paper/Purpur 1.21.3 server, it fails to initialize and then returns this error:


[GlowingEntities] Found server version 1.21.3
[GlowingEntities] Loaded transparent mappings.
[GlowingEntities] Glowing Entities reflection failed to initialize. The util is disabled. Please ensure your version (1.21.3-R0.1-SNAPSHOT) is supported.
java.lang.reflect.InvocationTargetException: null
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:72) ~[?:?]
    at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502) ~[?:?]
    at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486) ~[?:?]
    at BlissGems-2.0.0-ALPHA.jar/fr.skytasul.reflection.TransparentReflectionAccessor$TransparentConstructor.newInstance(TransparentReflectionAccessor.java:157) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.quickmc.glowingentities.GlowingEntities$Packets.loadReflection(GlowingEntities.java:447) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.quickmc.glowingentities.GlowingEntities$Packets.initialize(GlowingEntities.java:421) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.quickmc.glowingentities.GlowingEntities$Packets.ensureInitialized(GlowingEntities.java:366) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.quickmc.glowingentities.GlowingEntities.<init>(GlowingEntities.java:58) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.quickmc.QuickMC.init(QuickMC.java:67) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at BlissGems-2.0.0-ALPHA.jar/com.blissgems.BlissGems.onEnable(BlissGems.java:191) ~[BlissGems-2.0.0-ALPHA.jar:?]
    at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:288) ~[paper-api-1.21.3-R0.1-SNAPSHOT.jar:?]
    at io.papermc.paper.plugin.manager.PaperPluginInstanceManager.enablePlugin(PaperPluginInstanceManager.java:202) ~[paper-1.21.3.jar:1.21.3-63-4190ee7]
    at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]
Caused by: java.lang.NullPointerException: Cannot invoke "net.minecraft.world.level.Level.paperConfig()" because "world" is null
    at net.minecraft.world.entity.Entity.<init>(Entity.java:618) ~[paper-1.21.3.jar:1.21.3-63-4190ee7]
    at net.minecraft.world.entity.Marker.<init>(Marker.java:18) ~[paper-1.21.3.jar:1.21.3-63-4190ee7]
    at java.base/jdk.internal.reflect.DirectConstructorHandleAccessor.newInstance(DirectConstructorHandleAccessor.java:62) ~[?:?]
    ... 21 more

After experimenting, I've found the error is due to passing in a null World when initializing reflection and creating the markerEntity variable.

This was my working solution, the code is a bit rough:

    Object worldRef;

    try {
                worldRef = Class.forName(cpack + "CraftWorld").getDeclaredMethod("getHandle").invoke(Bukkit.getWorlds().get(0));

    } catch (NoSuchMethodException | ClassNotFoundException | InvocationTargetException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }

    var entityClass = getNMSClass(reflection, "world.entity", "Entity");
    var entityTypesClass = getNMSClass(reflection, "world.entity", "EntityType");
    Object markerEntity = getNMSClass(reflection, "world.entity", "Marker")
        .getConstructor(entityTypesClass, getNMSClass(reflection, "world.level", "World"))
        .newInstance(entityTypesClass.getField("MARKER").get(null), worldRef);
Ayont commented 4 days ago

Having the same issue.

SkytAsul commented 1 day ago

Fixed in 1.4.1