[Resource] Functional Board

Discussion in 'Resources' started by JPG2000, Nov 21, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    JPG2000

    I have created a quick class, allowing you to display information on a scoreboard with ease!

    Basicly, this can display information really easily. It sets the score in the order you set it in, so it reads from up to down. The actually score (number in read) will be oblivious, I wouldn't change it. Its men't to make an easy board like Mineplex's, that don't actually use the score numbers.

    To make this:
    [​IMG]


    All we have to do is:
    Code:
    FunctionalBoard board = new FunctionalBoard("My Scoreboard", "Welcome player", "Have fun player", "Enjoy! :P");
     
    FunctionalBoard.setBoard(player, board);

    Heres basically how it works:
    Code:
    //Create a FunctionalBoard object
    FunctionalBoard board = new FunctionalBoard("SB Name", "Unlimited scores");
    //This creates a new board, with the name "SB Name" and adds 1 score
     
    //We can also add scores to the board, not when we make it:
    board.addLine("My line");
     
    //If we wanted to get a Line to change the score or something, we can do:
    board.getLine("line");
     
    //And finally to show the board, use the static method:
    FunctionalBoard.setBoard(player, board);


    And the code:

    Code:
    package me.jpg.testplugin;
     
    import java.util.ArrayList;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
     
    /**
    *
    * @Author Jake
    */
    public class FunctionalBoard {
     
        private static Scoreboard board;
     
        private ArrayList<Score> score;
     
        private Objective o;
     
        public FunctionalBoard() {
     
        }
     
        public FunctionalBoard(String name, String... lines) {
            board = Bukkit.getScoreboardManager().getNewScoreboard();
     
            score = new ArrayList<Score>();
     
            o = board.registerNewObjective("objective", "dummy");
            o.setDisplayName(name);
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
     
            int counter = lines.length;
     
            for (String s : lines) {
                score.add(o.getScore(Bukkit.getOfflinePlayer(s)));
     
                o.getScore(Bukkit.getOfflinePlayer(s)).setScore(counter);
                counter--;
            }
        }
     
        public Score getLine(String line) {
            return o.getScore(Bukkit.getOfflinePlayer(line));
        }
     
        public void addLine(String... lines) {
     
            for (String s : lines) {
                score.add(o.getScore(Bukkit.getOfflinePlayer(s)));
            }
     
            int counter = score.size();
     
            for (Score s : score) {
                o.getScore(s.getPlayer()).setScore(counter);
                counter--;
            }
        }
     
        public ArrayList<Score> getScores() {
            return score;
        }
     
        public static void setBoard(Player player, FunctionalBoard fb) {
            player.setScoreboard(board);
        }
     
    }

    http://pastebin.com/pHhAMGT5

    So to clear it up, its just basically an object you can make that you can easily set information on the board.

    I did a test, and with my class, I made a SB that took 2 lines of code. When I used the BukkitAPI's Scoreboard, it took me 18 lines of code.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
    Phasesaber likes this.
  2. Offline

    ArthurMaker

    Awesome! Thanks :D
     
    JPG2000 likes this.
  3. Offline

    Garris0n

    You can use team prefixes/suffixes to make each line 48 characters max I believe.
     
    JPG2000 likes this.
  4. Offline

    JPG2000

    Garris0n Maybee I'll implement it in a new version.
     
  5. Offline

    Chlorek

    Garris0n
    Could you tell me how to make it 48 characters long (or any longer than 16 -,- )? Would be very helpful!
     
  6. Offline

    DrJava

    Could create scrolling text?
     
  7. Offline

    Garris0n

    Prefixes and suffixes of teams. Look in the resources section for the scoreboard tutorial.
     
  8. Offline

    BeatCycle

    board.getLine("line") how to use? example please
    ;)
     
  9. Offline

    mazentheamazin

  10. Offline

    BeatCycle

    Thanks!
     
  11. Offline

    HeavyMine13

    How can I make it so it updates?
     
  12. Offline

    indyetoile

Thread Status:
Not open for further replies.

Share This Page