Solved Scoreboard Library

Discussion in 'Plugin Development' started by MaTaMoR_, Mar 29, 2015.

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

    MaTaMoR_

    Hi, im looking for a Scoreboard libraby cuz i couldn't make a scoreboard by myself (i don't know how to update it without flazhing) .
     
    Last edited: Mar 29, 2015
  2. @MaTaMoR_ More than likely you are just creating the same scoreboard when you're updating it. If not, please post the code you use to update it.
     
  3. Offline

    MaTaMoR_

    Code:
    public void updateBuffer(Scoreboard scoreboard, Objective buffer) {
            Objective t = scoreboard.getObjective("t");
            Objective objective = scoreboard.getObjective("objective");
            t = objective;
            objective = buffer;
            buffer = t;
            buffer.unregister();
            buffer = scoreaboard.registerNewObjective("buffer", "dummy"); // Here's the problem
    }
    public void updateScoreboard(Player player) {
            Scoreboard scoreboard = player.getScoreboard();
            Objective buffer = scoreboard.getObjective("buffer");
            setUpObjective(player, buffer);
            buffer.setDisplaySlot(DisplaySlot.SIDEBAR);
            updateBuffer(scoreboard, buffer);
    }
    
     
    Last edited: Mar 29, 2015
  4. Offline

    ferrago

    @MaTaMoR_
    You are reregistering the new objective rather than just changing values currently in it. You can't really get around a flicker if you use this method.
     
  5. Offline

    MaTaMoR_

    a good programmer told me to use that, ¿ what i should do ?

    Fixed, i made this class and it works perfect :

    Code:
    public class IScoreboard {
     
    public static Map<UUID, IScoreboard> IBoards = new HashMap<>();
    private final Map<Integer, String> Body = new HashMap<>();  
    
    private UUID uuid;
    private Scoreboard board;
    private Objective objective;
    private Objective t;
    private Objective buffer;
    private String title;
    
    private String c(String text) {
        return ChatColor.translateAlternateColorCodes('&', text);
    }
    public static IScoreboard getIScoreboard(IPlayer iplayer) {
        return get(iplayer.getUUID());
    }
    private static IScoreboard get(UUID uuid) {
        if(IBoards.containsKey(uuid)) {
            return IBoards.get(uuid);
        }
     
        IScoreboard iboard = new IScoreboard();
        iboard.uuid = uuid;
        iboard.board = EDLB.ScoreboardManager.getNewScoreboard();
        iboard.objective = iboard.board.registerNewObjective("objective", "dummy");
        iboard.t = iboard.board.registerNewObjective("t", "dummy");
        iboard.buffer = iboard.board.registerNewObjective("buffer", "dummy");
        iboard.title = "&7Scoreboard";
     
        IBoards.put(uuid, iboard);
        return iboard;
    }
    
    public void setLine(int line, String text) {
        this.Body.put(line, text);
    }
    public void removeLine(int line) {
        this.Body.remove(line);
    }
    public void clearBody() {
        this.Body.clear();
    }
    public void setTitle(String title) {
        this.title = title;
    }
    public String getTitle() {
        return this.title;
    }
    private void setValues(Objective objective) {
        int Colour = 0;
     
        objective.setDisplayName(c(title));
     
        for(int line : Body.keySet()) {
         
            if(line > 15) {
             
                continue;
             
            }
         
            String text = Body.get(line);
         
            if(text.equals("")) {
             
                text = "&" + Colour;
                Colour++;
             
            }
         
            objective.getScore(c(text)).setScore(line);
        }
    }
    public void setIScoreboard() {
        Player player = Bukkit.getPlayer(uuid);
        objective.setDisplaySlot(DisplaySlot.SIDEBAR);
     
        setValues(objective);
     
        player.setScoreboard(board);
    }
    
    public void updateIScoreboard() {  
        buffer.setDisplaySlot(DisplaySlot.SIDEBAR);
        setValues(buffer);
     
        t = objective;  
        objective = buffer;
        buffer = t;
     
        String bufferName = buffer.getName();
        reRegisterBuffer(bufferName);
    }
    private void reRegisterBuffer(String bufferName) {
        buffer.unregister();
        buffer = board.registerNewObjective(bufferName, "dummy");
    }
    public void setDefaults() {
        IPlayer iplayer = IPlayer.getIPlayer(Bukkit.getPlayer(uuid));
     
                    setLine(15, "");
                    setLine(14, "&5&lQuarks &d" + iplayer.getQuarks());
                    setLine(13, "");
                    setLine(12, "&6&lGames &e" + iplayer.getGames());
                    setLine(11, "");
                    setLine(10, "&3&lWins &b" + iplayer.getWins());
                    setLine(9, "");
                 
        setIScoreboard();
    }
    public void updateQuarks() {
        IPlayer iplayer = IPlayer.getIPlayer(Bukkit.getPlayer(uuid));
     
        setLine(14, "&5&lQuarks &d" + iplayer.getQuarks());
     
        updateIScoreboard();
    }
    public void updateGames(){
        IPlayer iplayer = IPlayer.getIPlayer(Bukkit.getPlayer(uuid));
     
        setLine(12, "&6&lGames &e" + iplayer.getGames());
     
        updateIScoreboard();
    }
    public void updateWins() {
        IPlayer iplayer = IPlayer.getIPlayer(Bukkit.getPlayer(uuid));
     
        setLine(10, "&3&lWins &b" + iplayer.getWins());
     
        updateIScoreboard();
    }
    }
    
     
    Last edited by a moderator: Mar 29, 2015
Thread Status:
Not open for further replies.

Share This Page