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

EntityPlayer#spawnIn expects but cannot handle null values

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • This server is running CraftBukkit version 3736-Spigot-e4265cc-10f8667 (MC: 1.19.4) (Implementing API version 1.19.4-R0.1-SNAPSHOT)
    • Yes

      EntityPlayer#spawnIn expects to accept null Worlds.
      However, as the world is already assigned at the start of the method, the subsequent call to #getLevel always causes a NPE.

      The simplest fix is to replace this.getLevel().getCraftServer().getHandle().getServer() with this.server (not that the getter #getServer, which is inherited from Entity and calls getLevel().getServer()), but I believe the correct fix would be to also move the assignment to after the end of the null world handling, i.e.

          // CraftBukkit start - World fallback code, either respawn location or global spawn
          public void spawnIn(World world) {
              if (world == null) {
                  this.unsetRemoved();
                  Vec3D position = null;
                  if (this.respawnDimension != null) {
                      world = this.server.getLevel(this.respawnDimension);
                      if (world != null && this.getRespawnPosition() != null) {
                          position = EntityHuman.findRespawnPositionAndUseSpawnBlock((WorldServer) world, this.getRespawnPosition(), this.getRespawnAngle(), false, false).orElse(null);
                      }
                  }
                  if (world == null || position == null) {
                      world = ((CraftWorld) Bukkit.getServer().getWorlds().get(0)).getHandle();
                      position = Vec3D.atCenterOf(((WorldServer) world).getSharedSpawnPos());
                  }
                  this.setPos(position.x(), position.y(), position.z());
              }
              this.level = world;
              this.gameMode.setLevel((WorldServer) world);
           }
          // CraftBukkit end
      

      I understand that this is a niche issue that won't be hit by any vanilla code and doesn't actually need to be fixed for the server to function as expected, but it would make my life easier to not have to duplicate spawning logic for my use case.

            Doc Doc
            Jikoo Jikoo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: