Solved Scoreboards, returning any players with a specific score.

Discussion in 'Plugin Development' started by LuckehPickle, Jan 10, 2015.

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

    LuckehPickle

    Is it possible to get a player with a specific score? If you have any idea that'd be great!
     
  2. Offline

    nverdier

    @LuckehPickle What code do you have so far? Yes it's possible, but people won't spoon-feed you! Show us what you have and we will help you make it work.
     
    LuckehPickle likes this.
  3. Offline

    LuckehPickle

    @nverdier hahaha ok, I did alot of searching before hand and the closest thing I could find was getEntry(). heres my code
    Code:
    @SuppressWarnings("deprecation")
        public void setupBoard(Player player){
            Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
            Objective objective = board.registerNewObjective("Prison", "dummy");
            Config config = new Config(main, "data");
          
            objective.setDisplayName(ChatColor.GOLD + "[" + ChatColor.WHITE + config.getString("Users." + player.getUniqueId() + ".Rank") + ChatColor.GOLD + "]");  
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
          
            objective.getScore("Money" + ChatColor.GRAY + ":").setScore(8);
            objective.getScore(ChatColor.GRAY + "$" + config.getInt("Users." + player.getUniqueId() + ".Money")).setScore(7);
          
            objective.getScore("Rankup" + ChatColor.GRAY + ":").setScore(6);
            objective.getScore(ChatColor.GRAY + "$10000").setScore(5);
          
            objective.getScore("Online Players" + ChatColor.GRAY + ":").setScore(4);
            objective.getScore(ChatColor.GRAY + "" + Bukkit.getOnlinePlayers().length).setScore(3);
          
            objective.getScore("Website" + ChatColor.GRAY + ":").setScore(2);
            objective.getScore(ChatColor.GOLD + "atomichive.com").setScore(1);
          
            player.setScoreboard(board);
        }
      
        public void updatePlayerCount(Player player){
            Scoreboard board = player.getScoreboard();
            Objective objective = board.getObjective("Prison");
          
            //get the player with the score 3 and remove them
            //add a new player named Bukkit.getOnlinePlayers().length and set it with a score of 3
        }
     
  4. Offline

    1Rogue

  5. Offline

    LuckehPickle

    @1Rogue yes, but it only shows how to get a players score. or am I reading that wrong?

    @1Rogue I can't only get the players score, because the player could be named anything. I need to instead get the player with a score of 3
     
    Last edited by a moderator: Jan 10, 2015
  6. Offline

    1Rogue

  7. Offline

    LuckehPickle

  8. Offline

    1Rogue

    What purpose would passing an int do? READ what the documentation says. READ what the string you pass to it does. READ what the returned value is. You cannot learn what the method does withing READING the documentation.
     
  9. Offline

    LuckehPickle

    I have read it, several times now. getScores() returns all scores for the Entry that you pass, (a String). And in this situation that won't work. I instead need to get an Entry based on what Score it has (an int). Thats why I would pass an int (I do understand that it won't accept an int). The only thing I can think of now is Iterating through every Entry, getting its score and seeing if its equal to 3. Is that what you mean?

    @1Rogue Thanks for your help, sorry for frustrating you but I eventually found that I could achieve this by Iterating through every Entry, and resetting any entries that equal 3, with the following code
    Code:
    public void updatePlayerCount(Player player){
            Scoreboard board = player.getScoreboard();
            Objective objective = board.getObjective("Prison");
          
            for(String s : board.getEntries()){
                if(objective.getScore(s).getScore() == 3){
                    board.resetScores(s);
                }
            }
          
            objective.getScore(ChatColor.GRAY + "" + Bukkit.getOnlinePlayers().length).setScore(3);
        }
    Thanks for trying anyway, I know it can be extremely frustrating trying to help people with plugins.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  10. Offline

    1Rogue

    Yup! That's what you would do (and subsequently achieved I believe).
     
    LuckehPickle likes this.
Thread Status:
Not open for further replies.

Share This Page