Util SimpleScoreboard - Make pretty scoreboards with ease!

Discussion in 'Resources' started by RainoBoy97, Apr 30, 2014.

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

    CraftCreeper6

    Speaw
    You're using Spigot...
    coco5843 You probably are too...
     
  2. Offline

    lucasdidur

    I found the solution, implements a OfflinePlayer new class that accept name in blank and then replace here

    Code:
    OfflinePlayer player = new Message(team.getValue());
    
     
    coco5843 likes this.
  3. Offline

    Speaw

    How can i use it?
     
  4. Offline

    lucasdidur

    Speaw likes this.
  5. Offline

    Zyraun

    How would I update an OfflinePlayer's name on the scoreboard? For example,

    [Scoreboard Title]
    Name score
    Name score

    Is there a simple way to update what the Name shows up as?
     
  6. Offline

    Slimey101-Dev

    RainoBoy97 I can't even get this to work for me.
    Code:
    Code:
        private Scoreboard scoreboard;
     
        private String title;
        private Map<String, Integer> scores;
        private List<Team> teams;
     
        public Board(String title) {
                this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
                this.title = title;
                this.scores = Maps.newLinkedHashMap();
                this.teams = Lists.newArrayList();
        }
     
        public void blankLine() {
                add(" ");
        }
     
        public void add(String text) {
                add(text, null);
        }
     
        public void add(String text, Integer score) {
                Preconditions.checkArgument(text.length() < 48, "text cannot be over 48 characters in length");
                text = fixDuplicates(text);
                scores.put(text, score);
        }
     
        private String fixDuplicates(String text) {
                while (scores.containsKey(text))
                        text += "§r";
                if (text.length() > 48)
                        text = text.substring(0, 47);
                return text;
        }
     
        private Map.Entry<Team, String> createTeam(String text) {
                String result = "";
                if (text.length() <= 16)
                        return new AbstractMap.SimpleEntry<>(null, text);
                Team team = scoreboard.registerNewTeam("text-" + scoreboard.getTeams().size());
                Iterator<String> iterator = Splitter.fixedLength(16).split(text).iterator();
                team.setPrefix(iterator.next());
                result = iterator.next();
                if (text.length() > 32)
                        team.setSuffix(iterator.next());
                teams.add(team);
                return new AbstractMap.SimpleEntry<>(team, result);
        }
     
        @SuppressWarnings("deprecation")
        public void build() {
                Objective obj = scoreboard.registerNewObjective((title.length() > 16 ? title.substring(0, 15) : title), "dummy");
                obj.setDisplayName(title);
                obj.setDisplaySlot(DisplaySlot.SIDEBAR);
     
                int index = scores.size();
     
                for (Map.Entry<String, Integer> text : scores.entrySet()) {
                        Map.Entry<Team, String> team = createTeam(text.getKey());
                        Integer score = text.getValue() != null ? text.getValue() : index;
                        OfflinePlayer player = Bukkit.getOfflinePlayer(team.getValue());
                        if (team.getKey() != null)
                                team.getKey().addPlayer(player);
                        obj.getScore(player).setScore(score);
                        index -= 1;
                }
        }
     
        public void reset() {
                title = null;
                scores.clear();
                for (Team t : teams)
                        t.unregister();
                teams.clear();
        }
     
        public Scoreboard getScoreboard() {
                return scoreboard;
        }
     
        public void send(Player... players) {
                for (Player p : players)
                        p.setScoreboard(scoreboard);
        }
     
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
                Player player = event.getPlayer();
                // create a new scoreboard with title
                Board scoreboard = new Board("§a§lFeatures:");
                // text with custom score
                scoreboard.add("§lCustom scores ->", 1337);
                // also supports blank lines (up to 23 of them!)
                scoreboard.blankLine();
                scoreboard.add("§cBLANK LINES");
                scoreboard.blankLine();
                // if you dont specify a score it will display them in the order you add them in
                scoreboard.add("lines");
                scoreboard.add("§bin");
                scoreboard.add("§edescending");
                scoreboard.add("§2order");
                scoreboard.add(":)");
                scoreboard.blankLine();
                // the text can be up to 48 characters long (including color codes)
                scoreboard.add("and long lines with up to §l48 characters");
                // call this to create the scoreboard, nothing will happen if you forget to call this
                scoreboard.build();
                // send the scoreboard to the player(s), takes an array
                scoreboard.send(player);
        }
    }
     
    GrandmaJam likes this.
  7. Offline

    jpriani13

    The gist that mazentheamazin posted was deleted, Did anyone ever come up with a solution to updating the scoreboard?
     
  8. Offline

    Borrachondo

    Also the same problem :/ Please help
     
  9. Offline

    jjssman

    Anyway I'm currently achieving this using ProtocolLib, but It would be awesome if someone created a lib / resource to do it. (other than bukkit's builtin scoreboard api)
     
  10. Offline

    Borrachondo

    ProtocolLib has an API scoreboard? I'll use it right now.
     
  11. Fillefixsweden Spigot has issues with this as it was designed for Bukkit.

    For anyone having issues, if you are using Spigot that is the problem and this isn't the place to report it. Please poat in the Bukkit Alternates section.
     
  12. Offline

    LFPlugins

    Moved to other section.
     
  13. Offline

    Skionz

    LFPlugins Is the markup actually in your code? Lol
     
  14. Offline

    LFPlugins

  15. Offline

    Zer0DZN

    How to Make Kills and Deaths Scores? im a little confused
     
    GrandmaJam likes this.
  16. Offline

    567legodude

    This is a great utility, and it makes a great scoreboard. I have tried the various methods people have posted on the forum, and tried making one myself, but I can't get what I need.

    Can someone make a method that will take one of the items on the scoreboard, and change the name. So I need it to stay in the same place on the scoreboard, but I need to change the name of that item.
     
  17. Offline

    matanrak

  18. Offline

    Shawckz

    https://gist.github.com/Shawckz/17db140258ec47907a7e

    (just wrote it, not totally tested so lemme know if it works or not)

    Note: I wrote this on the spigot API (it should also work on bukkit)

    If you get an error on
    Code:
    objective.getScore(value).setScore(i);
    Change it to
    Code:
    objective.getScore(Bukkit.getOfflinePlayer(value)).setScore(i);
    To use:

    Code:
    PlayerBoard playerBoard = new PlayerBoard(player,"Display Name");//create a playerboard for our player
            playerBoard.setLine(9,"Some score");//remember, scoreboard's scores are ordered in descending order
            playerBoard.setBlank(8);//creates a blank line with score 8
            playerBoard.build();//must call this before sending/updating
            playerBoard.send();
         
            //TO UPDATE:
            playerBoard.setLine(9,"Updated score"); //changes "Some score" to "Updated Score"
            playerBoard.update();//automatically gets player's scoreboard and updates it
    Please provide constructive criticism as this is my first post.
     
  19. Offline

    matanrak

    its gives out errors
    Code:
    23.12 14:09:45 [Server] INFO at me.matanrak.MelonCore.MelonCore.showScoreboard(MelonCore.java:91) ~[?:?]
    23.12 14:09:45 [Server] INFO at me.matanrak.MelonCore.PlayerBoard.setLine(PlayerBoard.java:37) ~[?:?]
    23.12 14:09:45 [Server] INFO at me.matanrak.MelonCore.PlayerBoard.fixText(PlayerBoard.java:45) ~[?:?]
    23.12 14:09:45 [Server] INFO Caused by: java.lang.NullPointerException
    23.12 14:09:45 [Server] INFO at java.lang.Thread.run(Unknown Source) [?:1.7.0_55]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.run(MinecraftServer.java:528) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.y(MinecraftServer.java:625) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.DedicatedServer.z(DedicatedServer.java:316) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.MinecraftServer.z(MinecraftServer.java:786) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.ServerConnection.c(ServerConnection.java:82) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.NetworkManager.a(NetworkManager.java:159) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.LoginListener.c(LoginListener.java:41) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.LoginListener.b(LoginListener.java:109) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerList.a(PlayerList.java:147) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at net.minecraft.server.v1_8_R1.PlayerList.onPlayerJoin(PlayerList.java:262) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:494) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:509) [Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:303) ~[Spigot18.jar:git-Spigot-"609cd55"]
    23.12 14:09:45 [Server] INFO org.bukkit.event.EventException
     
  20. Offline

    lucasdidur

    ChipDev likes this.
  21. Offline

    matanrak

  22. Offline

    Shawckz

    Updated the gist, should be fixed.
     
  23. Offline

    zurg200

    D: Doesnt work for me.. I did everything and the scoreboard doesnt show up :mad:

    I did not add it to onEnable Should i have?
    if thats the problem can someone help me fix it
     
  24. Offline

    matanrak

    lucasdidur likes this.
  25. Offline

    zurg200

    Could u help me fix this.. I can't get mine working.. Pm me.. I'm struggling with this a lot
     
  26. Offline

    matanrak

    Ok what are the erros given?
     
  27. Offline

    zurg200

    No errors. It just doesn't show up.. Do I have to add it to the join event too? Cause I didn't do that
     
  28. Offline

    DemKazoo

    Cool, definitly using this. Quick question, does this also support belowName();?
     
  29. Offline

    macboinc

    How do I update scoreboard
     
  30. Offline

    spiderking220

    For anyone using Spigot with this I have the solution to making the All-In-One class given by @lucasdidur if you're having trouble getting it working. In his class, you'll need to set the title to avoid a NullPointerException. To do this, add the title in the constructor and register it.

    Title:
    Code:
     public SimpleScoreboard(String title)
            {
                this.scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
                this.scores = Maps.newLinkedHashMap();
                this.teams = Lists.newArrayList();
    
                this.title = "Title Name Here";
            }
    Put this in your Main class:

    Code:
    SimpleScoreboard scoreboard = new SimpleScoreboard("Title Name Here");
    
    I don't know if this will help anyone but I hope someone can get some use out of this.
     
Thread Status:
Not open for further replies.

Share This Page