Team prefix

Discussion in 'Spigot Plugin Development' started by Alex7895A, Jun 10, 2017.

  1. Hello, I am making a plugin to put a prefix in the tabist whith the scoreboard teams, in the console does not give me any error but I do not get the prefix in the tabist.

    This is my code
    Code (Text):
        private ScoreboardManager manager;
        private Scoreboard board;


        public void managerLoad(){
            this.manager = Bukkit.getScoreboardManager();
            this.board = manager.getNewScoreboard();
            Team team_owner = board.registerNewTeam("owner");
            team_owner.setPrefix(ChatColor.translateAlternateColorCodes('&', "&8&l[&5&lOwner&8&l] &r"));
        }


        public Scoreboard getScoreboard() {
            return this.board;
        }
    }

    And there i put the player in the team:

    Code (Text):
        public void onJoin(PlayerJoinEvent var1){
            Player var2 = var1.getPlayer();
            if(var2.hasPermission("oc.tabprefix.owner")){
                TeamManager.getInstance().getScoreboard().getTeam("owner").addPlayer(var2);
            }
     
  2. Tablist does not work with PJoinEvent I have this problem aswell I'm stumped rn
     
  3. I can't remember whether team changes tab, or just above player's head but you can use this method instead.
    player.setPlayerListName(string);

    It should still sort the players by their teams though.
     
  4. I dont use this method because y need to use more than 16 characters
     
  5. Does your method work somewhere else, when you don't call it right on player join? If so you can delay it by couple ticks.
     
  6. I think I found the error, I did not put to the player the scoreboard. I'll try that right now.
     
  7. It does not work yet, what do I do?
    This is my new code
    Code (Text):
    public class TeamManager {

        private TeamManager() { }

        static TeamManager instance = new TeamManager();

        public static TeamManager getInstance() {
            return instance;
        }

        private ScoreboardManager manager;
        private Scoreboard board;


        public void managerLoad(){
            this.manager = Bukkit.getScoreboardManager();
            this.board = manager.getNewScoreboard();
            Team team_owner = board.registerNewTeam("owner");
           
            team_owner.setPrefix(ChatColor.translateAlternateColorCodes('&', "&8&l[&5&lOwner&8&l] &r"));
            team_owner.setNameTagVisibility(NameTagVisibility.ALWAYS);
        }


        public Scoreboard getScoreboard() {
            return this.board;
        }
    }
    Code (Text):
    public class Listeners implements Listener {

        private Main main;

        public void onJoin(PlayerJoinEvent var1){
            Player var2 = var1.getPlayer();
            if(var2.hasPermission("oc.tabprefix.owner")){
                TeamManager.getInstance().getScoreboard().getTeam("owner").addPlayer(var2);
                var2.setScoreboard(TeamManager.getInstance().getScoreboard());
            }
        }
    }
     
  8. Do you actually set the scoreboard for the player?
    It appears to me as you don't.
    Use something along the lines of Player#setScoreboard(Scoreboard sb)
     
  9. I Find another method, is sending the Packet PlayerInfo, but how i use that packet.
     
  10. @Alex7895A It should be easy just use this in onjoin class


    Code (Text):
    player.setPlayerListName

    EXAMPLE
    Code (Text):
    player.setPlayerListName(Bukkit.getScoreboardManager().getMainScoreboard().getPlayerTeam(player.getPlayer()).getPrefix() + player.getName());
    Creating onJoin Class

    1. Creating Class called "onJoin"(lol)
    2. Then add implements listener on the 2 line
    public class 1.PNG
    3. Creating the event
    2.PNG
    Ignore the error in the picture
     
    #10 TheDaChicken, Jun 10, 2017
    Last edited: Jun 10, 2017
  11. @Steve.Rock but the limit is 16 characters and I need use more!
     
  12. @Alex7895A My prefix is more then 16 characters

    it should work
     
  13. @Alex7895A Can you send me your TeamManger class?
     
  14. Code (Text):
    public class TeamManager {
       
        public static TeamManager instance;
       
        public static TeamManager getInstace(){
            return instance;
        }
       
       
        public ScoreboardManager manager;
        public Scoreboard board;
       
        public void managerLoad(){
            this.board = this.manager.getNewScoreboard();
            Team team_owner = board.registerNewTeam("owner");
            String prefix = ChatColor.translateAlternateColorCodes('&', "&8&l[&5&lOwner&8&l] &f");
            team_owner.setPrefix(prefix);
            team_owner.setNameTagVisibility(NameTagVisibility.ALWAYS);
           
        }
       
        public Scoreboard getScoreboard(){
            return this.board;
        }

    }
     
  15. @Alex7895A
    Change that class into this
    Code (Text):
    public class TeamManager {
     
        public static TeamManager instance;
     
        public static Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
     
        public static TeamManager getInstace(){
            return instance;
        }
     
     
        public ScoreboardManager manager;
        public Scoreboard board;
     
        public void managerLoad(){
            Team team_owner = board.registerNewTeam("owner");
            String prefix = ChatColor.translateAlternateColorCodes('&', "&8&l[&5&lOwner&8&l] &f");
            team_owner.setPrefix(prefix);
            team_owner.setNameTagVisibility(NameTagVisibility.ALWAYS);
         
        }
     
        public Scoreboard getScoreboard(){
            return this.board;
        }
     
        public static String getPlayerPrefix(Player player) {
        String prefix = board.getPlayerTeam(player.getPlayer()).getPrefix();
        return prefix;
        }

    }

    Then Use
    Code (Text):
    player.setPlayerListName(TeamManager.getPlayerPrefix(player) + " " + player.getName());
     
  16. @Alex7895A What Version of spigot are you using?