ERROR:null, NullPointerException; help

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

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

    Muod

    Error I'm receiving in console:
    [​IMG]

    "Game" Class:
    Code:
    package com.minehit;
     
    import java.util.List;
    import java.util.Random;
     
    import org.bukkit.Bukkit;
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.util.Vector;
     
    public class Game {
        private static Game instance;
        public static GemWars plugin;
        public Game(GemWars plugin)
        {
          this.plugin = plugin;
        }
       
        public static void addPlayer(Player player){
            int AllPlayers = plugin.All.size();
            if(AllPlayers+1 == 8){
                //Start the game
            }else if(AllPlayers+1 < 8){
               
            }else if(AllPlayers+1 > 8){
                //Send them to the lobby
            }
            //If this is the 8th player start game
            //MAKE SURE TO ADD PLAYER TO ALL LIST TOO
        }
       
        public void startGame(){
           
        }
       
        public void endGame(){
            playerEnd(plugin.Emerald);
            playerEnd(plugin.Diamond);
            playerEnd(plugin.Gold);
            playerEnd(plugin.Iron);
            //Reset Scores
            plugin.EmeraldG = 0;
            plugin.DiamondG = 0;
            plugin.GoldG = 0;
            plugin.IronG = 0;
            plugin.Emerald.clear();
            plugin.Diamond.clear();
            plugin.Gold.clear();
            plugin.Iron.clear();
            //Reset Map
        }
       
        public void playerEnd(List<String> list){
            for(String s : list) {
                  Player p = Bukkit.getPlayerExact(s);
                  if(p != null) {
                    //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.getDouble("Locations.SPAWN.Pitch");
                    Vector sVector = plugin.GemWars.getVector("Locations.SPAWN.Vector");
                    //End Spawn Cords
                    Location Spawn = new Location(p.getWorld(), sX, sY, sZ);
                    p.getLocation().setPitch(sPitch);
                    p.getLocation().setDirection(sVector);
                    plugin.Players.set(p.getName() + ".gamesettings.team", String.valueOf("NA"));
                    plugin.Players.set(p.getName() + ".in.game", Boolean.valueOf(false));
                    plugin.Players.set(p.getName() + ".in.waitgame", Boolean.valueOf(false));
                    plugin.Players.set(p.getName() + ".in.spawn", Boolean.valueOf(true));
                    p.getInventory().setArmorContents(null);
                    p.getInventory().clear();
                  }
                }
        }
        public static String getPlayerTeam(){
            String FinalDecision = null;
            int EAmount = plugin.Emerald.size();
            int DAmount = plugin.Diamond.size();
            int GAmount = plugin.Gold.size();
            int IAmount = plugin.Iron.size();
            if(EAmount < DAmount && EAmount < GAmount && EAmount < IAmount){
                FinalDecision = "Emerald";
            }else if(DAmount < EAmount && DAmount < GAmount && DAmount < IAmount){
                FinalDecision = "Diamond";
            }else if(GAmount < EAmount && GAmount < DAmount && GAmount < IAmount){
                FinalDecision = "Gold";
            }else if(IAmount < EAmount && IAmount < DAmount && IAmount < GAmount){
                FinalDecision = "Iron";
            }else{
                Random random = new Random();
                int randomint = random.nextInt(4 - 1 + 1) + 1;
                if(randomint == 1){
                    FinalDecision = "Emerald";
                }else if(randomint == 2){
                    FinalDecision = "Diamond";
                }else if (randomint == 3){
                    FinalDecision = "Gold";
                }else if (randomint == 4){
                    FinalDecision = "Iron";
                }
            }
            return FinalDecision;
        }
        public static Game getInstance()
          {
            return instance;
          }
    }
    
    JoingCommand Class:
    Code:
    package com.minehit;
     
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
     
    public class JoinCommand implements CommandExecutor{
        public GemWars plugin;
        Game game = Game.getInstance();
        public JoinCommand(GemWars plugin)
        {
          this.plugin = plugin;
        }
       
         
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args)
        {
            if(sender instanceof Player){
            Player player = (Player)sender;
            if(plugin.Players.getBoolean(player.getName() + ".in.game") == false){
            game.addPlayer(player);
            }else{
                player.sendMessage(plugin.Prefix + ChatColor.RED + "You are already in the game! You may leave by doing /leave.");
            }
        }
            return false;
    }
    }
    
     
  2. Offline

    xTigerRebornx

    Muod You are making your instance of Game, but you aren't passing in the GemWars variable it needs in its constructor, so any methods trying to use it will be trying to use a variable that was never initialized.
     
  3. Offline

    Muod

  4. Offline

    xTigerRebornx

    Muod If you don't know what initializing a variable means, you should learn more Java before trying to use a 3rd party API.
    Code:
    public Game(GemWars plugin)
        {
          this.plugin = plugin;
        }
    This constructor is never used, so your plugin variable is never initialized
     
Thread Status:
Not open for further replies.

Share This Page