Need help expanding 16 character limit

Discussion in 'Plugin Development' started by Zyu, Jan 4, 2015.

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

    Zyu

    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:
     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. Offline

    TheCoderGuy

    Use teams inside of the tab. It works better.
     
    Konato_K likes this.
  3. Offline

    Konato_K

    @Zyu Just to add on what CoderGuy said, add the players to a team and set a prefix to a team, the prefix will display before their name in the tab list and their head, don't forget to reset the colors!
     
  4. Offline

    Zyu

    I'm trying to get the scoreboard prefix to work but Im fairly new to java and i need some help

    Code

    Code:
    @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:
    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

    I'm trying to get the scoreboard prefix to work but Im fairly new to java and i need some help

    Code

    Code:
    @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:
    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

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 31, 2016
  5. Offline

    Konato_K

Thread Status:
Not open for further replies.

Share This Page