Solved Scoreboard not displaying kill/death until you kill someone or die

Discussion in 'Plugin Development' started by glasseater, Jan 26, 2016.

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

    glasseater

    Hey guys,

    I have another scoreboard question. Basically I made a scoreboard and it works fine and updates fine. However when you first join and your stats aren't in the config yet, the scoreboard shows up like this
    http://prntscr.com/9v866r

    See how it doesn't have anything under kills/deaths?
    I want it to display a 0 until they get a kill or death. I am not sure why this is only happening with kills and deaths but not money.
    If anyone knows how to solve this their help would be greatly appreciated!

    Here is the code for the scoreboard:

    Code:
    final ScoreboardManager sm = Bukkit.getScoreboardManager();
                final Scoreboard sb = sm.getNewScoreboard();
                final Objective o = sb.registerNewObjective("stats", "dummy");
                o.setDisplaySlot(DisplaySlot.SIDEBAR);
                o.setDisplayName("§6§lStats");
               
                final Score name = o.getScore("§c§lPlayer");
                final Score name2 = o.getScore("§7" + p.getName());
                final Score blank1 = o.getScore("§1");
                final Score kills = o.getScore("§c§lKills");
                final Score kills2 = o.getScore("§7" + Data.getValue(p.getName(), "kills"));
                final Score blank2 = o.getScore("§2");
                final Score deaths = o.getScore("§c§lDeaths");
                final Score deaths2 = o.getScore("§7" + Data.getValue(p.getName(), "deaths"));
                final Score blank3 = o.getScore("§3");
                final Score money = o.getScore("§c§lMoney");
                final Score money2 = o.getScore("§7" + Data.getValue(p.getName(), "money"));
                name.setScore(18);
                name2.setScore(17);
                blank1.setScore(15);
                kills.setScore(14);
                kills2.setScore(13);
                blank2.setScore(12);
                deaths.setScore(11);
                deaths2.setScore(10);
                blank3.setScore(9);
                money.setScore(8);
                money2.setScore(7);
                p.setScoreboard(sb);
     
  2. Offline

    Zombie_Striker

    @glasseater
    It would be nice to see your code, but I can already tell it is because you are only getting the object from the config. First try checking if the player's scores are in the config, and if they are not in the config, add the default scores.
     
  3. Offline

    glasseater

    @Zombie_Striker
    Is there a better way to do it? Because like I said it doesn't do that with the balance though, and I do that the same ay
     
  4. Offline

    Zombie_Striker

    @glasseater
    I do not know why it would affect the kills and deaths and not the balance, but I have noticed the following:
    This sets the score for "deaths2" to have the score "10", but if you look at the image, there is nothing with the score of 10. This means that the score is not properly set. Try printing out what Data,getValue returns, and try null checking to make sure deaths2 is not null.
     
  5. Offline

    glasseater

    @Zombie_Striker

    Code:
      public static int getValue(String name, String value) {
        int amount = 0;
        if (con.isSet(name + "." + value)) {
          amount = con.getInt(name + "." + value);
        }
        return amount;
    Code:
      public static void death(String name) {
        int deaths = 0;
        if (con.isSet(name + ".deaths")) {
          deaths = con.getInt(name + ".deaths");
        }
        con.set(name + ".deaths", Integer.valueOf(deaths + 1));
        save();
    Nope doesn't look like its null. getVaule returns the amount of deaths, and kills.
     
  6. Offline

    Zombie_Striker

    @glasseater
    Does it actually print out a value? Are you sure death1 is not null? It seems like those scores are not getting registered, so you will need to follow those scoreboard values by debugging to see what is causing your problem.
     
  7. Offline

    glasseater

    @Zombie_Striker Yes it prints a value, once the reach one kill or one death. Also it changes like one second it will show as 0 kills and "no" deaths or vice versa, then the next time i log in its gone.
     
  8. Offline

    nlthijs48

    The problem is that you are setting the score for the player "§70" 3 times, so the last one stays because it overrides the others, which happens to be the amount of money. Remember that the texts on the scoreboard are normally players, so with player I'm not referring to an actual player, but just a line on your scoreboard. What you can do to fix this is making the 'player names' of your scores unique. You can do this by adding a ChatColor.RESET in front or after the kills value, and a ChatColor.WHITE before or after your deaths value. This would mean that zero kills will be "§r§70", zero deaths will be "§f§70" and zero money will stay "§70".
     
    Zombie_Striker likes this.
  9. Offline

    glasseater

    nlthijs48 likes this.
Thread Status:
Not open for further replies.

Share This Page