need help with Team.setprefix

Discussion in 'Spigot Plugin Development' started by ivo, Nov 6, 2019.

  1. ivo

    ivo

    When i try to set a nametag to Blue for Team blue it wont work...

    Anyone know how to fix it?

    Code:

    Code (Text):

              org.bukkit.scoreboard.Team bteam;
              ScoreboardManager manager = Bukkit.getScoreboardManager();
              Scoreboard board = manager.getNewScoreboard();
              bteam = board.registerNewTeam("BLUE");
              bteam.setPrefix("&9");
       
              p.sendMessage(ChatColor.GRAY + "You joined " + ChatColor.BLUE + team + ChatColor.GRAY + " team!");
              this.plugin.getPlayers().put(p, Team.valueOf(team.toUpperCase()));
              bteam.addEntry(p.getName());
              return false;
     
     
  2. ChatColor#translateAlternateColorCodes
     
  3. Code (Java):

    bteam.setPrefix(q("&9"));

    public static String q(String string) {
        return ChatColor.translateAlternateColorCodes('&', string);
    }
     
     
    #3 Marvin728, Nov 6, 2019
    Last edited: Nov 6, 2019
    • Like Like x 1
  4. bteam.setPrefix(Color.BLUE);
     
  5. I can code this for you if you'd like :).
     
  6. ivo

    ivo

    Ik if it then works if you change the prefix becaus it won’t add the player to the team and create a team if I do /scoreboard teams list is if that can be the case
     
  7. 1.13 and higher requires you to set the teams color not the prefix to change the name plate. Team.setColor()
     
  8. ivo

    ivo

    when i add Team.setColor(ChatColor.BLUE) i will get an error message
     
  9. ivo

    ivo

    Fixed the error but its still not showing the color above the name
     
  10. Unsure what you mean by "above the name".
     
  11. ivo

    ivo

    i mean color in nametag
     
  12. ivo

    ivo

    Wait this is my code

    Code (Text):

    package me.ivodev.cust.commands;

    import me.ivodev.cust.Teams;
    import me.ivodev.cust.enums.Team;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;


    public class TeamCommand implements CommandExecutor{

      private Teams plugin;
     
      public TeamCommand(Teams plugin) { this.plugin = plugin; }

      public String q(String string) {
          return ChatColor.translateAlternateColorCodes('&', "§");
      }
     
      public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
        if (sender instanceof Player) {    
            Player p = (Player)sender;
          if (args.length >= 1) {
            String team = args[0];
            if (team.equalsIgnoreCase("blue")) {
              if (this.plugin.getPlayers().containsKey(p)) {
                this.plugin.getPlayers().remove(p);
              }
              org.bukkit.scoreboard.Team bteam;
              ScoreboardManager manager = Bukkit.getScoreboardManager();
              Scoreboard board = manager.getNewScoreboard();
              bteam = board.registerNewTeam("BLUE");
              bteam.setColor(ChatColor.BLUE);
             
              p.sendMessage(ChatColor.GRAY + "You joined " + ChatColor.BLUE + team + ChatColor.GRAY + " team!");
              this.plugin.getPlayers().put(p, Team.valueOf(team.toUpperCase()));
              bteam.addEntry(p.getName());
              return false;
            }  if (team.equalsIgnoreCase("red")) {
              if (this.plugin.getPlayers().containsKey(p)) {
                this.plugin.getPlayers().remove(p);
              }
             
              org.bukkit.scoreboard.Team rteam;
              ScoreboardManager manager = Bukkit.getScoreboardManager();
              Scoreboard board = manager.getNewScoreboard();
              rteam = board.registerNewTeam("BLUE");
              rteam.setColor(ChatColor.RED);
             
              p.sendMessage(ChatColor.GRAY + "You joined " + ChatColor.RED + team + ChatColor.GRAY + " team!");
              this.plugin.getPlayers().put(p, Team.valueOf(team.toUpperCase()));
              rteam.addEntry(p.getName());
              return false;
            }
          }
          p.sendMessage(ChatColor.GRAY + "/team [red, blue]");
        } else {
          sender.sendMessage(ChatColor.RED + "You can't use this command!");
        }
        return false;
      }
    }
     


     
     
  13. You should set the scoreboard for that player to show the name tag.
    Code (Java):
    player.setScoreboard(manager);
    Also, if you want to show/hide the name tag, use Team.Option option.
     
  14. In addition to settings the players scoreboard, you are creating a new scoreboard every time a user runs the command. The colors will not show to all online players if you always create a new scoreboard. You'd be better off storing the scoreboard as a variable and make a new scoreboard every time the plugin loads.
     
  15. ivo

    ivo

    How can i do that

    Tryed but didnt work, can you maybe code it in?
     
  16. ivo

    ivo

    Code (Text):

      public void bscoreboard(Player player) {
          org.bukkit.scoreboard.Team bteam;
          ScoreboardManager manager = Bukkit.getScoreboardManager();
          Scoreboard board = manager.getNewScoreboard();
          bteam = board.registerNewTeam("BLUE");
          bteam.setColor(ChatColor.BLUE);
      }
     
    Like this way right? and then set it in OnEnable


    But how can i give the players there colored name then ?