Help checking player teams return no players or not.

Discussion in 'Plugin Development' started by Creeoer, Aug 16, 2014.

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

    Creeoer

    Hello, I seem to have a simple problem but I am trying to see whether my hunter or runner teams reutrn no players, if they do not the game is supposed to remove the current players from the game , I think I am checking the teams wrong as well, players aer also not being removed from the game, I do think I use == null do I?

    addPlayer method checking the teams:
    Code:
    Bukkit.getScheduler().scheduleSyncDelayedTask(DeathMongol.getInstance(), new Runnable(){
                public void run() {
            if(Hunters.isPlayerHunting(p) && Hunters.getHunters() == null && Runners.getRunners() == null){
                ItemStack[] items = {new ItemStack(Material.COOKED_BEEF, 16), new ItemStack(Material.DIAMOND_SWORD), new ItemStack(Material.BOW)};
                p.getInventory().addItem(items);
                p.getInventory().setHelmet( new ItemStack (Material.DIAMOND_HELMET));
                p.getInventory().setChestplate( new ItemStack (Material.DIAMOND_CHESTPLATE));
                p.getInventory().setLeggings( new ItemStack (Material.DIAMOND_HELMET));
                p.getInventory().setBoots( new ItemStack (Material.DIAMOND_BOOTS));
                p.updateInventory();
                p.teleport(a.spawn);
                Horse horse = (Horse) p.getWorld().spawnCreature(p.getLocation(), EntityType.HORSE); // Spawns the horse
                horse.getInventory().setSaddle(new ItemStack(Material.SADDLE, 1)); // Gives horse saddle
                horse.setTamed(true); // Sets horse to tamed
                horse.setOwner(p);// Makes the horse the players
            } else {
                p.sendMessage(ChatColor.RED + "You've been removed from the game since there are no players to begin with");
                ArenaManager.getManager().removePlayer(p);
     
           
        }  if (Runners.isPlayerRunning(p) && Hunters.getHunters() == null &&  Runners.getRunners() == null){
            ItemStack[] items = {new ItemStack(Material.COOKED_BEEF, 16), new ItemStack(Material.DIAMOND_SWORD), new ItemStack(Material.BOW)};
            p.getInventory().addItem(items);
            p.getInventory().setHelmet( new ItemStack (Material.LEATHER_HELMET));
            p.getInventory().setChestplate( new ItemStack (Material.LEATHER_CHESTPLATE));
            p.getInventory().setLeggings( new ItemStack (Material.LEATHER_LEGGINGS));
            p.getInventory().setBoots( new ItemStack (Material.LEATHER_BOOTS));
            p.updateInventory();
            p.teleport(a.spawn);
        } else {
            p.sendMessage(ChatColor.RED + "You've been removed from the game since there are no players to begin with");
            ArenaManager.getManager().removePlayer(p);
     
         
        }
        }
            }, 20 *10);
    Join Command:
    Code:
            if (Runners.isPlayerRunning((Player) sender) || Hunters.isPlayerHunting((Player) sender)){
                p.sendMessage(ChatColor.RED + "You can't join....you are already in a game");
            } else {
         
            p.sendMessage(ChatColor.GREEN + "You have joined the game!");
            ArenaManager.getManager().addPlayer(p, num);
            Bukkit.getServer().broadcastMessage(ChatColor.WHITE + "[DeathCavallo]" + ChatColor.AQUA + "A player has joined the game!");
                Random rand = new Random();
                rand.nextInt(20);
                if (rand.nextInt() % 2 == 0){
                    TeamHandler.getRunners().addRunner((Player) sender);
                      p.sendMessage(ChatColor.GREEN + "You are now a runner!");
                }  else if (rand.nextInt() % 3 == 0){
                    TeamHandler.getHunters().addHunter((Player) sender);
                    p.sendMessage(ChatColor.RED + "You are now a hunter!");
                    return true;
              
    Removing player from arena and team:
    Code:java
    1. public void removePlayer(Player p) {
    2. Arena a = null;
    3.  
    4. // Searches each arena for the player
    5. for (Arena arena : this.arenas) {
    6. if (arena.getPlayers().contains(p.getUniqueId()))
    7. a = arena;
    8. }
    9.  
    10. // Check arena validity
    11. if (a == null) {
    12. p.sendMessage("Invalid operation!");
    13. return;
    14. }
    15.  
    16. // Remove from arena player lost
    17. a.getPlayers().remove(p.getName());
    18.  
    19. // Remove inventory acquired during the game
    20. p.getInventory().clear();
    21. p.getInventory().setArmorContents(null);
    22.  
    23. // Restore inventory and armor
    24. p.getInventory().setContents(inv.get(p.getName()));
    25. p.getInventory().setArmorContents(armor.get(p.getName()));
    26.  
    27. // Remove player data entries
    28. inv.remove(p.getUniqueId());
    29. armor.remove(p.getUniqueId());
    30.  
    31. // Teleport to original location, remove it too
    32. p.teleport(locs.get(p.getUniqueId()));
    33. locs.remove(p.getUniqueId());
    34.  
    35. //Hunter Remove/Runner Remove
    36. Runners.getRunners().remove(p.getName());
    37. Hunters.getHunters().remove(p.getName());
    38. }
    39.  


    Finally ,my hunter and runner classes, and null pointer expection I get when a player is supposed to be removed from the game when there are no players:
    Hunter Class and runner class: pretty much the same thing just different list and method names:

    Code:
    private static List<Player> hunters = new ArrayList<Player>();
     
        public void addHunter(Player player){
            if(hunters.contains(player)){
                return;
            }
            hunters.add(player);
            player.setDisplayName(ChatColor.RED + player.getName());
     
         
            }
        public static List<Player> getHunters(){
            return hunters;
        }
        public void removeHunter(Player player){
            if(hunters.contains(player)){
                hunters.remove(player);
            }
        }
         
        public static boolean isPlayerHunting(Player player){
            if (hunters.contains(player)){
                return true;
            } else
                return false;
     
         
        }
     
            
    Expection:

    Code:
    [13:36:01 WARN]: [DeathCavalllo] Task #2 for DeathCavalllo v0.3 generated an exception
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_7_R3.inventory.CraftInventory.setContents(CraftInventory.java:66) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at me.creeoer.commands.ArenaManager.removePlayer(ArenaManager.java:200) ~[?:?]
            at me.creeoer.commands.ArenaManager$1.run(ArenaManager.java:139) ~[?:?]
            at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftTask.run(CraftTask.java:53) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at org.bukkit.craftbukkit.v1_7_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:345) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:600) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Bukkit-1.7.9-R0.2-11-g3fd9db2-b3098jnks]
    [13:36:03 INFO]: <creeoer> s
     
  2. Offline

    DinosParkour

    Code:
            at me.creeoer.commands.ArenaManager.removePlayer(ArenaManager.java:200) ~[?:?]
            at me.creeoer.commands.ArenaManager$1.run(ArenaManager.java:139) ~[?:?]
    What's in line 200 and line 139
     
  3. Offline

    Creeoer

    DinosParkour
    Well ArenaManager.removePlayer is the method...and that is in my main post..
     
  4. Offline

    DinosParkour

    Creeoer Full class with [s.yntax=java]code[/s.yntax] pls (it adds numbers to the lines so we can see where's the error) (no dots in syntax ofc lol)
     
  5. Offline

    Creeoer

    DinosParkour thread edited.

    Ugh...anyone please? You know what I'll shorten the question, I'm trying to get the players from hunters and runners and I cant check if they are ==null, how would I check the amount of players on each team? The classes are in the main post btw.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
Thread Status:
Not open for further replies.

Share This Page