... Scoreboard ...

Discussion in 'Spigot Plugin Development' started by Sunique, Jun 25, 2016.

  1. Heres the refresh code.
    Code (Text):
        public Game(int gameNumber, String map) {
            this.gameNumber = gameNumber;
            if (SkyWarsReloaded.getCfg().signJoinMode()) {
                mapName = map;
            }
            int size = SkyWarsReloaded.getCfg().getMaxMapSize()/2;
            min = 0 - size;
            max = 0 + size;
            if (SkyWarsReloaded.getCfg().getSpawn() == null) {
                SkyWarsReloaded.get().getLogger().info("YOU MUST SET SPAWN IN THE LOBBY WORLD WITH /SWR SETSPAWN BEFORE STARTING A GAME");
                endGame();
            }
            gameState = GameState.PREGAME;
            getGameMap();
            getScoreBoard();

            SkyWarsReloaded.get().getServer().getScheduler().scheduleSyncRepeatingTask(SkyWarsReloaded.get(),
                    new Runnable() {
                @Override
                public void run() {
                    if(gameState.equals(GameState.PLAYING)){
                        updateScoreboard();
                        if(timeLeft > 0)
                            timeLeft--;
                    }else{
                        return;
                    }
                }
            },20L,20L);
        }
     
  2. dont reload
     
  3. Alfie

    Patron

    That doesn't help - we need the updateScoreboard() void code.
     
  4. hmm
     
  5. I have updated SimpleScoreboard util from Bukkit Forums, it have a lot of useful methods. You can use it. If you want, I can explain all methods here:
    Code (Java):
    package ru.enervate.stainy.game.utils;

    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.scoreboard.*;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.concurrent.CopyOnWriteArrayList;

    @SuppressWarnings("deprecation")
    public class ScoreboardUtil {

        private static List<ScoreboardUtil> sbs = new ArrayList<>();
        private List<Score> list = new CopyOnWriteArrayList<>();

        private String objective;
        private String title;
        private Scoreboard sb;

        public ScoreboardUtil(String objective, String title, Scoreboard sb) {
            Objective obj = sb.getObjective(objective) != null ? sb.getObjective(objective) : sb.registerNewObjective(objective, "dummy");

            obj.setDisplayName(title);
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);

            this.objective = objective;
            this.title = title;
            this.sb = sb;

            sbs.add(this);
        }

        public static ScoreboardUtil getByScoreboard(Scoreboard sb) {
            for(ScoreboardUtil su : sbs) {
                if(su.getScoreboard().equals(sb)) return su;
            }

            return null;
        }

        public void add(String p, String n, String s) {
            add(p, n, s, null);
        }

        public void add(String p, String n, String s, Integer line) {
            Score sc = new Score(p, fixDuplicates(n), s);
            sc.setLine(line);
            list.add(sc);
        }

        public void blankLine() {
            add("", "§r", "", null);
        }

        private String fixDuplicates(String s) {
            for(Score sc : list) {
                while (sc.getScore().equalsIgnoreCase(s)) {
                    s += "§r";
                }
            }

            if (s.length() >= 32) s = s.substring(0, 31);

            return s;
        }

        public void build() {
            for(Team t : sb.getTeams()) {
                t.unregister();
            }

            Objective obj = sb.getObjective(objective);

            int index = list.size();

            for(Score sc : list) {
                OfflinePlayer p = Bukkit.getOfflinePlayer(sc.getScore());
                sb.resetScores(p);
                Team t = sb.registerNewTeam("text-" + index);
                t.setPrefix(sc.getPrefix());
                t.setSuffix(sc.getSuffix());
                t.addPlayer(p);

                if(sc.getLine() != null) {
                    obj.getScore(p).setScore(sc.getLine());
                } else {
                    obj.getScore(p).setScore(index);
                    sc.setLine(index);
                }

                index--;
            }
        }

        public void removeScore(String scoreName) {
            for(Score sc : list) {
                if(sc.getScore().equalsIgnoreCase(scoreName)) {
                    sb.resetScores(Bukkit.getOfflinePlayer(scoreName));
                    list.remove(sc);
                }
            }
        }

        public String findScore(String piece) {
            for(Score sc : list) {
                if (sc.getScore().toLowerCase().contains(piece.toLowerCase())) {
                    return sc.getScore();
                }
            }

            return "";
        }

        public Score getScore(String score) {
            for(Score sc : list) {
                if (sc.getScore().equalsIgnoreCase(score)) {
                    return sc;
                }
            }

            return null;
        }

        public void updatePrefix(String scoreName, String prefix) {
            update(scoreName, prefix, getScore(scoreName).getSuffix());
        }

        public void updateSuffix(String scoreName, String suffix) {
            update(scoreName, getScore(scoreName).getPrefix(), suffix);
        }

        public void update(String scoreName, String prefix, String suffix) {
            for(Score sc : list) {
                if(sc.getScore().equalsIgnoreCase(scoreName)) {
                    Team t = sb.getPlayerTeam(Bukkit.getOfflinePlayer(scoreName));
                    t.setPrefix(prefix);
                    sc.setPrefix(prefix);
                    t.setSuffix(suffix);
                    sc.setSuffix(suffix);
                }
            }
        }

        public void updateLine(String scoreName, int line) {
            for(Score sc : list) {
                if(sc.getScore().equalsIgnoreCase(scoreName)) {
                    sc.setLine(line);
                    sb.getObjective(objective).getScore(Bukkit.getOfflinePlayer(scoreName)).setScore(line);
                }
            }
        }

        public static List<ScoreboardUtil> getScoreboards() {
            return sbs;
        }

        public String getTitle() {
            return title;
        }

        public String getObjective() {
            return objective;
        }

        public Scoreboard getScoreboard() {
            return sb;
        }

        public class Score {

            private String prefix;
            private String score;
            private String suffix;
            private Integer line;

            public Score(String prefix, String score, String suffix) {
                this.score = fixDuplicates(score);
                this.suffix = suffix;
                this.prefix = prefix;
            }

            public String getPrefix() {
                return prefix;
            }

            public void setPrefix(String prefix) {
                this.prefix = prefix;
            }

            public String getScore() {
                return score;
            }

            public String getSuffix() {
                return suffix;
            }

            public void setSuffix(String suffix) {
                this.suffix = suffix;
            }

            public Integer getLine() {
                return line;
            }

            public void setLine(Integer line) {
                this.line = line;
            }
        }

    }
     
     
    • Like Like x 1
  6. So I create a new class and replace all that with some of these methods?
     
  7. I wouldn't use that class, really outdated.
     
  8. @MaTaMoR_ Do you have new ideas how to figure it out?
     
  9. See the class that i sent, see how i add entries to it and add the extra featurings to it.
     
  10. Thanks for being considerate... and haste-binning it. Thank you!