Solved Help with Scoreboards

Discussion in 'Plugin Development' started by UNC00KED, Nov 29, 2015.

Thread Status:
Not open for further replies.
  1. Having this problem with scoreboards in my plugin. I am making sort of a TNT Runner plugin except you also get points for ores you step on. My repeating task function is named blockRemover and repeats itself every 4 ticks. The problem is getting the score to update properly on the scoreboard. I thought I knew how to do it, but apparently I don't. The scoreboard adds a line every time the repeating task iterates, instead of simply updating.

    Here is my blockRemover function:
    Code:
    void blockRemover() {
           
            taskid = Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
               
                public void run() {
                   
                    for (Player player : Bukkit.getOnlinePlayers()) {
                       
                        if (playerToggle.get(player.getName()) != null) {
                           
                            if (playerToggle.get(player.getName()).equals(true)) {
                               
                                if (blocksToRemove.get(player.getName()) != null) {
                                   
                                    List<Integer> blockList = blocksToRemove.get(player.getName());
                                   
                                    int size = blockList.size();
                                   
                                    if (size != 0) {
                                       
                                        int x = blockList.get(0);
                                        int y = blockList.get(1);
                                        int z = blockList.get(2);
                                       
                                        int score = playerScore.get(player.getName());
                                       
                                        Block block = player.getWorld().getBlockAt(x, y, z);
                                       
                                        scoreDecider(block.getType().toString(), player);
                                       
                                        final Score objScore = objectives.get(player.getName()).getScore(ChatColor.GREEN + "Score: " + ChatColor.AQUA + score);
                                        objScore.setScore(0);
                                       
                                        block.setType(Material.AIR);
                                       
                                        blockList.remove(0);
                                        blockList.remove(0);
                                        blockList.remove(0);
                                       
                                    }
                                   
                                }
                               
                            }
                           
                        }
                       
                    }
                   
                }
               
            }, 20, 4);
           
        }
    This is what's happening:
    [​IMG]

    Would appreciate any help, thanks!
     
  2. Offline

    teej107

    @UNC00KED You need to remove the previous scoreboard entry. "Score: 0" and "Score: 1" are entirely different Strings.
     
  3. Thanks for the quick reply. How would you recommend I do that? Sorry, I'm not that well versed in the Scoreboard API.
     
  4. Offline

    teej107

  5. How can I use resetScores if the player's score is different every time they hit a block that gives them points? Here's what I have:
    Code:
    scoreboards.get(player.getName()).resetScores(ChatColor.GREEN + "Score: " + ChatColor.AQUA + score);
    final Score objScore = objectives.get(player.getName()).getScore(ChatColor.GREEN + "Score: " + ChatColor.AQUA + score);
    objScore.setScore(0);
    By the way, to do individual player scoreboards/objectives, I use hashmaps. So:
    Code:
    scoreboards.get(player.getName()) 
    returns a scoreboard, and likewise:
    Code:
    objectives.get(player.getName()) 
    returns an objective.

    Code:
    Map<String, Scoreboard> scoreboards = new HashMap<String, Scoreboard>();
    Map<String, Objective> objectives = new HashMap<String, Objective>();
     
  6. Offline

    teej107

    Store the value that you set when you change the scoreboard entry. Then you can fetch the old value to clear it and then update it.
     
  7. Got it. Had to create another hashmap named playerOldScore but it's working perfectly now. Thanks for the help!
     
Thread Status:
Not open for further replies.

Share This Page