Solved Problems with TagAPI and players with names bigger than 15 characters

Discussion in 'Plugin Development' started by Telmovieira, Mar 29, 2015.

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

    Telmovieira

    Hey all!
    I bring you one last bug untill the first instance of my plugin gets released! Unfortunaly, is quite a big one... So, my plugin depends on team system that stores player's name in list of strings. The problem is that my plugin uses TagAPI to color the player's name, so names longer than 15 characters become longer than 16 characthers, which breaks everything. There are multiple solutions to solve this. So i ask you this:
    - Is there an alternative to TagAPI to color the player's display name and how to do it(I preffer this solution because i get rid of one dependency)
    -Is there another way that i can store the players in the list besides their names or with a Player list (Which does not work at all for some reason...).
    Here is my code, fell free to ask me more questions:
    Code:
    public class Team {
     
        private static List<String> redTeam = new ArrayList<String>();
        private static List<String> blueTeam = new ArrayList<String>();
        private static List<String> yellowTeam = new ArrayList<String>();
        private static List<String> greenTeam = new ArrayList<String>();
    
        public static void addToTeam(TeamType type, Player player) {
            switch (type) {
            case RED:
                redTeam.add(player.getName());
                break;
            case BLUE:
                blueTeam.add(player.getName());
                break;
            case YELLOW:
                yellowTeam.add(player.getName());
                break;
            case GREEN:
                greenTeam.add(player.getName());
                break;
            }
    
        }
     
        public static Color getTeamColor(TeamType type) {
            switch (type) {
            case RED:
                return Color.RED;
            case BLUE:
                return Color.BLUE;
            case GREEN:
                return Color.GREEN;
            case YELLOW:
                return Color.YELLOW;
            default:
                return null;
            }
         
        }
     
        public static boolean isInTeam(Player player) {
            return redTeam.contains(player.getName())
                    || blueTeam.contains(player.getName())
                    || yellowTeam.contains(player.getName())
                    || greenTeam.contains(player.getName());
        }
    
        public static void clearTeams() {
            redTeam.clear();
            blueTeam.clear();
            greenTeam.clear();
            yellowTeam.clear();
        }
    
        public static List<String> getRedTeam() {
            return redTeam;
        }
    
        public static List<String> getBlueTeam() {
            return blueTeam;
        }
    
        public static List<String> getYellowTeam() {
            return yellowTeam;
        }
    
        public static List<String> getOrangeTeam() {
            return greenTeam;
        }
    
        public static List<String> getAllPlayersInTeams() {
            List<String> combinedTeams = new ArrayList<String>();
            combinedTeams.addAll(redTeam);
            combinedTeams.addAll(blueTeam);
            combinedTeams.addAll(yellowTeam);
            combinedTeams.addAll(greenTeam);
            return combinedTeams;
        }
    
        public static TeamType getTeamType(Player player) {
            if (!isInTeam(player))
                return null;
            return (redTeam.contains(player.getName()) ? TeamType.RED : (blueTeam
                    .contains(player.getName()) ? TeamType.BLUE
                    : (yellowTeam.contains(player.getName()) ? TeamType.YELLOW
                            : TeamType.GREEN)));
    
        }
    }
    Thanks to everyone who responds!
     
  2. Offline

    xTigerRebornx

    @Telmovieira For changing name color, use the scoreboard api and its teams, setting the prefix to the color you want
    For an easier way of storing the team of the player, use a Map, where the key can be their UUID (or if you use a WeakHashMap, a Player key would work), and the value is their TeamType.
    As for your code in general, you shouldn't be using static, it defeats the purpose of using an Object Oriented Language and is a horrible convention (in the way you use it). Do some research on proper encapsulation and managing your data without the need for statics.
     
  3. Offline

    Telmovieira

    @xTigerRebornx
    Do the scoreboard prefixes show in the name above the player in game?
     
  4. Offline

    xTigerRebornx

  5. Offline

    Telmovieira

    I got it to work properly now. I basicaly created a scoreboard with teams on the onEnable method only to disable frendly fire and to color people's names.
     
  6. Offline

    Fuzzybear04

    You can always use NametagEdit to colour people's names.
     
  7. Offline

    dlange

    @Fuzzybear04 since he is releasing his plugin I think he would prefer to make it minimum dependencies even though nametag edit was made by the Cazey :p
     
    Fuzzybear04 likes this.
  8. Offline

    Fuzzybear04

    @dlange Haha the Cazey referred me to NametagEdit ;)
     
    dlange likes this.
Thread Status:
Not open for further replies.

Share This Page