I have made teams, however when I view them, they are not in "name" form, they are given like @1ec421. I would like them to be in name form, plus they are not static (they keep changing). I recon I have done the code wrong, however I am creating the teams on my main class (onEnable): Code: public void onEnable() { new Teams("Red").getName(); new Teams("Blue"); new Teams("Yellow"); new Teams("Green"); And my "Teams" class: Code: package me.promckingz.pigquest; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import org.bukkit.entity.Player; public class Teams { private static List<Teams> AllTeams = new ArrayList<Teams>(); private static HashMap<String, Teams> playerTeams = new HashMap<String, Teams>(); private String teamName; public Teams(String teamName){ this.teamName = teamName.trim(); AllTeams.add(this); } public String getName(){ return teamName; } public void add(Player player){ playerTeams.put(player.getName(), this); } public boolean remove(Player player){ if(hasTeam(player)) return false; playerTeams.remove(player.getName()); return true; } public static boolean hasTeam(Player player){ return playerTeams.containsKey(player.getName()); } public static Teams getTeam(Player player){ if(!hasTeam(player)) return null; return playerTeams.get(player.getName()); } public static Teams getTeam(String name){ for(Teams t : AllTeams) if(t.teamName.equalsIgnoreCase(name)) return t; return null; } public static List<Teams>getAllTeams(){ return AllTeams; } } @AdamQpzm @AdamQpzm Updated code EDIT by Moderator: merged posts, please use the edit button instead of double posting.
@ProMCKingz What does it return when you print the value of getName()? Also, you don't want to have static fields in this - I'd make a TeamManager class to manage teams.
@ProMCKingz What do you mean not in name form?? How to you get the Name or what do you want to achieve? Maybe you mean the Object#toString() Method?
@PreFiXAUT I have a command that does: p.sendMessage("" + Teams.getAllTeams()); And once executed the teams appear like this: "1ec421". Instead of "Red" @AdamQpzm
@ProMCKingz That's because getAllTeams() returns a List, and not a String of all their names. Java doesn't know how to convert it to the format you want, so you have to create a method for it yourself. For example, loop over all the teams in getAllTeams() and call the getName() method on them.
@AdamQpzm Loop over? What do you mean? @PreFiXAUT I have also tried .toString(); and .getName(); And it gives the same results
@ProMCKingz Because player is an instance of the Teams class and their is no sendMessage method in it. Did you write this class?