How would I add a [Rank] on this scoreboard?

Discussion in 'Spigot Plugin Development' started by AutoRemixSound, May 23, 2017.

  1. This is what I got so far

    Code (Text):

    package me.camismgmt.scoreboard;
    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {

        static ArrayList<String> A = new ArrayList<String>();
     
     
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "AnimateScoreboard is now enabled!");
        }
     
        public void add(final Player player) {
            final ScoreboardManager manager = Bukkit.getScoreboardManager();
            final Scoreboard board = manager.getNewScoreboard();
         
            Objective objective = board.registerNewObjective("Scoreboard", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
         
            Score spacer = objective.getScore("§f");
            spacer.setScore(2);
         
            Score score = objective.getScore(ChatColor.GRAY + "BlockCraftMC.net");
            score.setScore(1);
         
            A.clear();
            A.add("1");
         
         
            BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
            Scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
                [USER=32110]@Override[/USER]
                public void run() {
                    Integer i = A.size();
                    if(i == 1) {
                        objective.setDisplayName(Colors("&b&lBlockCraft"));
                        A.add("A");
                    }
                    if(i == 2) {
                        objective.setDisplayName(Colors("&a&lBlockCraft"));
                        A.add("B");
                    }
                    if(i == 3) {
                        objective.setDisplayName(Colors("&6&lBlockCraft"));
                        A.add("C");
                    }
                    if(i == 3) {
                        A.clear();
                        A.add("1");
                    }
                }
            }, 0, 5);
            player.setScoreboard(board);
        }
     
        public static String Colors(String text) {
            return text.replaceAll("&", "§");
        }
     
        [USER=17846]@EventHandler[/USER]
        public void PlayerJoinEvent(PlayerJoinEvent e) {
            Player p = e.getPlayer();
            this.add(p);
        }
     
    }
     
     
    #1 AutoRemixSound, May 23, 2017
    Last edited: May 24, 2017
  2. Put the code in
    [CODE]here[/CODE]
    so that it retains formatting
     
  3. Code (Text):

    package me.camismgmt.scoreboard;
    import java.util.ArrayList;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scheduler.BukkitScheduler;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Main extends JavaPlugin implements Listener {

    static ArrayList<String> A = new ArrayList<String>();


    public void onEnable() {
    Bukkit.getPluginManager().registerEvents(this, this);
    Bukkit.getConsoleSender().sendMessage(ChatColor.GREEN + "AnimateScoreboard is now enabled!");
    }

    public void add(final Player player) {
    final ScoreboardManager manager = Bukkit.getScoreboardManager();
    final Scoreboard board = manager.getNewScoreboard();

    Objective objective = board.registerNewObjective("Scoreboard", "dummy");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);

    Score spacer = objective.getScore("§f");
    spacer.setScore(2);

    Score score = objective.getScore(ChatColor.GRAY + "BlockCraftMC.net");
    score.setScore(1);

    A.clear();
    A.add("1");


    BukkitScheduler Scheduler = Bukkit.getServer().getScheduler();
    Scheduler.scheduleSyncRepeatingTask(this, new Runnable() {
    @Override
    public void run() {
    Integer i = A.size();
    if(i == 1) {
    objective.setDisplayName(Colors("&b&lBlockCraft"));
    A.add("A");
    }
    if(i == 2) {
    objective.setDisplayName(Colors("&a&lBlockCraft"));
    A.add("B");
    }
    if(i == 3) {
    objective.setDisplayName(Colors("&6&lBlockCraft"));
    A.add("C");
    }
    if(i == 3) {
    A.clear();
    A.add("1");
    }
    }
    }, 0, 5);
    player.setScoreboard(board);
    }

    public static String Colors(String text) {
    return text.replaceAll("&", "§");
    }

    @EventHandler
    public void PlayerJoinEvent(PlayerJoinEvent e) {
    Player p = e.getPlayer();
    this.add(p);
    }

    }
    [\code]
     
  4. There you go ! Is that better ?
     
  5. Are you trying to add the players rank to the scoreboard or add their rank in front of their name?
     
  6. I'm trying to have it kinda like this photo
    [​IMG]
     
  7. If you want to display what their prefix is, you can make your normal scoreboard and get the pex api just check the prefix/suffix/whateveryouwant and set that as the team prefix