InventivetalentDev / CompactNPCLib

Library to create NPCs
MIT License
22 stars 9 forks source link

1.11 support #26

Closed null321-jared closed 7 years ago

null321-jared commented 7 years ago

NPCLib and its dependencies do not support 1.11.

At first it did this when it tried to inject the entities:

[18:20:36] [Server thread/ERROR]: java.lang.RuntimeException: java.lang.NullPointerException initializing NPCLib v2.2.6 (Is it up to date?)
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NullPointerException
    at org.inventivetalent.npclib.registry.NPCRegistry.getOrGenerateClass(NPCRegistry.java:95) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.injectClasses(NPCRegistry.java:78) ~[?:?]
    at org.inventivetalent.npclib.NPCLib.load(NPCLib.java:87) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:102) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:122) ~[?:?]
    at org.inventivetalent.npclib.NPCLibPlugin.onLoad(NPCLibPlugin.java:21) ~[?:?]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:305) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:542) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
Caused by: java.lang.RuntimeException: java.lang.NullPointerException
    at org.inventivetalent.reflection.resolver.wrapper.FieldWrapper.get(FieldWrapper.java:54) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.injectEntity(NPCRegistry.java:103) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.getOrGenerateClass(NPCRegistry.java:91) ~[?:?]
    ... 9 more
Caused by: java.lang.NullPointerException
    at org.inventivetalent.reflection.resolver.wrapper.FieldWrapper.get(FieldWrapper.java:52) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.injectEntity(NPCRegistry.java:103) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.getOrGenerateClass(NPCRegistry.java:91) ~[?:?]
    ... 9 more

Then I updated it to support 1.11's new way of storing the entitytypes using this code:

static void injectEntity(Class<?> clazz, int id, String name) {
    Class<?> EntityTypes = Reflection.nmsClassResolver.resolveSilent("EntityTypes");
    if(Minecraft.VERSION.newerThan(Minecraft.Version.v1_11_R1)) {
        MethodResolver methodResolver = new MethodResolver(EntityTypes);
        MethodWrapper method = methodResolver.resolveWrapper(new ResolverQuery("a", int.class,
                String.class, Class.class, String.class));
        if(method.exists()) {
            method.getMethod().setAccessible(true);
            method.invoke(null, id, name, clazz, name);
        } else {
            NPCLib.logger.warning("Could not inject " + clazz.getSimpleName() + " as " + name +
                    " with id " + id + " due to incompatible Minecraft verson!");
        }
    } else {
        FieldResolver fieldResolver = new FieldResolver(EntityTypes);
        ((Map) fieldResolver.resolveWrapper("c").get(null)).put(name, clazz);
        ((Map) fieldResolver.resolveWrapper("d").get(null)).put(clazz, name);
        ((Map) fieldResolver.resolveWrapper("f").get(null)).put(clazz, Integer.valueOf(id));
    }
    NPCLib.logger.info("Injected " + clazz.getSimpleName() + " as " + name + " with id " + id);
}

(I have no idea if that even works as intended, I don't even know what the injection does! I commented it out and everything appeared to work..)

Then I got this error:

[11:50:30] [Server thread/WARN]: [ReflectionHelper] Failed to find version enum for 'org.bukkit.craftbukkit.v1_11_R1'/'v1_11_R1.'
[11:50:30] [Server thread/INFO]: [ReflectionHelper] Generating dynamic constant...
[11:50:30] [Server thread/INFO]: [ReflectionHelper] Injected dynamic version v1_11_R1 (#10101).
[11:50:30] [Server thread/INFO]: [ReflectionHelper] Please inform inventivetalent about the outdated version, as this is not guaranteed to work.
[11:50:30] [Server thread/INFO]: [ReflectionHelper] Version is v1_11_R1 (10101)
[11:50:31] [Server thread/ERROR]: v1_11_R1 initializing NPCLib v2.2.6 (Is it up to date?)
java.lang.NoSuchFieldError: v1_11_R1
    at org.inventivetalent.npclib.registry.NPCRegistry.injectEntity(NPCRegistry.java:104) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.getOrGenerateClass(NPCRegistry.java:94) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.injectClasses(NPCRegistry.java:81) ~[?:?]
    at org.inventivetalent.npclib.NPCLib.load(NPCLib.java:87) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:102) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:122) ~[?:?]
    at org.inventivetalent.npclib.NPCLibPlugin.onLoad(NPCLibPlugin.java:21) ~[?:?]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:305) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:542) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]

Then I told it to use the newer version of ReflectionHelper Then I got:

[12:02:54] [Server thread/ERROR]: null initializing NPCLib v2.2.6 (Is it up to date?)
java.lang.ExceptionInInitializerError
    at org.inventivetalent.npclib.ClassGenerator.generateEntityClass(ClassGenerator.java:26) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.getOrGenerateClass(NPCRegistry.java:91) ~[?:?]
    at org.inventivetalent.npclib.registry.NPCRegistry.injectClasses(NPCRegistry.java:81) ~[?:?]
    at org.inventivetalent.npclib.NPCLib.load(NPCLib.java:87) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:102) ~[?:?]
    at org.inventivetalent.apihelper.APIManager.registerAPI(APIManager.java:122) ~[?:?]
    at org.inventivetalent.npclib.NPCLibPlugin.onLoad(NPCLibPlugin.java:21) ~[?:?]
    at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:305) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.DedicatedServer.init(DedicatedServer.java:204) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:542) [spigot.jar:git-Spigot-f950f8e-b64d852]
    at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72]
Caused by: java.lang.RuntimeException: java.lang.ClassNotFoundException: Could not resolve class for [ResolverQuery{name='org.bukkit.craftbukkit.UNKNOWN.entity.CraftEntity', types=[]}]
    at org.inventivetalent.reflection.minecraft.Minecraft.<clinit>(Minecraft.java:64) ~[?:?]
    ... 11 more
Caused by: java.lang.ClassNotFoundException: Could not resolve class for [ResolverQuery{name='org.bukkit.craftbukkit.UNKNOWN.entity.CraftEntity', types=[]}]
    at org.inventivetalent.reflection.resolver.ClassResolver.notFoundException(ClassResolver.java:68) ~[?:?]
    at org.inventivetalent.reflection.resolver.ClassResolver.notFoundException(ClassResolver.java:36) ~[?:?]
    at org.inventivetalent.reflection.resolver.ResolverAbstract.resolve(ResolverAbstract.java:88) ~[?:?]
    at org.inventivetalent.reflection.resolver.ClassResolver.resolve(ClassResolver.java:55) ~[?:?]
    at org.inventivetalent.reflection.resolver.minecraft.OBCClassResolver.resolve(OBCClassResolver.java:46) ~[?:?]
    at org.inventivetalent.reflection.minecraft.Minecraft.<clinit>(Minecraft.java:62) ~[?:?]
    ... 11 more

Then I tried updating PacketListener to 1.11 and it appeared to have worked. Then I created a playerNPC, told it to move and got this when my plugin ran: generated an exception java.lang.AbstractMethodError: org.inventivetalent.npclib.generated.entity.NPCEntityPlayer.move(DDD)V

And I have no idea what caused that so I decided to make this issue because you know a lot about the inner workings of this plugin because you designed it.

I tried to update it, I spent many hours on it today, but I just don't know enough about the code to update it in a timely manner.

null321-jared commented 7 years ago

@InventivetalentDev If you do not want to update this, can you please help me understand some of the things about this plugin so I can update it properly?

What is the point of the injection? I commented it out and nothing appeared to change.

I have been on the Spigot IRC, so we can talk about this there.