title: CraftBukkit development: Why does this throw NullPointerException?
body: <p>I'm writing a simple Bukkit/Spigot plugin that replaces endermen inside of End City structures with shulkers. Here's the code:</p>
  
  <pre class="lang-java prettyprint-override"><code>package ru.cardboardbox.shulkerspawner;
  import org.bukkit.*;
  import org.bukkit.block.Block;
  import org.bukkit.entity.Entity;
  import org.bukkit.entity.EntityType;
  import org.bukkit.event.EventHandler;
  import org.bukkit.event.Listener;
  import org.bukkit.event.entity.CreatureSpawnEvent;
  import org.bukkit.plugin.java.JavaPlugin;
  import org.bukkit.util.BlockVector;
  
  import java.util.logging.Logger;
  
  public final class main extends JavaPlugin implements Listener {
      World world_the_end = Bukkit.getWorld("world_the_end");
      private Logger log = Logger.getLogger("Minecraft");
      @Override
      public void onEnable() {
          log.info("[ShulkerSpawner] Good morning sunshine!");
          getServer().getPluginManager().registerEvents(this, this);
      }
      @EventHandler(ignoreCancelled = true)
      public void onSpawn(CreatureSpawnEvent e) {
  
          Location spawneeStandingOnBlockLocation = e.getLocation().add(new BlockVector(0,-1,0));
          Location spawneeRealLocation = e.getLocation();
          Block checkedBlock = spawneeStandingOnBlockLocation.getBlock();
          Material checkedBlockMaterial = checkedBlock.getType();
          Entity spawnedEntity = e.getEntity();
          log.info("[ShulkerSpawner] We're checking at " + spawneeRealLocation + ", the entity being an instance of " + e.getEntityType());
          log.info("[ShulkerSpawner] The entity is standing on the block " + spawneeStandingOnBlockLocation.toString() + ", which is " + checkedBlockMaterial.toString());
  
          if (e.getEntityType() == EntityType.ENDERMAN) {
  
  
  
              /////// NULL POINTER NEXT LINE
              Location endCityOrNull = world_the_end.locateNearestStructure(spawneeRealLocation, StructureType.END_CITY,3,true);
  
  
  
              if (endCityOrNull != null) {
                  if (    checkedBlockMaterial == Material.PURPUR_BLOCK  ||
                          checkedBlockMaterial == Material.PURPUR_SLAB   ||
                          checkedBlockMaterial == Material.PURPUR_PILLAR ||
                          checkedBlockMaterial == Material.PURPUR_STAIRS )
                  {
                      log.info("[ShulkerSpawner] Successfully(?) spawned a shulker at " + spawneeRealLocation.toString());
                      //It's cruft, but it's EXACTLY what I need. Don't ask why. I really need to replace endermen with shulkers.
                      world_the_end.spawnEntity(spawneeRealLocation,EntityType.SHULKER);
                      spawnedEntity.remove();
                  } else {
                      log.info("[ShulkerSpawner] Entity is not on city blocks");
                  }
              } else {
                  log.info("[ShulkerSpawner] Entity is not near a city");
              }
          } else {
              log.info("[ShulkerSpawner] Entity is not an Enderman");
          }
      }
  
  
  }
  </code></pre>
  
  <p>Problem: 
  The marked line, against all odds, tends to throw up with NullPointerException. The method locateNearestStructure is nullable and returns null when a structure was no found.</p>
  
  <p>The kicker:
  The NullPointerException is thrown upon assignment. It's not thrown for the world where the structure we're looking for doesn't spawn (so it would always return null).</p>
  
  <p>The question: Why does this happen, and how can this be fixed?</p>
  
  <pre><code>    [08:56:54] [Server thread/INFO]: [ShulkerSpawner] We're checking at Location{world=CraftWorld{name=world_the_end},x=1667.5,y=102.0,z=35.5,pitch=0.0,yaw=1.818178}, the entity being an instance of ENDERMAN
  [08:56:54] [Server thread/INFO]: [ShulkerSpawner] The entity is standing on the block Location{world=CraftWorld{name=world_the_end},x=1667.5,y=101.0,z=35.5,pitch=0.0,yaw=1.818178}, which is PURPUR_BLOCK
  [08:56:54] [Server thread/ERROR]: Could not pass event CreatureSpawnEvent to shulkerspawner v1.0-SNAPSHOT
  java.lang.NullPointerException: null
      at ru.cardboardbox.shulkerspawner.main.onSpawn(main.java:39) ~[?:?]
      at com.destroystokyo.paper.event.executor.asm.generated.GeneratedEventExecutor7.execute(Unknown Source) ~[?:?]
      at org.bukkit.plugin.EventExecutor.lambda$create$1(EventExecutor.java:69) ~[patched_1.15.2.jar:git-Paper-129]
      at co.aikar.timings.TimedEventExecutor.execute(TimedEventExecutor.java:80) ~[patched_1.15.2.jar:git-Paper-129]
      at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[patched_1.15.2.jar:git-Paper-129]
      at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:559) ~[patched_1.15.2.jar:git-Paper-129]
      at org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory.callCreatureSpawnEvent(CraftEventFactory.java:631) ~[patched_1.15.2.jar:git-Paper-129]
      at org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory.doEntityAddEventCalling(CraftEventFactory.java:552) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.WorldServer.addEntity0(WorldServer.java:1214) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.WorldServer.addEntity(WorldServer.java:1121) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.SpawnerCreature.spawnMobs(SpawnerCreature.java:123) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.ChunkProviderServer.lambda$tickChunks$7(ChunkProviderServer.java:723) ~[patched_1.15.2.jar:git-Paper-129]
      at it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap$1.forEach(Long2ObjectLinkedOpenHashMap.java:1661) ~[patched_1.15.2.jar:git-Paper-129]
      at com.google.common.collect.Iterables$UnmodifiableIterable.forEach(Iterables.java:105) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.ChunkProviderServer.tickChunks(ChunkProviderServer.java:659) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.ChunkProviderServer.tick(ChunkProviderServer.java:602) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.WorldServer.doTick(WorldServer.java:406) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.MinecraftServer.b(MinecraftServer.java:1245) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:430) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:1112) ~[patched_1.15.2.jar:git-Paper-129]
      at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:934) ~[patched_1.15.2.jar:git-Paper-129]
      at java.lang.Thread.run(Thread.java:835) [?:?]
  </code></pre>
  
  <p>To suggestions about <code>world_the_end</code> containing a null reference:
  This strangely covers all dimensions of the world, and works right in the overworld. Only in The End it throws up like this. Folder for The End is called "world_the_end" Did it default to the default world, and am I completely misunderstanding how bukkit worlds work?</p>