Scroll Score Name on Scoreboard

Discussion in 'Plugin Development' started by ZonalYewHD, Dec 17, 2014.

Thread Status:
Not open for further replies.
  1. I'm working on a party system for my server, and the scoreboard that each player has shows the party that they are in, and puts the party's name on the scoreboard. However, obviously, if the name is greater than 10 (plus 2 spaces, and 4 color codes), they get kicked with the message that the string cannot be greater than 16. How would I have a scrolling objective name? I've also tried using @Chinwe 's Scroller utility, but when you set the score of a Score object, it is added to the scoreboard, not replaced. Therefore, the scoreboard will work, add as many lines as possible, and then disappear.
     
  2. Offline

    Skionz

    @ZonalYewHD Create a scheduler that updates the scoreboard with a 'scrolling' name? You would have to do some string parsing.
     
    GrandmaJam likes this.
  3. Offline

    97WaterPolo

    @ZonalYewHD
    If I remember correctly, an objective name can have 32 characters? :confused: The score names can only have 16. You could use team prefix and suffixes to account for the extra spaces in a player's name.
     
  4. @Skionz @97WaterPolo
    The method I use for for creating a scoreboard is below:
    Code:
    public Scoreboard createMainBoard() {
            this.s = Bukkit.getScoreboardManager().getNewScoreboard();
            this.o = s.registerNewObjective(file.getUniqueID().toString()
                    .substring(0, 15), "dummy");
    
            name = new Scroller(BOLD + "Welcome " + file.getPlayerName() + "!", 11,
                    5, '&');
    
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
    
            Score blank1 = o.getScore(RESET.toString());
            Score pixels = o.getScore("" + AQUA + BOLD + "Pixels");
            Score pixelsV = o.getScore("  " + WHITE + BOLD
                    + pm.getFormattedPixels());
            Score blank2 = o.getScore(RESET.toString() + RESET.toString());
            Score rank = o.getScore("" + GREEN + BOLD + "Rank");
            Score rankV = o.getScore("  " + rm.getCurrentRank().getRankColor()
                    + BOLD + rm.getCurrentRank().getName());
            Score blank3 = o.getScore(RESET.toString() + RESET.toString()
                    + RESET.toString());
            Score friendsOnline = o.getScore("" + GOLD + BOLD + "Friends");
            Score friendsOnlineV = o.getScore("  " + BOLD + fm.getOnlineFriends()
                    + " / " + fm.getFriends().size());
            Score blank4 = o.getScore(RESET.toString() + RESET.toString()
                    + RESET.toString() + RESET.toString());
            Score party = o.getScore("" + LIGHT_PURPLE + BOLD + "Party");
            Score line = o.getScore(BOLD + "--------------");
            if (!Party.hasParty(Bukkit.getPlayer(playerID))) {
                o.getScore("  " + BOLD + "None").setScore(1);
            } else {
                if (Party.getParty(Bukkit.getPlayer(playerID)).getName().length() > 10) {
                    partyName = new Scroller(Party.getParty(
                            Bukkit.getPlayer(playerID)).getName(), 10, 4, '&');
                    Bukkit.getScheduler().scheduleSyncRepeatingTask(
                            ParkourCraft.get(), new Runnable() {
    
                                public void run() {
                                    o.getScore(
                                            YELLOW.toString() + BOLD
                                                    + partyName.next()).setScore(1);
                                }
                            }, 0, 10);
                } else
                    o.getScore(
                            "  "
                                    + BOLD
                                    + Party.getParty(Bukkit.getPlayer(playerID))
                                            .getName()).setScore(1);
                ;
            }
    
            blank1.setScore(12);
            pixels.setScore(11);
            pixelsV.setScore(10);
            blank2.setScore(9);
            rank.setScore(8);
            rankV.setScore(7);
            blank3.setScore(6);
            friendsOnline.setScore(5);
            friendsOnlineV.setScore(4);
            blank4.setScore(3);
            party.setScore(2);
            line.setScore(0);
    
            Bukkit.getScheduler().scheduleSyncRepeatingTask(ParkourCraft.get(),
                    new Runnable() {
    
                        public void run() {
                            strB = new StringBuilder(randomColor() + name.next());
                            o.setDisplayName(strB.toString().trim());
                        }
                    }, 0, 5);
    
            return this.s;
        }
    
    
    EDIT: I forgot to mention, if your party's name is less than 10 characters, it shows up fine. Everything works unless the name is more than 10 characters.
     
  5. Offline

    97WaterPolo

  6. @97WaterPolo I'd prefer to come up with my own method, if at all possible. Now, I will ask for help if I need it, but I don't want to use third-party APIs if I can help it.
     
  7. Offline

    Webbeh

    The basics :

    Code:
    title = The full title with a lot of chars;
    actualPos = 0;
    
    new runnable(every X ticks, depending on the speed you want it to scroll) {
      display substring(title, start at actualPos, end at actualPos+16)
      actualPos++
      if(actualPos > title length-16) actualPos = 0
    }
    
     
    GrandmaJam likes this.
  8. @Webbeh I'm not trying to scroll the title. I've already done that. I'm trying to scroll a score name. I realize the title is misleading. Fixing that now
     
  9. Offline

    Webbeh

    It's the exact same method.
     
    GrandmaJam and Skionz like this.
Thread Status:
Not open for further replies.

Share This Page