Solved Scoreboard Issue

Discussion in 'Plugin Development' started by PixelBeaver, Oct 12, 2015.

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

    PixelBeaver

    Hello, I am developing a plugin where, on command, a scoreboard is displayed below select players usernames which says titles such as "[FARMER]" or "[MINER]." The plugin works just fine, but it displays a 0 before each scoreboard title (ex. "0 [FARMER]"). I am new to using scoreboards, so I am guessing the answer is very simple, but does anyone know how to get rid of this 0 before the text?
     
  2. Offline

    Zombie_Striker

    @PixelBeaver
    It would be nice to actually see your code.
     
  3. Offline

    PixelBeaver

    @Zombie_Striker
    Here it is:
    Code:
    if (label.equalsIgnoreCase("farmer")) {
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard board = manager.getNewScoreboard();
                Objective objective = board.registerNewObjective("showfarmers", "farmer");
                objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
                objective.setDisplayName(ChatColor.RED + "[FARMER]");
                for (Player p : Bukkit.getOnlinePlayers()) {
                    if (p.getName().equalsIgnoreCase(username)) {
                        p.setScoreboard(board);
                    }
                }
            }
     
  4. Offline

    Zombie_Striker

    @PixelBeaver
    I don't think your scoreboard is handling the chatcolor correctly.

    Remove the chat color and see if that makes a difference.
    Also this is a bad way to get ONE player. Image if there were 100 players on the server. It would have too loop through EVERY SINGLE PLAYER ONLINE in order to JUST GET ONE PLAYER.

    Try getServer().getPlayer(Playername) to get the player.
     
  5. Offline

    OhhPickles

    That may / could return null if player is not online so its best to also check if Playername != null
     
  6. Offline

    PixelBeaver

    @Zombie_Striker @OhhPickles
    Thank you both for the help, although the
    0 did not go away :/ However, I tested it with someone else on the server, and apparently when I set my scoreboard as the farmer text, it shows up on the other person's name. When they set their scoreboard as the text, it shows up under my name. So, I'm guessing that it shows the scoreboard not on the sender's username, only on the other people's usernames...
     
  7. Offline

    ShadowRanger

    Try changing:
    Code:
    Objective objective = board.registerNewObjective("showfarmers", "farmer");
    
    to
    Code:
    Objective objective = board.registerNewObjective("showfarmers", "dummy");
    
     
    Zombie_Striker likes this.
  8. Offline

    PixelBeaver

    @ShadowRanger
    Just tested that out, sadly it doesn't work.

    I have updated my code, here is the new copy:
    Code:
        if (label.equalsIgnoreCase("farmer")) {
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard board = manager.getNewScoreboard();
                Objective objective = board.registerNewObjective("showfarmers", "dummy");
                objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
                objective.setDisplayName("[FARMER]");
                player.setScoreboard(board);
            }
    I also have a side question: is there a way to set everyone's scoreboard to display "[FARMER]" only under the player who sent the command's name? If I set the scoreboard as the sender's scoreboard, it displays it for everyone else but themselves, so is there a way to reverse that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 11, 2016
  9. Use the same scoreboard, don't create a new one every time.
     
  10. Offline

    PixelBeaver

    @MaTaMoR_ How would you suggest doing that?
     
  11. Offline

    ShadowRanger

    Declare a variable for the Scoreboard outside of the onCommand somewhere so you can access just the 1 without creating a new one each time the command is run.
     
  12. Offline

    PixelBeaver

    @ShadowRanger
    Oh okay that makes sense, I'll try that now.

    EDIT: Thank you everyone for the help, but the scoreboard is still displaying: [0 text].
     
    Last edited: Oct 15, 2015
  13. Offline

    Reynergodoy

    That's simple: "you can't get rid of this 0 ( if you can please post it here please, I'm searching this too )"
    Why?
    Minecraft scoreboards were coded that way :)
    This objective is "dummy", it won't update by any stats modification
    I recommend you use "health", that updates when you lose or heal a life point :)
    and after that you could use " / 20 - [FARMER]"
    That would display these in the conditions:
    * player has 20 health points
    * player max health is 20 health points


    The following scoreboard:
    20 / 20 - [FARMER]

    Please use formatting color codes
     
  14. Offline

    PixelBeaver

    @Reynergodoy
    Thank you so much, can't believe I didn't think about that! I'll be sure to mark this thread as [SOLVED], and once again thank you everybody for your help. :)
     
Thread Status:
Not open for further replies.

Share This Page