Solved Scoreboard can't show the number 1 apparently

Discussion in 'Plugin Development' started by Condolent, Jan 1, 2016.

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

    Condolent

    I have a scoreboard that shows the player's credits.
    Each time I kill a zombie, I gain 1 credit.
    The scoreboard gets updated each 2 seconds.

    Code for killing zombie:
    Code:
        @EventHandler
    public void onZombieKill(EntityDeathEvent e) {
            LivingEntity entity = e.getEntity();
            if(e.getEntity() instanceof Zombie) {
                if(entity.getKiller() instanceof Player) {
                    Bukkit.broadcastMessage(entity.getKiller().getName() + " killed a Zombie");
                    getPlayerCurrency().set(entity.getKiller().getUniqueId().toString(), getPlayerCurrency().getInt(entity.getKiller().getUniqueId().toString()) + 1);
                    plugin.savePlayerCurrency();
                }
            }
    }
    Code for showing scoreboard:
    Code:
    private void setupScoreboard(Player p) {
            ScoreboardManager sm = Bukkit.getScoreboardManager();
            Scoreboard onJoin = sm.getNewScoreboard();
            Objective o = onJoin.registerNewObjective("test", "dummy");
       
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
            o.setDisplayName("" + ChatColor.GREEN + ChatColor.BOLD + "ServerName");
       
            Score spacer = null;
            Score spacer2 = null;
            Score spacer3 = null;
       
            Score nameTitle = null;
            Score name = null;
            Score currencyTitle = null;
            Score currencyBalance = null;
            Score playersTitle = null;
            Score players = null;
       
            try {
           
           
                spacer = o.getScore(ChatColor.AQUA + "----------------");
                spacer.setScore(9);
           
                nameTitle = o.getScore("" + ChatColor.YELLOW + ChatColor.BOLD + "Name:");
                nameTitle.setScore(8);
           
                name = o.getScore(p.getName());
                name.setScore(7);
           
                spacer2 = o.getScore(ChatColor.BLACK + "");
                spacer2.setScore(6);
           
                currencyTitle = o.getScore("" + ChatColor.GOLD + ChatColor.BOLD + "Balance:");
                currencyTitle.setScore(5);
           
                currencyBalance = o.getScore(getPlayerCurrency().getInt(p.getUniqueId().toString()) + "");
                currencyBalance.setScore(4);
           
                spacer3 = o.getScore("");
                spacer3.setScore(3);
           
           
                playersTitle = o.getScore("" + ChatColor.DARK_GREEN + ChatColor.BOLD + "Players online:");
                playersTitle.setScore(2);
           
                players = o.getScore(Bukkit.getOnlinePlayers().size() + "");
                players.setScore(1);
           
           
                p.setScoreboard(onJoin);
           
            } catch(Exception ex) {
                System.out.println(ex);
            }
       
    }
    Code actually starting the scoreboard:
    Code:
    Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
        public void run(){
            for(Player p : Bukkit.getOnlinePlayers()){
                setupScoreboard(p);
             }
        }
    }, 40, 40);
    But the actual balance just disappears when the credit-integer is at 1. It shows up again when it's at 2 and shows every other number.

    What is wrong? Why can't it show the number 1? :confused:
     
    Last edited: Jan 1, 2016
  2. @Condolent
    You need to make sure that there aren't any scores with the same name (e.g. when the online player size is 1 and the balance is 1 they have the same name). You can do this, for example, by putting colors before/after it.
     
  3. Offline

    Condolent

    @megamichiel ahhh sh!t, totally forgot about that. God damnet..
    Thank you! xd
     
Thread Status:
Not open for further replies.

Share This Page