Trouble adding players to teams

Discussion in 'Plugin Development' started by jxcd, May 12, 2020.

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

    jxcd

    I'm trying to create commands that will give players a glow around their character with a command + color argument, because I want the players to be able to choose their glow color. I found that the easiest way to do that is to add the player to a color-coded team. My only problem is that I don't know how to do this without duplicating the team (& getting an error because the team already exists). Now, the command only works on the first try - any other attempts gives me an error unless I remove the team with the /team remove command.

    (Please ignore my messy code)

    How would I create teams so that my code doesn't try to create the same team every time the specific color command is run? All I want is /teamglow red to make the player glow red, /teamglow blue for blue, etc.

    Teams.java class
    Code:
        public void teamList(Player player, String color) {
          
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getMainScoreboard();
            Team red = board.registerNewTeam("Red");
            Team yellow = board.registerNewTeam("Yellow");
            Team pink = board.registerNewTeam("Pink");
            Team blue = board.registerNewTeam("Blue");
            red.setColor(ChatColor.RED);
            yellow.setColor(ChatColor.YELLOW);
            pink.setColor(ChatColor.DARK_AQUA); // not pink I know
            blue.setColor(ChatColor.BLUE);
          
            if (color.equalsIgnoreCase("red")) {
                red.addEntry(player.getName());
                player.sendMessage("RED!");
    
            }
            else if (color.equalsIgnoreCase("blue")) {
    
                blue.addEntry(player.getName());
                player.sendMessage("BLUE!");
                //return blue;
    
            }
            else if (color.equalsIgnoreCase("yellow")) {
                yellow.addEntry(player.getName());
                player.sendMessage("YELLOW!");
                //return yellow;
            }
          
            else if (color.equalsIgnoreCase("pink")) {
                pink.addEntry(player.getName());
                player.sendMessage("PINK!");
                //return pink;
            }
            //return null;
       
        }
    Command code:

    Code:
                if (cmd.getName().equalsIgnoreCase(cmd4)) {
    
                    if (args.length == 0) {
                        player.sendMessage(ChatColor.ITALIC + "Correct format: /teamglow [color]");
                      
                    }
                    else {
                      
                        Teams glow = new Teams();
                        glow.teamList(player, args[0]);
                        //teamType.addEntry(player.getName());
                        //System.out.println("Hello!!!" + teamType.toString());
                        player.sendMessage("This works!");
                    }
                  
                    return true;
                }
    
     
  2. Offline

    NiekZndt

    You could try making a list and appending to it.
     
Thread Status:
Not open for further replies.

Share This Page