Tutorial Scrolling scoreboards

Discussion in 'Resources' started by whereisthemonkey, Dec 31, 2015.

Thread Status:
Not open for further replies.
  1. Hey,

    Did you ever want a scrolling scoreboard like mineplex?
    Than this tutorial s perfect for you. I will teach you how to create your own scrolling scoreboard in only a few minutes:

    First we need a scoreboard class:
    Show Spoiler

    PHP:

    public class ScoreBoard {



    }



    Now we need a basic constructor:
    Show Spoiler

    PHP:

        
    private Player player;

        public 
    ScoreBoard(Player player){
            
    this.player player;
        }



    Now we need to register thescoreboard:
    Show Spoiler

    PHP:

        
    private Player player;
        private 
    Scoreboard scoreboard;
        private 
    Objective test;
        private 
    int scheduler;

        public 
    ScoreBoard(Player player){
            
    this.player player;
            
    this.scoreboard Bukkit.getScoreboardManager().getNewScoreboard();
        
            
    this.test scoreboard.registerNewObjective("test""dummy");
            
    this.test.setDisplayName(ChatColor.DARK_RED "" ChatColor.BOLD "TEST");
            
    this.test.setDisplaySlot(DisplaySlot.SIDEBAR);
        }



    Now we add the class message:
    Show Spoiler

    PHP:

        
    public void scrollingMessage(String messageChatColor color){
            
    scheduler Bukkit.getScheduler().scheduleSyncRepeatingTask(MainClass.getInstance(), new Runnable() {
            
                
    int index 0;
                
    String last " " message.substring(indexindex 16) + " ";
            
                @
    Override
                
    public void run() {
                    if(
    player.getPlayer().isOnline()){
                        
    scoreboard.resetScores(color last);
                    
                        
    index++;
                    
                        if(
    index 16 >= message.length() + 1){
                            
    index 0;
                        }
                    
                        
    last " " message.substring(indexindex 16) + " ";
                        
    Score score title.getScore(color last);
                        
    score.setScore(7);
                        
    player.getPlayer().setScoreboard(scoreboard);
                    }else{
                        
    Bukkit.getScheduler().cancelTask(scheduler);
                    }
                }
            }, 
    2020);
        }

    What this class does is it takes the string message and cuts it to a length of 16. Then it takes this string and displays it, by moving the delimiters of the string to one to the right each time. If the delimiters run out, the whole thing is reset to 0 and everything begins again.

    MainClass.getInstance() is a link to your mainclass


    Here's the whole class again:
    Show Spoiler

    PHP:

        
    private Player player;
        private 
    Scoreboard scoreboard;
        private 
    Objective test;
        private 
    int scheduler;

        public 
    ScoreBoard(Player player){
            
    this.player player;
            
    this.scoreboard Bukkit.getScoreboardManager().getNewScoreboard();
        
            
    this.test scoreboard.registerNewObjective("test""dummy");
            
    this.test.setDisplayName(ChatColor.DARK_RED "" ChatColor.BOLD "TEST");
            
    this.test.setDisplaySlot(DisplaySlot.SIDEBAR);
        }

        public 
    void scrollingMessage(String messageChatColor color){
            
    scheduler Bukkit.getScheduler().scheduleSyncRepeatingTask(MainClass.getInstance(), new Runnable() {
            
                
    int index 0;
                
    String last " " message.substring(indexindex 16) + " ";
            
                @
    Override
                
    public void run() {
                    if(
    player.getPlayer().isOnline()){
                        
    scoreboard.resetScores(color last);
                    
                        
    index++;
                    
                        if(
    index 16 >= message.length() + 1){
                            
    index 0;
                        }
                    
                        
    last " " message.substring(indexindex 16) + " ";
                        
    Score score title.getScore(color last);
                        
    score.setScore(7);
                        
    player.getPlayer().setScoreboard(scoreboard);
                    }else{
                        
    Bukkit.getScheduler().cancelTask(scheduler);
                    }
                }
            }, 
    2020);
        }



    Now have fun with your new scrolling board by sending it to your player:
    PHP:

    ScoreBoard board 
    = new ScoreBoard(player);
            
    board.scrollingMessage("Welcome " player.getName(), ChatColor.GOLD);

    Please report any bugs in the comment, I will try to keep this thread up to date.
    If you're using this code crediting me would be awesome.

    Have a happy new year and see you soon for more tutorials!!
     
    Last edited: Dec 31, 2015
  2. Offline

    teej107

    @whereisthemonkey You might want to nullify that Player field once they log out. Also where the heck did the display() method come from?
     
  3. @teej107 Yeah, I got my class with more stuff and there I got a display() function
    And do you mean stopping the scheduler with nullfying the player?
     
  4. Offline

    Gorbit99

    I wouldn't call this a "Tutorial". You're just spoonfeeding the code without any explanation or even comments.
     
Thread Status:
Not open for further replies.

Share This Page