net.minecraft.server.v1_11_R1.EnumGamemode

Discussion in 'Spigot Plugin Development' started by tootoll, Apr 16, 2017.

  1. Im having problems after updating to latest spigot build
    i am using PlayerBuilder for placeholder purposes

    code lines defining it after constructing a player are simple as
    Code (Text):
    private EnumGamemode mode;
    ...
    this.mode = EnumGamemode.SURVIVAL;
    ...
    this.player.a(this.mode);
    getting:
    Code (Text):
    java.lang.NullPointerException
        at net.minecraft.server.v1_11_R1.EntityPlayer.a(EntityPlayer.java:1016) ~[test-1.11.2.jar:git-Spigot-54ec0b8-1ac133e]
    after spigot update.

    I can build it with no gamemode but does anyone know what changed and why do i get NullPointerException after updating from older 1.11.2 to latest spigot 1.11.2?
     
  2. Not sure what build you're using, but I pulled this from the latest one:
    Code (Java):
    this.playerConnection.sendPacket(new PacketPlayOutGameStateChange(3, enumgamemode.getId()));
    Although this cóuld indicate that mode is null, enumgamemode.getId() is called earlier for the event, so I'm going to leave that out of the picture. If you're using the latest build, the only thing that can be null is this.playerConnection.
    I looked in CraftBukkit 1.8.8 for comparison, and noticed that in that version it's going through the Bukkit API which has a null check for the playerConnection.
    What happens if you don't call the method at all?
     
    • Like Like x 1
  3. if i do not use gamemode, that is //this.player.a(this.mode);, everything works as expected, no errors on server startup.
     
  4. I didn't quite elaborate, my bad. I meant as in are you missing any functionality if you don't call the method?
     
  5. No i do not, but if i remember correctly (from snippet code) when you create empty tab holder you should set its gmode. As far that i tested i do not have any problems on normal servers with removing this method as i said in first post i can compile it and it works with no problem.

    But i was still wondering what change in Spigot. Most of the time when going from example R1 to R2 or next MC version, some minor tweaks are needed to make something like this to work (especially with ".a()", ".b()" or what ever is there...), but this time for me that it was new-er spigot still on identical R and MC version.
     
  6. In the latest version it seems that unchanged-ish nms code is used for the gamemode. In previous versions a bukkit method would be called which first checked if the playerConnection field was null. If it was null, nothing would be done at all so you should be fine not calling it.