Solved Problem with scoreboard

Discussion in 'Plugin Development' started by MinecraftDorado, Jul 24, 2016.

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

    MinecraftDorado

    I have tried different ways to read the score that determined scoreboard is obtained, but I failed to work, any advice?
    Code:
        @SuppressWarnings("deprecation")
        @EventHandler
        public void scoreboard(PlayerJoinEvent e){
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
           
            if(board.getObjective("Score") == null){
                Objective objective = board.registerNewObjective("Score", "dummy");
                objective.setDisplayName(ChatColor.AQUA + "-------");
                objective.setDisplaySlot(DisplaySlot.SIDEBAR);
               
                e.getPlayer().setScoreboard(board);
                board.getObjective("Score").getScore(e.getPlayer()).setScore(0);
            }
            return;
        }
        // This is the method I use to read:
        @SuppressWarnings("deprecation")
        public Score getScore(Player player){       
            Objective ob = player.getScoreboard().getObjective("Score");
            Score score = ob.getScore(player);       
            return score;
        }
     
  2. Offline

    Zombie_Striker

    @MinecraftDorado
    What is your problem? How do you know it "failed"? Have you tried debugging?
     
  3. Offline

    MinecraftDorado

    @Zombie_Striker
    I want the method only the value of the scoreboard.I've been testing, and the problem is that I want to implement the method does not work, and when he does shoot me incorrect data.
     
  4. Offline

    Zombie_Striker

    @MinecraftDorado
    You are most likely getting "incorrect data" because of this line:
    Scores require Strings instead of Players. Add ".getName()" to fix this issue.

    Also, I don't think it shows the player's name if the score is zero. Try setting the score to something else (E.g. 1) and see if that fixes your problem.
     
  5. @Zombie_Striker
    Scoreboards can display a score of 0. How else would you be able to have 0 points in a minigame? :p

    @MinecraftDorado
    Your problem is, as @Zombie_Striker pointed out, that score names are Strings, not Player objects.
     
  6. Offline

    MinecraftDorado

    @Zombie_Striker
    Code:
        public Score getScore(Player player){     
            Objective ob = player.getScoreboard().getObjective("Score");
            Score score = ob.getScore(player.getName());     
            return score;
        }
    I have already changed, but still malfunctioning, when running shows:
    MinecraftDorado: org.bukkit.craftbukkit.v1_9.scoreboard.CraftScore@6e5e93b4 (The numbers after the @ change every time you run)
    What would have to get out is simply this:
    MinecraftDorado: 1
     
  7. Offline

    ArsenArsen

    It is not that function. Somewhere you forget to pull the score out, for example when you do your .println()

    println() Just runs toString on the object, what you need to do is pull the score out of the score object first
    EDIT: Orr you do sendMessage("Score: " + scoreObject), which also runs a toString
     
  8. Offline

    MinecraftDorado

    @ArsenArsen
    I have placed this in the code but still does not work, now do not even get the message
    Code:
        public void getScore(Player player){       
            Objective ob = player.getScoreboard().getObjective("Score");
            Score score = ob.getScore(player.getName());   
            player.sendMessage("Score: " + score);
            return;
        }
     
  9. Offline

    ArsenArsen

    player.sendMessage("Score: " + score);
    I never said its the thing to do, I said it runs a toString. What you need to do is player.sendMessage("Score: " + score.getScore());
     
  10. Offline

    MinecraftDorado

    @ArsenArsen
    Ready, and change it and now it works, thanks.
     
  11. Offline

    ArsenArsen

    No problem. Here to help.
     
Thread Status:
Not open for further replies.

Share This Page