Scoreboard teams with prefixes/suffixes not working.......

Discussion in 'Spigot Plugin Development' started by fujiboy4, Apr 5, 2017.

  1. I don't know how much I need to explain other than the nametag does not change whatsoever. I got the displayname on the tablist to change using the
    Code (Text):
    Player#setPlayerListName();
    ...

    Here is my current code:
    Code (Text):
    public class Titles {

        Player p;
        String prefix;
        String suffix;

        Scoreboard scoreboard;
        Team team;

        @SuppressWarnings("deprecation")
        public Titles(Player player, String prefix, String suffix) {
            scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            System.out.println("Registered Scoreboard...");
            team = scoreboard.registerNewTeam("team");
            System.out.println("Registered Team...");
           
            this.prefix = prefix;
            this.suffix = suffix;

            team.setPrefix(this.prefix);
            team.setSuffix(this.suffix);

            System.out.println(" Prefix: " + this.prefix + " Suffix: " + this.suffix);
           
            this.p = player;
           
            if (!team.hasPlayer((OfflinePlayer) player)) {
                System.out.println("Doesn't have player... adding it to the list.");
                team.addPlayer((OfflinePlayer) player);
                System.out.println(team.getPlayers().toString());
            }

            if (scoreboard != null) {
                if (p != null) {
                    p.setScoreboard(scoreboard);
                    System.out.println("Set scoreboard : " + scoreboard.toString());
                } else {
                    System.out.println("Player = null");
                }
            } else {
                System.out.println("Scoreboard = null");
            }

        }

        public void setPrefix(String newPrefix) {
            this.prefix = newPrefix;
        }

        public void setSuffix(String newSuffix) {
            this.suffix = newSuffix;
        }

        public String getPrefix() {
            return this.prefix;
        }

        public String getSuffix() {
            return this.suffix;
        }
    }
     

    No errors, and the stack tracing:

    Code (Text):
    [19:26:18 INFO]: UUID of player Fujeh_ is 5e36cc82-6029-471f-924b-9f84ac35863d
    [19:26:18 INFO]: Registered Scoreboard...
    [19:26:18 INFO]: Registered Team...
    [19:26:18 INFO]:  Prefix:  Suffix:
    [19:26:18 INFO]: Doesn't have player... adding it to the list.
    [19:26:18 INFO]: [CraftPlayer{name=Fujeh_}]
    [19:26:18 INFO]: Set scoreboard : [email protected]4f1
    [19:26:18 INFO]: Fujeh_[/127.0.0.1:63030] logged in with entity id 531 at ([Hub]-107.72371308932851, 4.0, 1918.4611040264654)

    Hopefully you guys can help my problem... :/ Btw, I did try team.addEntry and team.getEntry but that doesn't seem to work. Does it take a player ign or uuid string?

    Thanks.
     
  2. The Code works fine for me
    What Version are you using and or are there other Plugins that change the prefix or suffix?
     
  3. You got it working? It might be the 1.10 build I'm using. For some odd reason I have another problem working with Entities riding as passangers on player's heads. What build are you using?
     
  4. I tested it in several Versions (1.8-1.11) still worked. Could you show how you use it in your Code?
     
  5. Code (Text):
    final Titles title = new Titles(p, "", "");

            new BukkitRunnable() {

                @Override
                public void run() {
                    RolePlayGroup rpg2 = Main.listManager.getRolePlayGroupByMember(p.getUniqueId());
                    if (rpg2 != null) {
                        if (scoreboard.hasScoreboard()) {              
                                title.setPrefix(ChatColor.GOLD + "" + ChatColor.BOLD + rpg2.getName());
                            if (rpg2.getRoleByName(p.getUniqueId()) != null) {
                                title.setSuffix(ChatColor.BLUE + "" + ChatColor.BOLD
                                        + rpg2.getRoleByName(p.getUniqueId()).getName());
                            } else {
                                title.setSuffix(ChatColor.RED + "");
                            }
                            p.setPlayerListName(title.getPrefix() + " " + ChatColor.GRAY + p.getName() + " " + title.getSuffix());
                        }
                        p.setScoreboard(scoreboard.getScoreboard());

                    } else {
                        p.setScoreboard(Bukkit.getScoreboardManager().getNewScoreboard());
                    }

                    if (!p.isOnline()) {
                        cancel();

                    }

                    rpg2 = null;
                }

            }.runTaskTimer(plugin, 0L, 100L);

    Note: All methods including my other object RolePlayGroup work. I removed all the other scoreboard code being run in here as well so it's easier to read.
     
  6. You never update the Title with the Method
    Try to put the Scoreboard registering in an seperate method like update()
     
  7. What do you mean? I did realize though, that I was checking if the actual sidebar scoreboard is on and I put the titles in there as if it needs to be on, which it doesn't matter whether or not the scoreboard is on.
     
  8. I'm going to re-install the 1.10 BuildsTools.jar and see if I still get the same problem.
     
  9. Okay I redownloaded 1.10 Spigot, put it in the server, and readded it to the Build Path. And it still doesn't seem to work.

    2017-04-05_18.40.49.png
     
  10. I see that you got another Scoreboard on the Side.
    Try to implement the Method with the Scoreboard you are using for the Sidebar

    maybe use it like this:
    Code (Text):
    Title title = new Title(player, prefix, suffix, scoreboard)
     
  11. Well, so I have these 2 classes...
    Code (Text):
    public class Scoreboards {

        Player p;
       
        Scoreboard scoreboard;
        Objective obj;

        public Scoreboards(Player p, String title, ArrayList<String> lines) {
            scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
           
            obj = scoreboard.registerNewObjective("test", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', title));

            if (!(lines.size() > 16) || !(lines.size() < 0)) {
                for (int i = lines.size() - 1; i > -1; i--) {
                    Score score = obj.getScore(ChatColor.translateAlternateColorCodes('&', lines.get(i)));
                    score.setScore(lines.size() - i);
                }
            } else {
                throw new IllegalArgumentException();
            }

            p.setScoreboard(scoreboard);

            this.p = p;      
        }

        public boolean hasScoreboard() {
            if (p != null) {
                if (p.getScoreboard() != null) {
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }

        public static void resetBoard(Player p) {
            Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            p.setScoreboard(scoreboard);
        }

        public void removeAll() {
            for (String entry : this.scoreboard.getEntries()) {
                this.scoreboard.resetScores(entry);
            }
        }

        public void removeLine(int line) {
            for (String entry : this.scoreboard.getEntries()) {
                if (this.obj.getScore(entry).getScore() == line) {
                    this.scoreboard.resetScores(entry);
                    break;
                }
            }
        }

        public Scoreboard getScoreboard() {
            return scoreboard;
        }

        public String getTitle() {
            return obj.getDisplayName();
        }

        public void setTitle(String name) {
            this.obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', name));
        }

        public void set(int row, String text) {
            Validate.isTrue(16 > row, "Row can't be higher than 16");
            if (text.length() > 32) {
                text = text.substring(0, 32);
            }

            for (String entry : this.scoreboard.getEntries()) {
                if (this.obj.getScore(entry).getScore() == row) {
                    this.scoreboard.resetScores(entry);
                    break;
                }
            }

            this.obj.getScore(ChatColor.translateAlternateColorCodes('&', text)).setScore(row);
        }

    }
     

    Code (Text):
    public class Titles {

        Player p;
        String prefix;
        String suffix;

        Scoreboard scoreboard;
        Team team;

        @SuppressWarnings("deprecation")
        public Titles(Player player, String prefix, String suffix) {
            scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            System.out.println("Registered Scoreboard...");
            team = scoreboard.registerNewTeam("team");
            System.out.println("Registered Team...");
           
            this.prefix = prefix;
            this.suffix = suffix;

            team.setPrefix(this.prefix);
            team.setSuffix(this.suffix);

            System.out.println(" Prefix: " + this.prefix + " Suffix: " + this.suffix);
           
            this.p = player;
           
            if (!team.hasPlayer((OfflinePlayer) player)) {
                System.out.println("Doesn't have player... adding it to the list.");
                team.addPlayer((OfflinePlayer) player);
                System.out.println(team.getPlayers().toString());
            }

            if (scoreboard != null) {
                if (p != null) {
                    p.setScoreboard(scoreboard);
                    System.out.println("Set scoreboard : " + scoreboard.toString());
                } else {
                    System.out.println("Player = null");
                }
            } else {
                System.out.println("Scoreboard = null");
            }

        }

        public void setPrefix(String newPrefix) {
            this.prefix = newPrefix;
        }

        public void setSuffix(String newSuffix) {
            this.suffix = newSuffix;
        }

        public String getPrefix() {
            return this.prefix;
        }

        public String getSuffix() {
            return this.suffix;
        }
    }
     

    So there are two separate scoreboards... Can you only have one scoreboard at a time?
     
  12. Yes there can only be one Scoreboard at a time

    EDIT: As far as I know...
     
  13. Okay, I tried making it so it will only set the titles scoreboard, and it still doesn't show.
     
  14. So you mean that you are still trying to put up 2 Scoreboards at the same time?
     
  15. Yes. I commented out the p.setPlayerListName and saw that the tablist names do change.. just not above heads. Someone else tested this code and sent me a screenshot showing that they used almost the same exact method and it worked for them above head.
     
  16. Can you show me the screenshot?
     
  17. /papi ecloud download (plugin)
     
  18. [QUOTE =“ fujiboy4,post:2338060,member:31201”]我不知道我需要解釋多少,除了名簽不會改變。我使用
    Code (Text):
     Player#setPlayerListName(); [/ CODE]在選項卡列表上更改了顯示名稱...

    這是我當前的代碼:
    [SPOILER =“ Titles.java”] [CODE]公共類標題{

        玩家p;
        字符串前綴;
        字符串後綴;

        計分板計分板;
        團隊團隊;

        @SuppressWarnings(“棄用”)
        公共標題(播放器,字符串前綴,字符串後綴){
            記分板= Bukkit.getScoreboardManager()。getNewScoreboard();
            System.out.println(“ Registered Scoreboard ...”);
            team = scoreboard.registerNewTeam(“ team”);
            System.out.println(“已註冊團隊...”);
         
            this.prefix =前綴;
            this.suffix =後綴;

            team.setPrefix(this.prefix);
            team.setSuffix(this.suffix);

            System.out.println(“前綴:” + this.prefix +“後綴:” + this.suffix);
         
            this.p =玩家;
         
            如果(!team.hasPlayer((OfflinePlayer)播放器)){
                System.out.println(“沒有播放器...將其添加到列表中。”);
                team.addPlayer((OfflinePlayer)播放器);
                System.out.println(team.getPlayers()。toString());
            }

            if(scoreboard!= null){
                如果(p!= null){
                    p.setScoreboard(scoreboard);
                    System.out.println(“ Set scoreboard:” + scoreboard.toString());
                }其他{
                    System.out.println(“ Player = null”);
                }
            }其他{
                System.out.println(“ Scoreboard = null”);
            }

        }

        公共無效setPrefix(String newPrefix){
            this.prefix = newPrefix;
        }

        公共無效setSuffix(String newSuffix){
            this.suffix = newSuffix;
        }

        公共字符串getPrefix(){
            返回this.prefix;
        }

        公共字符串getSuffix(){
            返回this.suffix;
        }
    }
    [/ CODE] [/ SPOILER]

    沒有錯誤,並且堆棧跟踪:

    [SPOILER =“ Stacktrace”]
    [CODE] [19:26:18 INFO]:玩家Fujeh_的UUID為5e36cc82-6029-471f-924b-9f84ac35863d
    [19:26:18 INFO]:註冊計分板...
    [19:26:18 INFO]:註冊團隊...
    [19:26:18 INFO]:前綴:後綴:
    [19:26:18信息]:沒有播放器...將其添加到列表中。
    [19:26:18 INFO]:[CraftPlayer {name = Fujeh_}]
    [19:26:18 INFO]:設置記分板:[email protected]4f1
    [19:26:18 INFO]:Fujeh _ [/ 127.0.0.1:63030]使用實體ID 531登錄到([Hub] -107.72371308932851,4.0,1918.4611040264654)[/ CODE]
    [/ SPOILER]

    希望你們能解決我的問題...:/順便說一句,我確實嘗試了team.addEntry和team.getEntry,但這似乎不起作用。是否需要播放器ign或uuid字符串?

    謝謝。[/ QUOTE]
    how do i run these codes? where where should i put the file in