ArrayList help please

Discussion in 'Plugin Development' started by DividedByZero, Aug 5, 2014.

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

    DividedByZero

    Code:
    package me.hiros.freezetag.Hub;
    
    import java.util.ArrayList;
    import java.util.UUID;
    
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.Plugin;
    
    public class Hub {
    	private Plugin plugin;
    
    	public static ArrayList<PlayerData> hubplayers;
    
    	public Hub(Plugin plugin) {
    		this.plugin = plugin;
    		Hub.hubplayers = new ArrayList<PlayerData>();
    	}
    
    	public void addPlayer(Player player) {
    		hubplayers.add(new PlayerData(player));
    	}
    
    	public void removePlayer(Player player) {
    		PlayerData data = getPlayerData(player);
    		if(data == null) {
    			plugin.getLogger().severe("Could not find player in hub storage.");
    			return;
    		}
    		hubplayers.remove(data);
    	}
    
    	public PlayerData getPlayerData(Player player) {
    		for(PlayerData data : getHubPlayers()) {
    			if(data.getName().equalsIgnoreCase(player.getName())) return data;
    		}
    		return null;
    	}
    
    	public ArrayList<PlayerData> getHubPlayers() {
    		return hubplayers;
    	}
    }
    
    class PlayerData {
    	private String name;
    	private UUID playerid;
    	private ItemStack[] inv;
    	private ItemStack[] armor;
    	private Location loc;
    
    	public PlayerData(Player player) {
    		this.name = player.getName();
    		this.playerid = player.getUniqueId();
    		this.inv = player.getInventory().getContents();
    		this.armor = player.getInventory().getArmorContents();
    		this.loc = player.getLocation();
    	}
    
    	public String getName() {
    		return name;
    	}
    
    	public UUID getPlayerId() {
    		return playerid;
    	}
    
    	public ItemStack[] getInv() {
    		return inv;
    	}
    
    	public ItemStack[] getArmor() {
    		return armor;
    	}
    
    	public Location getLocation() {
    		return loc;
    	}
    }
    
    I have been having this problem for maybe a month now and I'm just now revisiting it. Basically the issue is when I call getPlayerData(player) it returns null idk why.
    It's like some weird bug. Also if you need my source to further answer my question it is at http://github.com/DividedByZeros/FreezeTag
    Could someone explain to me why this is not detecting whether the player is in the hub by the player object.
     
  2. Offline

    Iroh

Thread Status:
Not open for further replies.

Share This Page