Scoreboard is adding lines instead of replacing them

Discussion in 'Plugin Development' started by MordorKing78, Jan 14, 2017.

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

    MordorKing78

    Hello, so as the title says my scoreboard is adding lines instead of replacing them.

    Code: (JoinListener)

    PHP:
            final HashMap<StringInteger> list = new HashMap<StringInteger>();

            final 
    String spacing "         ";
           
            new 
    BukkitRunnable(){
                public 
    void run(){
                    list.
    put("§9"14);
                    list.
    put("§e§lPlayers"13);
                    list.
    put("§r" Bukkit.getOnlinePlayers().size(), 12);
                    list.
    put("§8"11);
                    list.
    put("§e§lStats"10);
                    list.
    put("§8§8>§6 Active Kit:§r todo"9);
                    list.
    put("§8>§6 Coins:§r " plugin.ecoManager.getFunds(p), 8);
                    list.
    put("§8>§6 Kills:§r " plugin.kitManager.getKills(p), 7);
                    list.
    put("§8>§6 Deaths:§r "  plugin.kitManager.getDeaths(p), 6);
                   
                    if(
    plugin.kitManager.getKills(p) != || plugin.kitManager.getDeaths(p) != 0){
                        
    double killDeathRatio =  plugin.kitManager.getKills(p)/plugin.kitManager.getDeaths(p);
                        list.
    put("§8>§6 Ratio:§r " killDeathRatio5);   
                    }else{
                        list.
    put("§8>§6 Ratio:§r 1.0"5);   
                    }
                    list.
    put("§7"4);
                    list.
    put("§e§lRank"3);
                    list.
    put("§8>§6 Elo:§r " plugin.eloManager.getElo(p), 2);
                    list.
    put("§8>§6 Rank:§r " ChatColor.stripColor(plugin.eloManager.getFormat(p)), 1);
                   
                    
    ScoreboardUtil.rankedSidebarDisplay(pspacing "§l§6Mine§eHavoc" spacing, list);
                }
            }.
    runTaskTimer(plugin051);    
    Let's say the scoreboard says:
    Coins: 2528

    When the coins change to another number let's say 2312, then this happens:
    Coins: 2528
    Coins: 2312
     
  2. Offline

    JanTuck

    Due to the mechanics of Maps it does actually what you tell it to do.

    It does not replace because
    Coins: 2528
    Coins: 2312
    is different from each other, you would have to replace the last coins amount before putting a new one.

    You could for example loop through the keyset and look for the string "Coins" and then remove if you have found it.

    Code:
       for ( String key: KEYSET) {
                if (HASCOINS) {
                    REMOVEKEY
                    break;
                }
            }
     
Thread Status:
Not open for further replies.

Share This Page