Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5631

PlayerList#moveToWorld can cause an NPE

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: Minor Minor
    • None
    • None
    • None
    • git-Spigot-a03b1fd-fc318cc
    • DungeonsXL
    • Yes

      Context

      My plugin does the following:

      • Copy a world folder into the root directory
      • * Load the world-
      • Teleport the player into the world
      • Let the player do things in the world until he leaves
      • Unload the world, save it elsewhere and delete the world folder in the root directory

      The first three things happen in the same tick.

      The problem

      Even though the world loads without issues for the first time, after unloading it and loading a newly copied one with the same name, teleporting the player into it causes an NPE.

      Checking blocks, getting locations etc. in the world works without problems, and debbuging the plugin prints the target location in the newly loaded world as "Location{world=CraftWorld

      {name=DXL_Edit_0},x=80.0,y=4.0,z=192.0,pitch=0.0,yaw=0.0}". 

       
      
      

      [19:28:54] [Server thread/INFO]: Sataniel issued server command: /dxl edit Test
      [19:28:54] [Server thread/INFO]: DEditWorld{name=Test}
      [19:28:54] [Server thread/INFO]: CraftWorld{name=DXL_Edit_0}

      [19:28:54] [Server thread/INFO]: Location{world=CraftWorld

      {name=DXL_Edit_0}

      ,x=80.0,y=4.0,z=192.0,pitch=0.0,yaw=0.0}
      [19:28:54] [Server thread/ERROR]: null
      org.bukkit.command.CommandException: Unhandled exception executing command 'dxl' in plugin DungeonsXL v0.18-SNAPSHOT
      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:47) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:149) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at org.bukkit.craftbukkit.v1_15_R1.CraftServer.dispatchCommand(CraftServer.java:723) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.PlayerConnection.handleCommand(PlayerConnection.java:1658) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1498) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:47) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.PacketPlayInChat.a(PacketPlayInChat.java:1) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:918) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:911) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:895) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:828) [spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at java.lang.Thread.run(Thread.java:748) [?:1.8.0_241]
      Caused by: java.lang.NullPointerException
      at net.minecraft.server.v1_15_R1.PlayerList.moveToWorld(PlayerList.java:644) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer.teleport(CraftPlayer.java:672) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at org.bukkit.craftbukkit.v1_15_R1.entity.CraftEntity.teleport(CraftEntity.java:453) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      at de.erethon.commons.player.PlayerUtil.secureTeleport(PlayerUtil.java:89) ~[?:?]
      at de.erethon.dungeonsxl.player.DEditPlayer.<init>(DEditPlayer.java:62) ~[?:?]
      at de.erethon.dungeonsxl.command.EditCommand.onExecute(EditCommand.java:81) ~[?:?]
      at de.erethon.commons.command.DRECommandExecutor.onCommand(DRECommandExecutor.java:67) ~[?:?]
      at org.bukkit.command.PluginCommand.execute(PluginCommand.java:45) ~[spigot-1.15.2.jar:git-Spigot-a03b1fd-fc318cc]
      ... 17 more

      
      

      The NPE occurs at this line in PlayerList:

      location.setWorld(server.getWorldServer(dimensionmanager).getWorld());

       

      If the server code is stretched like this:

      644 location.

      645 setWorld(

      646 server

      647 .getWorldServer(dimensionmanager)

      648 .getWorld());

      the NPE occurs at line 648, so getWorldServer(dimensionmanager) must be null for some reason.

       

      Plugin source: https://github.com/DRE2N/DungeonsXL/blob/master/core/src/main/java/de/erethon/dungeonsxl/player/DEditPlayer.java (the version used for this has three printlns between 57 and 58) and https://github.com/DRE2N/DRECommons/blob/master/core/src/main/java/de/erethon/commons/player/PlayerUtil.java#L78

       

      I hope you can help, thank you for all of the good work so far

      Edit: It turned out I messed up at some point and kept a reference to a World object when the World was already unloaded.

            Unassigned Unassigned
            Sataniel Daniel Saukel
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: