1.16.x Error null pointer when creating world

Discussion in 'Spigot Plugin Development' started by Thund27, Sep 16, 2020 at 9:39 PM.

  1. Hi, I'm creating/loadinf a world in the onJoin() event method but I get an error in the console.

    The code :
    Code (Java):
    public void onJoin(PlayerJoinEvent event)
            Player player = event.getPlayer();
            String world_name = UUIDTypeAdapter.fromUUID(player.getUniqueId());
            player.sendMessage(world_name); //just a testing line
            new WorldCreator(world_name).createWorld();
    The error :
    Code (Text):
    [22:18:16] [Server thread/INFO]: Preparing spawn area: 37%
    [22:18:25] [Server thread/FATAL]: Error executing task on Server
    java.lang.NullPointerException: null
            at net.minecraft.server.v1_16_R2.ChunkMapDistance.b(ChunkMapDistance.java:244) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PlayerChunkMap.movePlayer(PlayerChunkMap.java:956) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.ChunkProviderServer.movePlayer(ChunkProviderServer.java:482) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PlayerConnection.a(PlayerConnection.java:479) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PacketPlayInTeleportAccept.a(SourceFile:30) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PacketPlayInTeleportAccept.a(SourceFile:8) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.TickTask.run(SourceFile:18) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.ba(MinecraftServer.java:941) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.executeNext(MinecraftServer.java:934) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.IAsyncTaskHandler.executeAll(SourceFile:103) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.executeModerately(MinecraftServer.java:911) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.loadSpawn(MinecraftServer.java:596) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.craftbukkit.v1_16_R2.CraftServer.createWorld(CraftServer.java:1068) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.Bukkit.createWorld(Bukkit.java:524) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.WorldCreator.createWorld(WorldCreator.java:325) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at fr.thund.skyblock.SbListener.onJoin(SbListener.java:45) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_261]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_261]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_261]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.PlayerList.a(PlayerList.java:200) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.LoginListener.c(LoginListener.java:153) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.LoginListener.tick(LoginListener.java:52) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.NetworkManager.a(NetworkManager.java:219) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.ServerConnection.c(ServerConnection.java:130) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.b(MinecraftServer.java:1126) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.DedicatedServer.b(DedicatedServer.java:352) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.a(MinecraftServer.java:1007) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.w(MinecraftServer.java:846) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at net.minecraft.server.v1_16_R2.MinecraftServer.lambda$0(MinecraftServer.java:164) ~[spigot-1.16.3.jar:git-Spigot-3a70bd9-bf3d720]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_261]
    [22:18:29] [Worker-Main-23/INFO]: Preparing spawn area: 83%

    I noticed that the error occurre during the loading of the spawn area of the world, and after waiting a bit I can teleport to the world so I really don't understand this error.

    I'd love to get some help, thanks
  2. The stack trace says that the error is on Line 45 of your SbListener.java class. Which line is this? It's also a NPE so make sure that whatever is on that line isn't null as well.
  3. no idea ;) if everything works an it's just an error message why dont you just put a try{ }catch arround it? ;) Pro programmer move xD
  4. The line 45 corresponds to the line with createWorld();
    It would mean that the world created/loaded is null ?
  5. I'm a beginner and idk what exception to catch x)

    edit : a null pointer exception I guess ?
  6. He means surround it by a try and empty catch, which isn't very good practise at all.
  7. Yes the nullpointer.

    Your code should look like this:

    new WorldCreator(world_name).createWorld();
    }catch(NullPointerException exc){ }
    • Funny Funny x 1
  8. Yes but sometimes it works ^^. I already worked with some crappy afafaf apis from other plugins and sometimes there is like a method, you have to give it like a name for example but you need a method where you dont have a name BUT: the method with the name works just fine, it only throws a nullPointer

    try catch and call it a day xD
  9. Why don't you just do player.getUniqueID().toString(); ?
    You're catching the NPE, why? You should always try to fix your problems, not just ignore them. :ROFLMAO:
    • Funny Funny x 2
    • Optimistic Optimistic x 1
  10. Hey man if it works it works so dont change it, thats the nr1 programming law xD

    (This may be the reason why all of my plugins apis are DEFINETLY the best apis on earth xD)
    • Optimistic Optimistic x 1
  11. What is this?
    Code (Text):
    String world_name = UUIDTypeAdapter.fromUUID(player.getUniqueId());
    If you want to get the UUID as a string just add .toString(); at the end
  12. I agree with you, besides I tried this code :
    Code (Text):
    try {
                player.sendMessage("got into try");
                new WorldCreator(world_name).createWorld();
            } catch (NullPointerException e) {
                player.sendMessage("§cnull pointer exception");
    and I still get the error in my console and my minecraft player receive the message I put in the try
  13. Ok, I'll try it but idk if it's gonna change anything
  14. Well that's a bad idea because it doesnt remove the dash in the uuid
  15. Then do this:
    Code (Java):
    player.getUniqueID().toString().replaceAll("-", "");
    That should work just fine I believe.
  16. Not a big deal, Just replace them
  17. Please don't do that, for one that's bad practice because if something is null that you didn't expect in the same block, you'll have a significantly harder time debugging it. For another, try / catch blocks are relatively performance-expensive operations compared to just checking if a variable is null.
    • Like Like x 1
    • Agree Agree x 1
  18. From what I have just researched you don't need to be using UUIDTypeAdapter (Which fetches data from Mojang)
    Simply use this to get the server logged UUID of the player (Especialy if the server mode is 'offLine')
    Code (Text):
    String world_name = player.getUniqueId().toString();