PlayerRespawnEvent weird error

Discussion in 'Plugin Development' started by migsthegod, Jan 25, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    migsthegod

    Im having this problem with a plugin i have:
    (its minenion by shouykseikyo)
    Code:
    2012-01-24 07:47:30 [SEVERE] Could not pass event org.bukkit.event.player.PlayerRespawnEvent to Minenion
     
    java.lang.NullPointerException
     
        at com.shoukaseikyo.minenion.MinenionPlayerListener.onPlayerRespawn(MinenionPlayerListener.java:40)
     
        at org.bukkit.plugin.java.JavaPluginLoader$3.execute(JavaPluginLoader.java:286)
     
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:57)
     
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:327)
     
        at net.minecraft.server.ServerConfigurationManager.moveToWorld(ServerConfigurationManager.java:263)
     
        at net.minecraft.server.ServerConfigurationManager.moveToWorld(ServerConfigurationManager.java:222)
     
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:965)
     
        at net.minecraft.server.Packet9Respawn.handle(SourceFile:30)
     
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:226)
     
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:100)
     
        at net.minecraft.server.NetworkListenThread.a(SourceFile:108)
     
        at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:536)
     
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:434)
     
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:465)
    Im now using the latest RB 1818

    Here is lines 35-43:
    Code:
      public void onPlayerRespawn(PlayerRespawnEvent event)
      {
            if(minenion.start == true)
            {
                // if a blue team player respawn move it to blue team start point
                if(minenion.playerTeam.get(event.getPlayer()) == BLUE_TEAM)  ####<--line 40
                {
                    event.setRespawnLocation(minenion.blueTeamLocation);
                }
    Here is a link to the code:
    http://pastebin.com/pG9kWzww

    Any ideas? :D
     
  2. Offline

    uruhax

    There's a null object at line 40 of the MinenionPlayerListener class, check it. If you don't know what's wrong paste the code here.
     
    migsthegod likes this.
  3. Offline

    migsthegod

    Sorry i was about to do that

    Added the lines 35-43 :D

    The weird thing is, this works when i test it locally.
    When i run it on our hosted server this comes up but both are using same plugins and bukkit build

    The code looks ok right?

    Im new to java and I have no idea why we get a nullpointerexception

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  4. Offline

    uruhax

    The NullPointerException happens if, while running a program/plugin, java finds a variable with a null (empty) value. Maybe you're trying to get the team of a player who isn't in a team, i can't find out with only this part of the code. Try using

    if(minenion.playerTeam.get(event.getPlayer()) != null && minenion.playerTeam.get(event.getPlayer()) == BLUE_TEAM) {

    }
     
  5. Offline

    migsthegod

    Thanks for the help man :D
    I tried this, the error is now gone, HOWEVER, the problem remains:
    i dont respawn at the respawn point but rather, i spawn at the essentials defined spawn (/setspawn). :(

    Now using latest RB 1818

    Here is a link to the code:
    http://pastebin.com/pG9kWzww
     
  6. Offline

    Bruno Lanevik

    Should be
    Code:
    if(minenion.playerTeam.get(event.getPlayer()) != null ) {
        if(minenion.playerTeam.get(event.getPlayer()) == BLUE_TEAM){
            //code
        }
    }
    The reason it's getting nullpointer is when you have the statement if(event.getPlayer()) != null && event.getPlayer()) == BLUE_TEAM) it will check both if it's null and if it's on the blue team. However since you have the && it will not break if it's null.
    As you might know Integers can't be null. So what happens is that you are trying to see if it's "1" but you get NULL. So then it casts a nullpointerexception.

    I'm guessing that the reason that you're getting a null value is that the team is not properly set on the player. Try using static vars
     
  7. Offline

    uruhax

    Try changing your Priority for that event to Lowest. And btw, when you check if the player is in the red team you try to respawn him in the purpleTeamLocation lol. Hope the priority thing fixes your problem :D

    Bruno Lavenik is right about the if statement. I hadn't seen that BLUE_TEAM was an integer constant so i thought the nullpointer would be on the player team.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  8. Offline

    migsthegod


    Thanks guys :D
    I was actually about to try and change the priority level first when i saw that the my registerEvents were "deprecated."

    Is it because of the new events system? Here is how it currently is (deprecated):
    Code:
            pluginManager.registerEvent(Event.Type.PLAYER_RESPAWN, playerListener, Event.Priority.Normal, this);
    Am i not respawning properly because of this?
    Im trying to read the new tutorial and figure it out but is my event listener outdated causing me not to respawn properly?

    I'll try using static vars too thanks :D
    Just in case it might help here is the main class too:
    http://pastebin.com/D9FJ3tp9
     
  9. Offline

    uruhax

    No, it isn't because of the deprecated methods, those still work. I tried to make respawning work on a test here but i also didn't manage. How about trying to change the event to a PlayerDeathEvent and teleporting the player where you want him to go?

    I tried doing the PlayerRespawnEvent with Highest priority and strangely it worked, you should try that. Hope it works. Might be because with highest it acts last setting the respawn point. Essentials sets it first then the plugin overwrites it, probably.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  10. Offline

    migsthegod

    Lol. It worked :oops:
    I hit myself for not trying that.

    Seriously thanks for the help man.
    Im new to java but im starting to enjoy it specially with the friendly and helpful community here at bukkit.
    Thanks uruhax, Bruno Lanevik [diamond]
     
  11. Offline

    uruhax

  12. Offline

    Bruno Lanevik

    No problems, feel free to pm me if you need help.
     
Thread Status:
Not open for further replies.

Share This Page