Need help expanding 16 character limit

Discussion in 'Spigot Plugin Development' started by Timuh, Jan 5, 2015.

  1. So I'm trying to get tablist to show a prefix with a name but it gives errors to certain users due to the 16 character limit. Help please

    Code
    Code (Text):
     ArrayList<String> mod = new ArrayList<String>();
           
            String mods = ChatColor.GOLD + "[MOD] " + p.getName();
            for(String m : mod)
            {
                if(mods.length() + 6 > 16)
                      mods = mods.substring(0, mods.length());
                mods += m;
            }
             }
             if(p.hasPermission("mod.rank")){
                 e.setJoinMessage(ChatColor.GOLD + "[MOD] " + e.getPlayer().getName() + ChatColor.GRAY + " has join" + ChatColor.AQUA + " HeroMC" + ChatColor.GRAY + "!");
                 p.setPlayerListName(mods);
     
  2. You can't expand it, it is hardcoded into Minecraft.

    You need to cull the end of the name, shorten it however many you need to.
     
  3. i seen plugin do it like for example NameTagEdit. Not sure if they use scoreboards to do this. But i don't know how to use scoreboards to do that
     
  4. They use scoreboard prefixes.
     
    • Agree Agree x 1
  5. I'm trying to get the scoreboard prefix to work but Im fairly new to java and i need some help

    Code
    Code (Text):
    @EventHandler(priority=EventPriority.HIGHEST)
        public void playerJoin(PlayerJoinEvent e) {
          Player p = e.getPlayer();
            e.setJoinMessage("");
             Team team = ScoreboardAPI.createTeam("ADMIN");
             team.setPrefix(ChatColor.RED + "[ADMIN] " + e.getPlayer().getName());
             team.addPlayer(e.getPlayer());
           
             if(p.hasPermission("admin.rank")){
                 e.setJoinMessage(ChatColor.RED + "[ADMIN] " + e.getPlayer().getName() + ChatColor.GRAY + " has join" + ChatColor.AQUA + " HeroMC" + ChatColor.GRAY + "!");
                 p.setPlayerListName(ChatColor.RED + "" + p.getName());
             }
        }
    Don't know what to do after that

    Scoreboard API
    Code (Text):
    import org.bukkit.Bukkit;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;

    public class ScoreboardAPI {
     
        private static Scoreboard board;
     
        public static Scoreboard getScoreboard() {
            if (board == null)
                board = Bukkit.getScoreboardManager().getNewScoreboard();
            return board;
        }
     
        private static void initScoreboard() {
            if (board == null)
                board = Bukkit.getScoreboardManager().getNewScoreboard();
        }
     
        public static Team createTeam(String name) {
            initScoreboard();
            Team toReturn = board.getTeam(name);
            if (toReturn == null)
                toReturn = board.registerNewTeam(name);
            return toReturn;
        }
     
        public static Objective createObjective(String name, String criteria) {
            initScoreboard();
            Objective toReturn = board.getObjective(name);
            if (toReturn == null)
                toReturn = board.registerNewObjective(name, criteria);
            return toReturn;
        }
    }
     
    Like i know that you need to do something like setScoreboard() and connect it to the player but I'm lost with that
     
  6. Scoreboard sb = player.get score board();
    if(sb.get team(prefix) !=null)
    sb.registerTeam(prefix)
    Team team = sb.get team(prefix)
    team.setPrefix(prefix)
    team.add player(player)

    Something like that is how you create a prefix for a team, my phones auto correct modified the code a little well I was writing it out
     
  7. i have this but I'm pretty sure its wrong
    Code (Text):
     ScoreboardManager manager = Bukkit.getScoreboardManager();
      Scoreboard board = manager.getNewScoreboard();
      Team admin = board.registerNewTeam("admin");
     
      @EventHandler(priority=EventPriority.HIGHEST)
        public void playerJoin(PlayerJoinEvent e) {
          Player p = e.getPlayer();
            e.setJoinMessage("");

             if(p.hasPermission("admin.rank")){
                 e.setJoinMessage(ChatColor.RED + "[ADMIN] " + e.getPlayer().getName() + ChatColor.GRAY + " has join" + ChatColor.AQUA + " HeroMC" + ChatColor.GRAY + "!");
                  admin.setPrefix(ChatColor.RED + "[ADMIN] " + e.getPlayer().getName());
                 p.setScoreboard(board);
                 admin.addPlayer(p);
             }
        }
     
  8. Are the first 3 lines in a method of some sort? And you only want to set the teams prefix when your registering it. Also you only want to register it if the team doesn't already exist on the scoreboard
     
    • Useful Useful x 1