[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

    stuntguy3000

    Sir, i love you :D
     
  2. Offline

    iWareWolf

    How do I remove an player off the scoreboard?
     
  3. Offline

    chasechocolate

    You can make it so it only sends the scoreboard to players in a specific world:
    Code:java
    1. for(Player inWorld : world.getPlayers()){
    2. inWorld.setScoreboard(board);
    3. }


    Thanks for the feedback <3 :p

    Code:java
    1. Scoreboard blankBoard = manager.getNewScoreboard();
    2. player.setScoreboard(blankBoard);

    I'll add it to the OP tomorrow.

    Yeah... ;(

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

    fresser123

    I have the line:
    Code:
     p.setScoreboard(plugin.board);
     
  5. Offline

    herberti1

    How I disable the Scoreboard?
     
  6. Offline

    Cryptite

    If I wanted my scoreboard only display objectives via their display name, is this this possible to do without setting a score? If not, how do you set a score such that much scoreboard could display (on the sidebar) something like:

    (with blue color) Objective 1
    (with red color) Objective 2
    (with gray color) Objective 3

    without integer involvement, etc.

    Thanks for the hard work!
     
  7. Offline

    stirante

    How can I delete scoreboard from server's data? I'm creating a lot of scoreboards in my plugin and I don't want to save them on server.
     
  8. Offline

    TheUpdater

    my dose not work why? plz tell where to put it i have tryed made on PlayerJoinEvent

    Code:
        @Override
        public void onEnable() {
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
           
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName("Display Name");
            OfflinePlayer p = Bukkit.getPlayer("EzLeR_iGODz");
            Score score = objective.getScore(p);
            score.setScore(42);
            ((Player) p).setScoreboard(board);
    }
     
  9. Offline

    stuntguy3000

    Why are you using offline players?
     
  10. Offline

    TheUpdater

    cant use anything else
     
  11. Offline

    confuserr

    Well duh, you're setting it in onEnable when no players are on the server...
     
  12. Offline

    Digi

    chasechocolate
    Actually setting that to true will allow friendly fire, which means teammates can hurt themselves.
     
  13. Offline

    njb_said

    Stupidest question ever:
    How can I store the scoreboard. Should I get the main scoreboard each time I want to edit something (make a team etc)
    Or should I make a newscoreboard in the onEnable and then do getMainScoreboard.

    I know how to work with scoreboards its just saving them thats my issue :p

    Should I save them to a hashmap? so they can be accessed?

    EDIT: I worked it out before I edited this :p
     
  14. Offline

    Digi

    If you have only one scoreboard object you can just create a field for that object and store it...

    Just add "private Scoreboard board" outside of any method (as a field...) and remove "Scoreboard" from your 'board' variable in onEnable so you'll use the field instead of making a local variable.

    Then you can use board in that class.

    Or you could make it protected/public to use it in other classes by using 'plugin.board', assuming plugin is the pointer to your main class...
     
  15. Offline

    Javaer

    Hey, Can I get an example of making the scoreboard.
    like where to put the code?
    Because when I tried it in my self I always had an error in the ScoreBoardManager...
     
  16. Offline

    Digi

    Javaer
    You expect people to give you detailed information but you don't even post the error you get.
     
  17. Offline

    Javaer

    Srry, My error is in this line:
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Always get error in the console..
     
  18. Offline

    Digi

    Javaer
    I still don't see you posting the actual error.

    But I have to assume you're not using a new enough Bukkit API build that has the scoreboard API implemented, the beta version does not have it, download the latest dev version.
     
  19. Offline

    njb_said

    getPlayerTeam doesnt seem to be working for me.
    Hmm
     
  20. Offline

    PHILLIPS_71

    chasechocolate
    I have made a scoreboard show up under a players name for their health but im getting a error for the
    ("showhealth", "health");
    setDisplaySlot
    ("/ 20");
    I'm using the new CB it lets me import it but still comes up red with Syntax error on token "setDisplaySlot" identifier expected after this token.
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    this is my code

    Code:
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
        board.registerNewObjective("showhealth", "health");
     
        Objective objective = board.getObjective("showhealth");
        objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
        objective.setDisplayName("/ 20");
     
        for(Player online : Bukkit.getOnlinePlayers()){
            online.setScoreboard(board);
        }
    }
     
  21. Offline

    chasechocolate

    Yeah, I just got what it said from the JavaDocs... I'll fix that.

    PHILLIPS_71 probably got changed with a new release. I'll update the OP when I get a chance to experiment with the new builds.

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

    unforgiven5232

    "player" gives me an error, i don't know how to solve it other than doing what eclipse thinks is good which is to add
    OfflinePlayer player; which does not help at all >.<
     
  23. Offline

    iWareWolf

    1.5.1 Beta Build broke this.
     
  24. Offline

    Tirelessly

  25. Offline

    iWareWolf

    Tirelessly
    Thats not 1.5.1 Beta Build and the methods were deleted.
     
  26. Offline

    Jigabot

    Scoreboard API wasn't added till after the current beta build so builds 2738 onward should be used with these examples.
     
  27. Offline

    iWareWolf

  28. Offline

    Terradominik

    Is there a way to display 2 Scoreboards to a player? (I want to have something in the right box and under the players name)
     
  29. Offline

    Javaer

    Hey I saw your tutrial and I am using the latest Dev build for Bukkit and I got this error:
    Code:
    2013-04-10 14:34:04 [INFO] This server is running CraftBukkit version git-Bukkit-1.5.1-R0.1-7-ge80e64d-b2744jnks (MC: 1.5.1) (Implementing API version 1.5.1-R0.2-SNAPSHOT)
    2013-04-10 14:34:04 [SEVERE] Could not load 'plugins\Ctf.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.NullPointerException
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182)
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.loadPlugins(CraftServer.java:239)
        at org.bukkit.craftbukkit.v1_5_R2.CraftServer.<init>(CraftServer.java:217)
        at net.minecraft.server.v1_5_R2.PlayerList.<init>(PlayerList.java:55)
        at net.minecraft.server.v1_5_R2.DedicatedPlayerList.<init>(SourceFile:11)
        at net.minecraft.server.v1_5_R2.DedicatedServer.init(DedicatedServer.java:105)
        at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:381)
        at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    Caused by: java.lang.NullPointerException
        at me.Kenig.Ctf.CtfMain.<init>(CtfMain.java:61)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:178)
        ... 9 more
    Line 61:
    Code:
    Scoreboard board = manager.getNewScoreboard();
     
  30. Offline

    Digi

    iWareWolf
    Beta doesn't even have the Scoreboard API, dev builds newer than beta have it.

    Javaer
    Is your "manager" variable asigned ? :)
     
Thread Status:
Not open for further replies.

Share This Page