[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

    chasechocolate

  2. Offline

    DrTURTLE2

  3. Offline

    elraro

    i have problems in the reset of a scoreboard...

    Code:java
    1. Objective inf_scoreboard = board.registerNewObjective("info", "dummy");
    2. inf_scoreboard.setDisplayName("Info");
    3. final Score jugadorescomenzar = inf_scoreboard.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Jug. empezar:")); //Get a fake offline player
    4. jugadorescomenzar.setScore(contadorjugadores);

    Now, i want to DELETE the score jugadorescomenzar, but i doesnt know how :(
     
  4. Offline

    alph0nzo

    Hi

    I'm completely new to minecraft servers and Bukkit. Me and a couple of friends have bought a server on ClanForge Multiplay and we are using a Bukkit profile.

    I've been trying to make a CTF arena but none of my scoreboards are showing up etc. So I've read through the thread and cant seem to find where I need to go to add scoreboards etc. On the ClanForge config files I only get the basic ones including server.properties. Do I need to do anything with that to show a scoreboard?

    Any help would be more than grateful.
     
  5. Offline

    TheRedHeadHD

    When I attempt to write "player.setScoreboard(hub);" into the script, I get an error with "player". Could you help me out?
     
  6. Offline

    AppleMen

    I am getting error's. This is my code. I think i forgot something really stupid….

    Code:java
    1. package me.matthijs110.FactionsExtras;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import org.bukkit.scoreboard.Objective;
    8. import org.bukkit.scoreboard.Scoreboard;
    9. import org.bukkit.scoreboard.DisplaySlot;
    10. import org.bukkit.scoreboard.ScoreboardManager;
    11.  
    12. public class Main extends JavaPlugin implements Listener {
    13.  
    14. public void OnEnable(){
    15. getServer().getPluginManager().registerEvents(this, this);
    16.  
    17. ScoreboardManager manager = Bukkit.getScoreboardManager();
    18. Scoreboard board = manager.getNewScoreboard();
    19. Objective objective = board.registerNewObjective("showhealth", "health");
    20. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    21. objective.setDisplayName("/ 20");
    22.  
    23. for(Player online : Bukkit.getOnlinePlayers()){
    24. online.setScoreboard(board);
    25. online.setHealth(online.getHealth());
    26. }
    27. }
    28. }
     
  7. Offline

    TheRedHeadHD

  8. Offline

    chasechocolate

    TheRedHeadHD are you ever calling the register(player) method?
     
  9. Offline

    AppleMen

    My scoreboard isn't working either..
    Code:java
    1. package me.matthijs110.FactionsExtras;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.Listener;
    6. import org.bukkit.plugin.java.JavaPlugin;
    7. import org.bukkit.scoreboard.Objective;
    8. import org.bukkit.scoreboard.Scoreboard;
    9. import org.bukkit.scoreboard.DisplaySlot;
    10. import org.bukkit.scoreboard.ScoreboardManager;
    11.  
    12. public class Main extends JavaPlugin implements Listener {
    13.  
    14. public void OnEnable(){
    15. getServer().getPluginManager().registerEvents(this, this);
    16.  
    17. ScoreboardManager manager = Bukkit.getScoreboardManager();
    18. Scoreboard board = manager.getNewScoreboard();
    19. Objective objective = board.registerNewObjective("showhealth", "health");
    20. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    21. objective.setDisplayName("/ 20");
    22.  
    23. for(Player online : Bukkit.getOnlinePlayers()){
    24. online.setScoreboard(board);
    25. online.setHealth(online.getHealth());
    26. }
    27. }
    28. }
     
  10. Offline

    Garris0n

    Why are you setting the player's health to the player's health? You need to update their scoreboard value, not set their health..
     
  11. Offline

    AppleMen

    How
     
  12. Offline

    Garris0n

    Well it will update whenever they take damage I'd assume. You could set the score to their health once to update it initially...but setting their health to their health isn't going to do anything...
     
  13. Offline

    Cuniculator

    I've got a question about updating the scoreboard.
    I tried updating the scoreboard every 2 ticks, due to a timer I want to use.
    The scoreboard is specific to the player and will update for EVERY player.
    It works just fine, the problem is that it keeps flickering, when I change the delay to 100 ticks it just works fine.
    My question is: Is there a minumum delay you can use to refresh a scoreboard, if so, what is this delay?

    The following is my code.. (where 'timer(player)' is the time that is passed since the start of the timer)
    I've also showed the scoreboard to the player in a onPlayerJoin event

    Code:java
    1. public void run() {
    2. for(Player player : Bukkit.getOnlinePlayers()) {
    3.  
    4. ScoreboardManager manager = Bukkit.getScoreboardManager();
    5. org.bukkit.scoreboard.Scoreboard board = manager.getMainScoreboard();
    6.  
    7. float dtime = 0;
    8.  
    9. if(timer(player.getName()) != null){
    10. dtime = (float) timer(player.getName()) / 10;
    11. }
    12.  
    13. String p = player.getName();
    14.  
    15. OfflinePlayer time = Bukkit.getOfflinePlayer("§9§lTime");
    16. OfflinePlayer timev = Bukkit.getOfflinePlayer("§b"+dtime);
    17. OfflinePlayer name = Bukkit.getOfflinePlayer("§a"+p);
    18.  
    19. Objective objective = null;
    20.  
    21. if(board.getObjective(p) == null){
    22. objective = board.registerNewObjective(p, "dummy");
    23. }else{
    24. objective = board.getObjective(p);
    25. }
    26.  
    27. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    28.  
    29. for(OfflinePlayer ofpl : board.getPlayers()){
    30. board.resetScores(ofpl);
    31. }
    32.  
    33. objective.setDisplayName("§6Stats");
    34.  
    35. if(plugin.speedRunTime.get(player.getName()) != null){
    36. objective.getScore(time).setScore(2);
    37. objective.getScore(timev).setScore(1);
    38. }else{
    39. board.resetScores(time);
    40. board.resetScores(timev);
    41. }
    42.  
    43. objective.getScore(name).setScore(3);
     
  14. Offline

    TheRedHeadHD

  15. Offline

    chasechocolate

  16. Offline

    TheRedHeadHD

  17. Offline

    Ultimate_n00b

    One issue here, is that I have never heard of a program called "Miencraft".
     
    calebbfmv likes this.
  18. Offline

    TheRedHeadHD

    Ultimate_n00b I fixed that issue, but yet again, the scoreboard doesn't show up. Does it have to do with Optifine?[​IMG]
     
  19. Offline

    chasechocolate

    TheRedHeadHD I think the score won't show up if it is 0. Try changing it to 1
     
  20. Offline

    viper_monster

    TheRedHeadHD, I think you will have to make a scheduled repeating that runs every sec or two, because when you run the server there are no players online and scoreboard will get assigned to noone; Or you could do this code in player join event
     
    calebbfmv and Ultimate_n00b like this.
  21. Offline

    TrollTaylor

    chasechocolate Where am i supposed to put these lines cause when i put them were i think i do it gives me a null pointer exception
    Code:java
    1. ScoreboardManager manager = Bukkit.getScoreboardManager();
    2. Scoreboard board = manager.getNewScoreboard();
    3.  
    4. Objective objective = board.registerNewObjective("coins", "dummy");
    5. Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Coins:"));
     
  22. Offline

    FlawlezZ

    chasechocolate

    How can I separate? Every player should have his own rank. Currently there's always displayed the rank of one player :/.

    And also how do I get rid of the 0 before [Rank] ? There's always one in front of the []..


    Code:java
    1. public void onEnable() {
    2. ScoreboardManager manager = Bukkit.getScoreboardManager();
    3. Scoreboard board = manager.getMainScoreboard();
    4.  
    5. Objective objective = board.registerNewObjective("Flawssentials", "Achievement.THE_END");
    6. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    7.  
    8. final Scoreboard finalBoard = board;
    9. final Objective finalObjective = objective;
    10.  
    11.  
    12. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    13. @Override
    14. public void run() {
    15. for (Player online : Bukkit.getOnlinePlayers()) {
    16.  
    17. String color = "GRAY";
    18. String rank = getRank(online.getName());
    19.  
    20. if (getMorale(online.getName()) >= 1000) {
    21. color = "AQUA";
    22. } else if (getMorale(online.getName()) <= -1000) {
    23. color = "DARK_RED";
    24. }
    25. finalObjective.setDisplayName("[" + ChatColor.valueOf(color) + rank + ChatColor.WHITE + "]");
    26. online.setScoreboard(finalBoard);
    27. getLogger().info("Scoreboards gesetzt");
    28. }
    29. }
    30.  
    31.  
    32. }, 0L, 60*20L);
    33. }
     
  23. Offline

    chasechocolate

    FlawlezZ the 0 is always there, it represents an unset score.
     
  24. Offline

    FlawlezZ

    Ok, What is The Solution for Q1?can you answer please
     
  25. Offline

    TheRedHeadHD

    Codisimus I set it to 1. It still doesn't work.
     
  26. Offline

    viper_monster

    TheRedHeadHD
     
  27. Offline

    Codisimus

    Sorry but I have no idea wut you're talking about and I couldn't find my previous post lol.
     
  28. Offline

    PieMan456

    chasechocolate
    Hello Chase,
    I have used your tutorial on how to make a scoreboard plugin and most of it was helpful. Except, When I register a new objective and i try to set the display slot and name there are errors and it will not work. If you know what is wrong please tell me. Thanks!
    Here is my main class so far:
    Code:
    package me.pieman.board;
     
    import org.bukkit.Bukkit;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
     
     
    public class Board extends JavaPlugin{
       
        ScoreboardManager sbManager = Bukkit.getScoreboardManager();
        Scoreboard Kills = sbManager.getNewScoreboard();
       
        Objective obj = Kills.registerNewObjective("Kills", "playerKillCount");
        obj.getDisplaySlot(DisplaySlot.SIDEBAR);
        obj.getDisplayName(ChatColor.GREEN + "Kills");
    The obj.getDisplayName/getDisplaySlot will not work they show errors.
     
  29. Offline

    Ultimate_n00b

    You can't run code outside of a method..
     
    JPG2000 and spoljo666 like this.
  30. Offline

    Ad237

    Is it possible to display a mob's health under their name or is it only for players?
     
Thread Status:
Not open for further replies.

Share This Page