1.13.2 Error during chunk generation

Discussion in 'Spigot Plugin Development' started by eirikh1996, Mar 28, 2020.

  1. Hello. I am trying to update an island world generator plugin to 1.13.2. I have finally got it enabling/disabling/loading without any problems. However, there is currently a problem I am stuck at. After the serer starts and it begins to load the spawn, the console gets spammed with this error:

    Code (Text):
    [01:46:44 ERROR]: Could not pass event ChunkLoadEvent to IslandCraft v1.0.8
    org.bukkit.event.EventException: null
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:316) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:66) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:507) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:492) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.Chunk.addEntities(Chunk.java:816) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_201]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:1556) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.MinecraftServer.postToMainThread(MinecraftServer.java:1565) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:103) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.World.getChunkAt(World.java:267) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.ChunkCache.<init>(SourceFile:44) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.NavigationAbstract.b(SourceFile:127) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.Navigation.b(SourceFile:68) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.NavigationAbstract.a(SourceFile:107) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.NavigationAbstract.a(SourceFile:157) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.PathfinderGoalRandomStroll.c(SourceFile:67) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.PathfinderGoalSelector.doTick(SourceFile:102) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityInsentient.doTick(EntityInsentient.java:659) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityLiving.movementTick(EntityLiving.java:2254) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityInsentient.movementTick(EntityInsentient.java:510) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityAgeable.movementTick(EntityAgeable.java:145) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityAnimal.movementTick(EntityAnimal.java:27) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntitySheep.movementTick(EntitySheep.java:95) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityLiving.tick(EntityLiving.java:2098) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.EntityInsentient.tick(EntityInsentient.java:248) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.World.entityJoinedWorld(World.java:1331) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.World.g(World.java:1298) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.World.tickEntities(World.java:1132) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.WorldServer.tickEntities(WorldServer.java:583) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:968) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_201]
    Caused by: java.lang.NoSuchMethodError: net.minecraft.server.v1_13_R2.WorldServer.getChunkProviderServer()Lnet/minecraft/server/v1_13_R2/ChunkProviderServer;
            at com.github.hoqhuuep.islandcraft.nms.v1_13_R2.NmsHandler.installBiomeGenerator(NmsHandler.java:20) ~[?:?]
            at com.github.hoqhuuep.islandcraft.bukkit.BiomeGeneratorListener.onChunkLoad(BiomeGeneratorListener.java:90) ~[?:?]
            at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source) ~[?:?]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_201]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_201]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:312) ~[spigot-1.13.2.jar:git-Spigot-1a3504a-a46fdbc]
            ... 33 more
    As one can see from the stacktrace, it shows that the problem is located in NmsHandler.java at line 20

    Here is how the method the problem occurs in:

    Code (Java):
    public boolean installBiomeGenerator(World world, BiomeGenerator biomeGenerator) {
            if (!(world instanceof CraftWorld)) {
                // Wrong version?
                return false;
            }
            final CraftWorld craftWorld = (CraftWorld) world;
            final WorldServer worldServer = craftWorld.getHandle();
            final ChunkGenerator<?> chunkGenerator = worldServer.worldProvider.getChunkGenerator();
            WorldChunkManager worldChunkManager = chunkGenerator.getWorldChunkManager();
            if (worldChunkManager instanceof CustomWorldChunkManager) {
                return false;
            }
            if (chunkGenerator instanceof ChunkGeneratorAbstract) {
                ChunkGeneratorAbstract<?> cgAbs = (ChunkGeneratorAbstract<?>) chunkGenerator;
                try {
                    Field cmField = cgAbs.getClass().getDeclaredField("c");
                    cmField.setAccessible(true);
                    cmField.set(chunkGenerator, new CustomWorldChunkManager(biomeGenerator));
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
            return true;
        }
    And the exact line 20 in the same class, which is part of the above method, looks like this:

    Code (Java):
    final CraftWorld craftWorld = (CraftWorld) world;
    What is actually happening here? And the fact that this happens at a line where the ONLY operation done is to cast a World variable to a CraftWorld variable makes this issue utterly confusing. What is happening here? And how can I get around this problem?
     
  2. you would access a null value