Can't check if player is on a team or not using ==null

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

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

    Creeoer

    Alright, my issue is simple. Bascially I want to check if there are either no or any players on two given teams (Hunters and Runnes) != null and == null doesn't seem to work? Because when I do /join instead of taking me to the game it gives me You can't join, a game is in session!!

    Join code:

    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 if (Runners.getRunners() == null && Hunters.getHunters() == null){
           
            p.sendMessage(ChatColor.GREEN + "You have joined the game!");
            ArenaManager.getManager().addPlayer(p, num);
           
               
        }  if (Runners.getRunners() != null || Hunters.getHunters() != null){
            p.sendMessage(ChatColor.RED + "You can't join, a game is in session!!");
            return true;
        }
       
          


    Hunter class (Runner same thing ,different names):
    Code:
    package me.creeoer.teams;
     
    import java.util.ArrayList;
    import java.util.List;
     
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
     
    public class Hunters {
     
       
       
       
    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;
       
           
        }
       
           
        }
        
     
  2. Offline

    Jake6177

    That's because it's not null, it's just empty. Try testing isEmpty().

    e.x. !Runners.getRunners().isEmpty()
     
  3. Offline

    Creeoer

    Thanks, and how would I check if the list has a player in it? Would I do Runners.getRunners().equals(>0)? Which doesn't seem to work, I also thought you used null to check if ANYTHING was in there or not, obviousuly I was wrong, I guess you use it to check if there is an instance of something, correct? Jake6177
     
  4. Offline

    Jake6177

    If the list isn't empty then there is a player in it.
     
Thread Status:
Not open for further replies.

Share This Page