Question

for some reason all entries I am putting into a HashSet are duplicating the last entry (Even though they're different). I don't know why this is and have tried many things to fix it.

Here is my code for putting an entry into the hashset:

public Arena(String name) {
    Arena.data = new ArrayList<PlayerData>();
    Arena.name = name;
    Arena.players = Integer.valueOf(Main.getPlugin().getConfig().getString("MaxUsers"));
    Arena.MinPlayers = Integer.valueOf(Main.getPlugin().getConfig().getString("MinUsers"));
    ConfigurationSection spawn = Main.getPlugin().getConfig().getConfigurationSection("Arenas."+name+".spawn");
    spawnPoint = LocationUtil.locationFromConfig(spawn, true);
    state = ArenaState.WAITING;
    Arena.playerManager = new PlayerManager(this);
    arenas.add(this);
}

Here is the code that actually gets all the entries to be put into the hashset.

public static void loadArenas() {       
    FileConfiguration fc = Main.getPlugin().getConfig();   
    for(String keys : fc.getConfigurationSection("Arenas").getKeys(false)){
        Arena arena = new Arena(keys);
    }
    for(Player player : Bukkit.getOnlinePlayers()){
        for(Arena arena : Arena.arenas) player.sendMessage(Bukkit.getServer().getPluginManager().getPlugin("PresidentAssassination").getConfig().getString("Prefix").replaceAll("(&([a-f0-9]))", "\u00A7$2") + ChatColor.RESET + " " + arena.getName());
    }
}

Any help would be greatly appreciated. Sorry for the messy code, I'm only twelve :P

Was it helpful?

Solution

Given this code:

Arena.name = name;

... it looks like your name variable is static. (The same is true for some of your other variables too.)

That means that rather than each Arena instance having a separate name, you have a single variable associated with the type itself. You almost certainly want instance variables instead of static variables, so you'd use:

this.name = name;

(etc) in your constructor. See the Variables page in the Java Tutorial for more information.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top