Redraw objective of scoreboard over old objective

Discussion in 'Plugin Development' started by plisov, Oct 19, 2016.

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

    plisov

    So Im trying to make a scoreboard and everything works fine. However when I kill someone it draws a new objective. How would I delete the old objective and put the new one in? Because right now when I kill someone my old kill number lets say was 89 and when I kill someone it makes a new objective over it with the number 90.
    Here is the non working code
    Code:
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
           
            Player player = event.getPlayer();
           
            String name = player.getName();
       
            Scoreboard board = player.getScoreboard();
           
            Objective objective = board.getObjective(DisplaySlot.SIDEBAR);
    
            objective.setDisplayName(objective.getDisplayName());
               
                String pName = player.getName();
               
                getConfig().get(pName + ".kills");
                getConfig().get(pName + ".deaths");
                saveConfig();
               
                int kills = getConfig().getInt(name + ".kills");           
                int deaths = getConfig().getInt(name + ".deaths");
               
                int kdr = (Math.round(kills/deaths));
               
                Score ratio = objective.getScore(ChatColor.GREEN + "K.D. Ratio: " + kdr);
                ratio.setScore(0);
               
            Score kills1 = objective.getScore(ChatColor.GREEN + "Kills: " + kills);
            kills1.setScore(1);
           
           
            Score deaths1 = objective.getScore(ChatColor.RED + "Deaths: " + deaths);
            deaths1.setScore(2);
           
        }
    Here is the code that was working before. This code didn't have to make a new objective. All it did was change the objective's score.
    Code:
        @EventHandler
        public void onMove(PlayerMoveEvent event) {
           
            Player player = event.getPlayer();
           
            String name = player.getName();
       
            Scoreboard board = player.getScoreboard();
           
            Objective objective = board.getObjective(DisplaySlot.SIDEBAR);
    
            objective.setDisplayName(objective.getDisplayName());
               
                String pName = player.getName();
               
                getConfig().get(pName + ".kills");
                getConfig().get(pName + ".deaths");
                saveConfig();
               
                int kills = getConfig().getInt(name + ".kills");           
                int deaths = getConfig().getInt(name + ".deaths");
               
                int kdr = (Math.round(kills/deaths));
               
                Score ratio = objective.getScore(ChatColor.GREEN + "K.D. Ratio: ");
                ratio.setScore(kdr);
               
            Score kills1 = objective.getScore(ChatColor.GREEN + "Kills: ");
            kills1.setScore(getConfig().getInt(name + ".kills"));
           
           
            Score deaths1 = objective.getScore(ChatColor.RED + "Deaths: ");
            deaths1.setScore(getConfig().getInt(name + ".deaths"));
           
        }
     
  2. Offline

    Zombie_Striker

    This does nothing. Either delete it or make it save the values.

    1. Loop through all the contents of the scoreboard.
    2. If the score is equal to 0 (the score you set for ratio), remove it from the scoreboard and break out of the loop.
     
  3. Offline

    plisov

    How would I remove an objective?
     
Thread Status:
Not open for further replies.

Share This Page