[Tutorial] Scoreboards/Teams with the Bukkit API

Discussion in 'Resources' started by chasechocolate, Apr 5, 2013.

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

    TheAJ471

    chasechocolate If I have this in a lsitener for my plugin (finally got it to work) how would i make it so it removes them when you type a command. But thats in a different command listener. So I guess how would I transfer over the same team to remove the scoreboard.

    chasechocolate Also when I join my game th scoreboard shows up and when you die it goes away, but when you join again it doesnt show up.

    EDIT: IGNORE THIS! I GOT IT FIXED WITH
    Code:java
    1. Scoreboard blankBoard = manager.getNewScoreboard();
    2. player.setScoreboard(blankBoard);
     
  2. @ chasechocolate For the health example, it appears for a split second whenever I get damaged.
     
  3. Offline

    Reany3D

    I wonder how to do this on sidebar;

    Player 1 see;
    DisplayName
    ScoreName1 100
    ScoreName2 90

    Player2 see;
    DisplayName
    ScoreName1 60
    ScoreName2 80
     
  4. Offline

    HeavyMine13

    Ambigous Health Problem!

    Code:
    Code:java
    1. package me.HeavyMine13.hj;
    2.  
    3.  
    4. import java.util.ArrayList;
    5. import java.util.List;
    6.  
    7. import me.HeavyMine13.hj.ParticleEffect;
    8.  
    9.  
    10.  
    11.  
    12.  
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19.  
    20. import org.bukkit.Bukkit;
    21. import org.bukkit.entity.Player;
    22. import org.bukkit.event.EventHandler;
    23. import org.bukkit.event.EventPriority;
    24. import org.bukkit.event.Listener;
    25. import org.bukkit.event.player.PlayerLoginEvent;
    26. import org.bukkit.scheduler.BukkitScheduler;
    27. import org.bukkit.scoreboard.DisplaySlot;
    28. import org.bukkit.scoreboard.Objective;
    29. import org.bukkit.scoreboard.Scoreboard;
    30. import org.bukkit.scoreboard.ScoreboardManager;
    31.  
    32. public class listeners implements Listener {
    33. Hj plugin;
    34.  
    35. public listeners(Hj instance){
    36. plugin = instance;
    37. }
    38.  
    39.  
    40.  
    41. @EventHandler (priority = EventPriority.HIGH)
    42. public void onPlayerLogin(final PlayerLoginEvent event) {
    43. ScoreboardManager manager = Bukkit.getScoreboardManager();
    44. Scoreboard board = manager.getNewScoreboard();
    45.  
    46. Objective objective = board.registerNewObjective("showhealth", "health");
    47. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    48. objective.setDisplayName("/ 20");
    49.  
    50. for(Player online : Bukkit.getOnlinePlayers()){
    51. online.setScoreboard(board);
    52. Player p = event.getPlayer();
    53. online.setHealth(online.getHealth()); //Update their health
    54.  
    55. if (event.getPlayer().hasPermission("particles.use")){
    56. BukkitScheduler scheduler = Bukkit.getServer().getScheduler();
    57. scheduler.scheduleSyncRepeatingTask (plugin, new Runnable() {
    58. public void run() {
    59. ParticleEffect.NOTE.display(event.getPlayer().getLocation(), 0.5F, 1.0F, 0.5F, 1F, 1);
    60. }
    61. }, 80L, 0);
    62.  
    63. }
    64. }
    65. }
    66. }
    67.  


    Main Class:
    Code:java
    1. package me.HeavyMine13.hj;
    2.  
    3. import org.bukkit.plugin.java.JavaPlugin;
    4.  
    5. public final class Hj extends JavaPlugin {
    6.  
    7.  
    8. @Override
    9. public void onEnable(){
    10. getLogger().info("RUN has been enabled,what a noob!");
    11. getServer().getPluginManager().registerEvents(new listeners(this), this);
    12. }
    13.  
    14. @Override
    15. public void onDisable() {
    16. getLogger().info("RUN has been disabled,u noob!");
    17. }
    18. }
    19.  
    20.  
     
  5. Offline

    Bart

  6. Offline

    Scullyking

    I know I'm late on this, but thank-you for creating such a simple and clean tutorial! :)
     
  7. Offline

    Swing_dude

    I know that I'm a noob for asking this, but if I have the "dummy" objective on a scoreboard called board and I change the value on my account. will the new value show up on all other accounts using that scoreboard? In other words, if there is a shared scoreboard, are the scores player-specific?
     
  8. Offline

    LCastr0

    How can I set a scoreboard per player?
     
  9. Offline

    TryB4

    LCastr0
    make a new scoreboard for each player
     
  10. Offline

    LCastr0

    Duuhh, Ik, but then It'd show all the players in the same scoreboard
    I want one like:
    Player1 can see this scoreboard:
    <ScoreBoard Name>
    Points: 10

    Player 2 can see this scoreboard:
    <ScoreBoard Name>
    Points: 15

    What I have now, is this:
    Player1 AND Player2 can see this scoreboard:
    <Scoreboard Name:
    Points: 15
    Points: 10

    TryB4 any idea?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 30, 2015
  11. Offline

    TryB4

    LCastr0
    Make a new scoreboard for each player.
    Code:java
    1. public void updateBoard(Player p) {
    2.  
    3. Scoreboard b = Bukkit.getScoreboardManager().getNewScoreboard();
    4.  
    5. //objective stuff
    6.  
    7. p.setScoreboard(b)
    8.  
    9. }
     
  12. Offline

    LCastr0

    ok, nevermind, fixed :)
     
  13. Offline

    Swing_dude

    chasechocolate Can I have a player on a team if they aren't on the board that the team is registered to? For example, team is registered on board1. could a player on board2 join the team "team"?
     
  14. Offline

    ryr11

    at objective.setDisplaySlot(DisplaySlot.SIDEBAR);

    I get Syntax error on token "setDisplaySlot", Identifier expected after this token.
    and
    Syntax error at ".", ... expected
    Any ideas please?
     
  15. Offline

    Acer_Mortem

    chasechocolate
    For some reason, whenever I update a players scoreboard (as shown below), the updated score never shows, and only shows the new one. Any ideas?

    Updating the Bosrd:
    Code:
            int maxHealth = dfs.getCustomConfig().getInt(name + ".MaxHealth");
            plugin.getLogger().info(maxHealth + "~");
            Score HealthScore = obj.getScore(Bukkit.getOfflinePlayer(ChatColor.WHITE + "~" + ChatColor.RED + "Health"));
            HealthScore.setScore(maxHealth);
    Just so you know, maxHealth is not null. It does infact equal 100, as shown by the logger.
     
  16. Offline

    HeavyMine13

    When a player logs on, his health appears as 0
     
  17. Offline

    Blingdaddy1

    How am i supposed to make player a variable?
    Like
    There is NO WHERE and NO WAY I can make player a variable
    And you don't explain it in the tutorial
    so im sitting here like
    how do i make player a variable?
    I try bukkit.getPlayer(args[0]);
    Nope, eclipse doesnt know what args is
    and I try like 10 other things
    NOTHING
    WORKS
     
  18. Offline

    viper_monster

    Blingdaddy1 Learn Java first and then dive into Bukkit. :)
     
    Paxination and HeavyMine13 like this.
  19. Offline

    WillTheBastard

    How about you try learning Java first.... Good lord.
     
    Paxination likes this.
  20. Offline

    Paxination

    So if I made my own Scoreboard, would it conflict with any plugins that use this system as well? Would we be fighting over it?
     
  21. Offline

    viper_monster

  22. Offline

    Paxination

    Well damn, thats limited! So if I have a plugin already that uses it, im screwed. Mojang should make it display on a per world basis, or a collection of worlds.
    How feasible would it be to do that my self?
     
  23. Offline

    Captain Dory

    You could get the other plugins code and change that for a different world, and display that scoreboard if the world the player in is equal to the other plugin's code.
     
  24. Offline

    Superckl1

    Hey guys, I'm having a bit of a problem with Scoreboards. I know how to use them and everything, there is just always this mysterious space at the end of a player's nameplate:
    [​IMG]
    The problem is outlined in more detail here. Any ideas?
     
  25. Offline

    guitargun

    does someone know how you save a hasmap<String, ScoreBoard> or hashmap<String, Score> to a file? I need this for the server because when I reload the hashmap is set to null
     
  26. Offline

    Log-out

    @HeavyMine13 You have to update health for each online player
    Code:JAVA
    1.  
    2. for (Player online : Bukkit.getOnlinePlayers()) {
    3. if (online.getHealth() > 0) {
    4. online.setHealth(online.getHealth() - 0.0001);
    5. }
    6. }
    7.  
     
  27. Offline

    ratedam

    So if i only want to show a scoreboard with "Hello player"
    I only do this?

    Code:
    ScoreboardManager manager = Bukkit.getScoreboardManager();
     
    Scoreboard board = manager.getNewScoreboard()
     
    //Setting where to display the scoreboard/objective (either SIDEBAR, PLAYER_LIST or BELOW_NAME)
     
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
     
     
     
    //Setting the display name of the scoreboard/objective
     
    objective.setDisplayName("Welcome player");
     
  28. Offline

    DevRosemberg

    How can i fix a Team already excists Bug?
     
  29. Offline

    Captain Dory

    First time trying out scoreboards, not showing up :c
    This is my code:
    Code:
    public class Main extends JavaPlugin {
       
        public void onEnable() {
           
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Team team = board.registerNewTeam("Blacks");
            team.addPlayer(Bukkit.getOfflinePlayer("Captain_Dory"));
            team.setPrefix("Black:");
            team.setDisplayName("Blacks");
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("Killz");
            Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
            score.setScore(1);
            board.resetScores(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Kills:"));
           
            for(Player online : Bukkit.getOnlinePlayers()){
                online.setScoreboard(board);
            }
           
        }
       
    }
    Probably forgetting something stupid, please reply if you know how to fix this, thanks :)
     
  30. Offline

    Dubehh

    Is there a way yo add a player to a team on command?
    Like 'team'.addPlayer();
    Please help ;P
     
Thread Status:
Not open for further replies.

Share This Page