NullPointerException ; Could not pass event PlayerRespawnEvent. Immediate help please!

Discussion in 'Plugin Development' started by Muod, Apr 25, 2014.

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

    Muod

    Alright so I have no clue why I'm getting that error in the console. This is my code for the class that is getting that error,
    Code:
    blic class GWEvents implements Listener {
        //Heading
        public GemWars plugin;
     
        public GWEvents(GemWars plugin)
        {
          this.plugin = plugin;
        }
        //End Heading
       
        @EventHandler
        public void onPlayerJoinEvent(PlayerJoinEvent event){
            Player player = event.getPlayer();
            if(!plugin.Players.contains(player.getName())){
            //REMEMBER TO TELEPORT THE PLAYER TO SPAWN HERE
            plugin.Players.set(player.getName() + ".gamesettings.score", Integer.valueOf(0));
            plugin.Players.set(player.getName() + ".gamesettings.team", String.valueOf("NA"));
            plugin.Players.set(player.getName() + ".in.game", Boolean.valueOf(false));
            plugin.Players.set(player.getName() + ".in.waitgame", Boolean.valueOf(false));
            plugin.Players.set(player.getName() + ".in.spawn", Boolean.valueOf(true));
            plugin.savePlayers();
            }else{
                //REMEMBER TO TELEPORT THE PLAYER TO SPAWN HERE
                player.getInventory().setArmorContents(null);
                player.getInventory().clear();
                player.setHealth(20);
                player.setFoodLevel(20);
                plugin.Players.set(player.getName() + ".in.game", Boolean.valueOf(false));
                plugin.Players.set(player.getName() + ".in.waitgame", Boolean.valueOf(false));
                plugin.Players.set(player.getName() + ".in.spawn", Boolean.valueOf(true));
            }
            if(plugin.GemWars.contains("Locations.SPAWN")){
                //Spawn Cords
                double sX = plugin.GemWars.getDouble("Locations.SPAWN.X");
                double sZ = plugin.GemWars.getDouble("Locations.SPAWN.Z");
                double sY = plugin.GemWars.getDouble("Locations.SPAWN.Y");
                float sPitch = (float)plugin.GemWars.getInt("Locations.SPAWN.Pitch");
                Vector sVector = plugin.GemWars.getVector("Locations.SPAWN.Vector");
                //End Spawn Cords
                Location Spawn = new Location(player.getWorld(), sX, sY, sZ);
                player.teleport(Spawn);
            }
        }
       
        @EventHandler(priority=EventPriority.HIGHEST)
        public void onPlayerRespawnEvent(PlayerRespawnEvent event){
            Player player = event.getPlayer();
        if(plugin.All.contains(player.getName())){
            if(plugin.Emerald.contains(player.getName())){
                //Spawn Cords
                double eX = plugin.GemWars.getDouble("Locations.ESPAWN.X");
                double eZ = plugin.GemWars.getDouble("Locations.ESPAWN.Z");
                double eY = plugin.GemWars.getDouble("Locations.ESPAWN.Y");
                float ePitch = (float)plugin.GemWars.getInt("Locations.ESPAWN.Pitch");
                Vector eVector = plugin.GemWars.getVector("Locations.ESPAWN.Vector");
                //End Spawn Cords
                Location eSpawn = new Location(player.getWorld(), eX, eY, eZ);
                event.setRespawnLocation(eSpawn);
                player.getLocation().setPitch(ePitch);
                player.getLocation().setDirection(eVector);
            }else if(plugin.Diamond.contains(player.getName())){
                //Spawn Cords
                double dX = plugin.GemWars.getDouble("Locations.DSPAWN.X");
                double dZ = plugin.GemWars.getDouble("Locations.DSPAWN.Z");
                double dY = plugin.GemWars.getDouble("Locations.DSPAWN.Y");
                float dPitch = (float)plugin.GemWars.getInt("Locations.DSPAWN.Pitch");
                Vector dVector = plugin.GemWars.getVector("Locations.DSPAWN.Vector");
                //End Spawn Cords
                Location dSpawn = new Location(player.getWorld(), dX, dY, dZ);
                event.setRespawnLocation(dSpawn);
                player.getLocation().setPitch(dPitch);
                player.getLocation().setDirection(dVector);
            }else if(plugin.Gold.contains(player.getName())){
                //Spawn Cords
                double gX = plugin.GemWars.getDouble("Locations.GSPAWN.X");
                double gZ = plugin.GemWars.getDouble("Locations.GSPAWN.Z");
                double gY = plugin.GemWars.getDouble("Locations.GSPAWN.Y");
                float gPitch = (float)plugin.GemWars.getInt("Locations.GSPAWN.Pitch");
                Vector gVector = plugin.GemWars.getVector("Locations.GSPAWN.Vector");
                //End Spawn Cords
                Location gSpawn = new Location(player.getWorld(), gX, gY, gZ);
                event.setRespawnLocation(gSpawn);
                player.getLocation().setPitch(gPitch);
                player.getLocation().setDirection(gVector);
            }else if(plugin.Iron.contains(player.getName())){
                //Spawn Cords
                double iX = plugin.GemWars.getDouble("Locations.ISPAWN.X");
                double iZ = plugin.GemWars.getDouble("Locations.ISPAWN.Z");
                double iY = plugin.GemWars.getDouble("Locations.ISPAWN.Y");
                float iPitch = (float)plugin.GemWars.getInt("Locations.ISPAWN.Pitch");
                Vector iVector = plugin.GemWars.getVector("Locations.ISPAWN.Vector");
                //End Spawn Cords
                Location iSpawn = new Location(player.getWorld(), iX, iY, iZ);
                event.setRespawnLocation(iSpawn);
                player.getLocation().setPitch(iPitch);
                player.getLocation().setDirection(iVector);
            }
        }else{
            //Spawn Cords
            double sX = plugin.GemWars.getDouble("Locations.SPAWN.X");
            double sZ = plugin.GemWars.getDouble("Locations.SPAWN.Z");
            double sY = plugin.GemWars.getDouble("Locations.SPAWN.Y");
            float sPitch = (float)plugin.GemWars.getInt("Locations.SPAWN.Pitch");
            Vector sVector = plugin.GemWars.getVector("Locations.SPAWN.Vector");
            //End Spawn Cords
            Location Spawn = new Location(player.getWorld(), sX, sY, sZ);
            event.setRespawnLocation(Spawn);
            player.getLocation().setPitch(sPitch);
            player.getLocation().setDirection(sVector);
        }
        }
    }
    
    Any idea's at all? I would like to thank you in advance if you do know how to fix this.
     
  2. Offline

    Serializator

    Can you post the error so we can see which problem cause the error and on which line etc. So please post the error above or underneath the class code.
     
  3. Muod Full stack trace please. But essentially, there's a null somewhere where there shouldn't be.
     
  4. Offline

    RawCode

    add debug output and stacktrace.
     
  5. Offline

    Muod

  6. Muod What's line 59? Something on there is null
     
  7. Offline

    Serializator

    Muod
    On line 59 you set the pitch from the player to a variable. The variable is a integer out of the configuration file from your plugin. So check in your configuration if the path "Locations.ESPAWN.Pitch" exists and if it does check if it is initialized. If all of that is right we need to look further into the code.
     
  8. Offline

    ZeusAllMighty11

    Serializator

    Only objects can be null, not primitives. A null float would result in default.
     
  9. Offline

    Serializator

    Your totally right but maybe the path isn't created?
     
  10. Offline

    Muod

    ZeusAllMighty11 , Serializator , AdamQpzm , RawCode,
    Here is my GemWars.yml file so you guys can analyze.
    Code:
    GameGoing: false
    MapGoing: NA
    CarryingGem: {}
    Locations:
      SPAWN:
        X: 22.599261587632633
        Z: 135.47663812018308
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
      LOBBY:
        X: 24.930373583680783
        Z: 135.4815538254248
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
      ISPAWN:
        X: 26.953406058542264
        Z: 135.48544542542967
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
      GSPAWN:
        X: 28.872116616565542
        Z: 135.48954184643534
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
      ESPAWN:
        X: 32.848687345499
        Z: 135.49855397262453
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
      DSPAWN:
        X: 30.674670211558634
        Z: 135.49466237261967
        Y: 64.0
        Pitch: 20.250008
        Vector:
          ==: Vector
          x: 0.9381397948214438
          y: -0.34611718200522296
          z: 0.00982963341852414
    
     
  11. Muod What's line 59, though? Please post your whole class, not just from "blic" onwards
     
  12. Offline

    Serializator

    AdamQpzm
    On line 59 he sets the pitch from the player to the path "Locations.ESPAWN.Pitch"
     
  13. Offline

    Serializator


    I pasted into my IDEA and check the line ;)
     
  14. Serializator I thought so. That's not his whole class, or he uses some form of magic.
     
  15. Offline

    Serializator


    It is the whole class. Above you see "public class" and underneath the bracket to close it.
     
  16. Serializator Really? I see "blic class". And I notice he doesn't use a package or any imports?
     
  17. Offline

    Serializator

    Sorry, so paste the whole class i think.
     
Thread Status:
Not open for further replies.

Share This Page