Update scoreboard player [ScoreHelper] HELP

Discussion in 'Spigot Plugin Development' started by ElbestHD, Jan 29, 2019.

  1. Hi people of spigot, it will be that you can help me to scoreboard update to the players since I made a code and I get an error and I come to see if you can help me, SORRY MY ENGLISH
    API SCOREHELPER
    Code (Text):
    public class ScoreHelper {
     
        private static HashMap<UUID, ScoreHelper> players = new HashMap<>();
     
        public static boolean hasScore(Player player) {
            return players.containsKey(player.getUniqueId());
        }
     
        public static ScoreHelper createScore(Player player) {
            return new ScoreHelper(player);
        }
     
        public static ScoreHelper getByPlayer(Player player) {
            return players.get(player.getUniqueId());
        }

        public static ScoreHelper removeScore(Player player) {
            return players.remove(player.getUniqueId());
        }
     
        private Scoreboard scoreboard;
        private Objective sidebar;

        private ScoreHelper(Player player) {
            scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
            sidebar = scoreboard.registerNewObjective("sidebar", "dummy");
            sidebar.setDisplaySlot(DisplaySlot.SIDEBAR);
            // Create Teams
            for(int i=1; i<=15; i++) {
                Team team = scoreboard.registerNewTeam("SLOT_" + i);
                team.addEntry(genEntry(i));
            }
            player.setScoreboard(scoreboard);
            players.put(player.getUniqueId(), this);
        }

        public void setTitle(String title) {
            title = ChatColor.translateAlternateColorCodes('&', title);
            sidebar.setDisplayName(title.length()>32 ? title.substring(0, 32) : title);
        }

        public void setSlot(int slot, String text) {
            Team team = scoreboard.getTeam("SLOT_" + slot);
            String entry = genEntry(slot);
            if(!scoreboard.getEntries().contains(entry)) {
                sidebar.getScore(entry).setScore(slot);
            }

            text  = ChatColor.translateAlternateColorCodes('&', text);
            String pre = getFirstSplit(text);
            String suf = getFirstSplit(ChatColor.getLastColors(pre) + getSecondSplit(text));
            team.setPrefix(pre);
            team.setSuffix(suf);
        }

        public void removeSlot(int slot) {
            String entry = genEntry(slot);
            if(scoreboard.getEntries().contains(entry)) {
                scoreboard.resetScores(entry);
            }
        }

        public void setSlotsFromList(List<String> list) {
            while(list.size()>15) {
                list.remove(list.size()-1);
            }
         
            int slot = list.size();

            if(slot<15) {
                for(int i=(slot +1); i<=15; i++) {
                    removeSlot(i);
                }
            }

            for(String line : list) {
                setSlot(slot, line);
                slot--;
            }
        }

        private String genEntry(int slot) {
            return ChatColor.values()[slot].toString();
        }

        private String getFirstSplit(String s) {
            return s.length()>16 ? s.substring(0, 16) : s;
        }

        private String getSecondSplit(String s) {
            if(s.length()>32) {
                s = s.substring(0, 32);
            }
            return s.length()>16 ? s.substring(16) : "";
        }

    }
    CODE SCOREBOARD
    Code (Text):
    public class ScoreboardManager extends BukkitRunnable implements Listener {
     
        public static List<String> config = Main.getPlugin().getConfig().getStringList("scoreboard.lines");
        public static List<String> lines = new ArrayList<String>();
        private Main main;
        public ScoreboardManager() {
            this.main = main;
        }
     
        public void createscoreboard(Player p) {
            ScoreHelper helper = ScoreHelper.createScore(p);
             helper.setTitle(Main.getPlugin().getConfig().getString("scoreboard.title"));
               for(String l : config) {
                lines.add(l.replace("<name>", String.valueOf(p.getName()))
                        .replace("<kills>", String.valueOf(SQL.getKills(p.getUniqueId().toString())))
                        .replace("<deaths>", String.valueOf(SQL.getDeaths(p.getUniqueId().toString())))
                        .replace("<rank>", String.valueOf(SQL.getRank(p.getUniqueId().toString())))
                        .replace("<online>", String.valueOf(Bukkit.getOnlinePlayers().size()))
                        .replace("<elo>", String.valueOf(SQL.getELO(p.getUniqueId().toString()))));
            }
         helper.setSlotsFromList(lines);
       }
     
        @EventHandler
        public void onPlayerJoinEvent(final PlayerJoinEvent e) {
            Player p = e.getPlayer();
                createscoreboard(p);

        }
     
        @EventHandler
        public void onPlayerQuit(PlayerQuitEvent e) {
            Player p = e.getPlayer();
            if (ScoreHelper.hasScore(p)) {
              ScoreHelper.removeScore(p);        
                }
         }

        @Override
        public void run() {    
        }  
    }
     
    CLASS MAIN
    Code (Text):
    @Override
        public void onEnable() {
           ScoreboardManager scoreboardmanager = new ScoreboardManager();
            scoreboardmanager.runTaskTimerAsynchronously(this, 20, 20);
    ERROR
    upload_2019-1-28_22-57-12.png
     
    #1 ElbestHD, Jan 29, 2019
    Last edited: Jan 29, 2019
  2. What is the error?
     
  3. There is the error :(
    upload_2019-1-28_22-57-48.png
     
  4. People help please :D
     
  5. Show your config file please