[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

    RyuGamer97

    hi am new to this I just try to learn all this the only thing I understand is the average mchelloplugin xD and I want to do this but nose begins as one could help me?
     
  2. Offline

    AdmetusTheGreat

    Hey RyuGamer97
    I suggest you watch some YouTube tutorials about basic commands, etc before jumping into Teams/Scoreboards.
     
  3. Offline

    the_super_koala

    I need help making a scoreboard plugin that displays steps mob kills deaths and blocks mined, any help?
     
  4. Offline

    Beekie

    chasechocolate Is there a way to check if a player has a scoreboard or not?
     
  5. Offline

    chasechocolate

    Beekie I guess you could compare objective display names: player.getScoreboard().getObjective(DisplaySlot.SIDEBAR).getDisplayName().equals(...)
     
    Beekie likes this.
  6. Offline

    newtj599zzzbro

    how do you add a player on a team if they have a permission?
     
  7. Offline

    Gawdzahh

    Since getOfflinePlayer has been deprecated what do you use for changeSingle() ?
     
  8. Offline

    RainoBoy97

  9. Offline

    whitebradcam

    How can I get multiple offline players to be in my scoreboard? Like the ones on the big servers.
     
  10. chasechocolate Quick Question Can You Remove The Name Tag When Your Team Is Invisible ??
     
  11. Offline

    RyuGamer97

    me search on youtube and not have good luck for this tutorials :( i need help get basic plugin for test ?

    anyone have idea

    "what is a the program useful for this content me have eclipse and not working 100% for me "

    View attachment 20524
    anyone have idea for what is orden for this dates ? me see youtubers tutorials pesimos and working plugin is a mchelloplugin.

    help help help help i need plugin for scoreboard editable for my server :(
    ...

    do you have videos tutorial for scoreboard and api "is a beatiful in other servers "and have curiosity for plugins optional Api

    public class ?
    public void .... this a aver big big problem for me not have idea sorry :( for inpacient

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

    MinecraftMart

    chasechocolate
    Question, if i let the scoreboard beneath the players name show something thats in the config. And the config updates, does the scoreboard also automaticly update? Or do i need to make a method for that?
    And wich objective criterias should i use?
     
  13. Offline

    chasechocolate

    MinecraftMart no, you have to update it manually. I use "dummy" 99% of the time, the other ones are minecraft defaults. See the link in the first post.
     
  14. Offline

    RyuGamer97

    @chasechocolate need you help you see my pic what this orden for create scoreboard i need need need please
     
  15. Offline

    ScriptJunkie

    So i read through the whole thread and I have one question. If i register the scoreboard should i be able to do '/scoreboard objective objname list' and see the objectives listed? Or is it hidden from this function?
     
  16. Offline

    darkgreetingsnl

    chasechocolate
    I need your help! How do I teleport a team to his spawnpoint?
    Can you give an example please? I am trying things out, but never works..
     
  17. Offline

    chasechocolate

    darkgreetingsnl loop through all the players in the team and teleport them individually.
     
  18. Offline

    Kato233

    Hey guys

    Not sure what's going on really. Copied and pasted and browsed the API and can't really figure out why my Objective won't work.

    Code:
    package com.AcroTM.StatsSystem;
     
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.*;
     
    public class ScoreBoard {
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
     
        Objective objective = board.registerNewObjective("lives", "dummy");
        objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
        objective.setDisplayName("lives");
     
        for(Player online : Bukkit.getOnlinePlayers()){
            Score score = objective.getScore(online);
            score.setScore(5); //Example
        }
     
        for(Player online : Bukkit.getOnlinePlayers()){
            online.setScoreboard(board);
        }
    }
    
    These are the errors I am getting: http://prntscr.com/44z0w2
    I am not a noob in Java by any means, so I don't think it's me. There seems to be some people that can use this and others that cannot. Does it only work with a certain version of CB? Let me know if you guys can help a brother out.

    Cheers

    Hey all!

    I figured it out! You need to call upon a constructor if you are getting the errors of setdisplay and what not.
    Here is the code that WORKS
    Code:
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.*;
     
    public class ScoreBoard {
        ScoreboardManager manager = Bukkit.getScoreboardManager();
        Scoreboard board = manager.getNewScoreboard();
        Objective obj;
     
        public ScoreBoard() {
            obj = board.registerNewObjective("lives", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName("Stats TEST");
            for(Player online : Bukkit.getOnlinePlayers()){
                Score score = obj.getScore(online);
                score.setScore(5); //Example
            }
     
            for(Player online : Bukkit.getOnlinePlayers()){
                online.setScoreboard(board);
            }
        }
    }
     
    
    Simply call new ScoreBoard(); to initialize it.

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

    alzdoesmc

    If anyone can help me, it'd be greatly appreciated. I've got the code all set up, except it's not appearing when I join.
    Code:
        private Scoreboard pb;
    
        public Scoreboard getScoreboard(){
            return this.pb;
        }
        
        @EventHandler
        public void onJoin(PlayerJoinEvent event){ 
            Player p = event.getPlayer();
            p.setScoreboard(setupScoreboard());
        }
        
        public Scoreboard setupScoreboard(){
            pb = Bukkit.getScoreboardManager().getNewScoreboard();
            String none = "§r";
            String ip1 = "§a§lYou are playing on:";
            String ip2 = "§f§lPLAY.ALZDOESMC.COM";
            String site1 = "§a§lJoin our website:";
            String site2 = "§f§lalzdoesmc.com";
            String yt1 = "§a§lSubscribe to our YouTube:";
            String yt2 = "§f§lyt.alzdoesmc.com";
            String twitter1 = "§a§lFollow us on Twitter:";
            String twitter2 = "§f§l@AlzDoesMinecraf";
            String online = "§a§lThere are §7" + Bukkit.getOnlinePlayers() + "§8/§f" + Bukkit.getMaxPlayers() + " §a§lonline";
            Objective objective = pb.registerNewObjective("title", "dummy");
            objective.setDisplayName("§d§lPEARL NETWORK");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            Score top = objective.getScore(none);
                top.setScore(99);
            Score ipd1 = objective.getScore(ip1);
                ipd1.setScore(98);
            Score ipd2 = objective.getScore(ip2);
                ipd2.setScore(97);
            Score none1 = objective.getScore(none);
                none1.setScore(96);
            Score sited1 = objective.getScore(site1);
                sited1.setScore(95);
            Score sited2 = objective.getScore(site2);
                sited2.setScore(94);
            Score none2 = objective.getScore(none);
                none2.setScore(93);
            Score ytd1 = objective.getScore(yt1);
                ytd1.setScore(92);
            Score ytd2 = objective.getScore(yt2);
                ytd2.setScore(91);
            Score none3 = objective.getScore(none);
                none3.setScore(90);
            Score twitterd1 = objective.getScore(twitter1);
                twitterd1.setScore(89);
            Score twitterd2 = objective.getScore(twitter2);
                twitterd2.setScore(88);
            Score none4 = objective.getScore(none);
                none4.setScore(87);
            Score onlined = objective.getScore(online);
                onlined.setScore(86);
            return pb;
            
        }
    
     
  20. Offline

    Zarkopafilis

    For some reason my below name scoreboard is set to 0
     
  21. Offline

    Ozeir

    chasechocolate After I reload my server the teams will be emptied..
    And how can I set spawnpoints without using a config..?
     
  22. Offline

    Deleted user

    chasechocolate
    How would you make it so that the plugin setups the scoreboard when it enables and then when a player types a command it adds the player to the scoreboard. I can't figure out how to use the scoreboard across methods
     
  23. Offline

    chasechocolate

    alan1099 you can have a global Scoreboard variable in the main class that is instantiated (or "setup") in the onEnable(). Then, on the onCommand() method do whatever you need to do with the variable in the main class. If you don't know how to have variables shared across classes, then look up constructors.
     
  24. Offline

    Sw_aG

    chasechocolate
    Can you please help me, I'm trying to create a PvP-Scoreboard that will disaply the top 3 Killers on the server and after the server reloads itself it'll reset the scoreboard.
    The issue with my plugin that its not refresh itself every tick and its not only for the top 3 killers.

    Heres the plugin code: http://txs.io/AGpb
     
  25. Offline

    Awesomedanguy

  26. Offline

    WitchCraftMC

    Hello! I was wondering why my code isnt working :/ If Anyone could help that would be gr8! Heres the code:
    Code:
            // START OF SBTEAMS
            if(commandLable.equalsIgnoreCase("ct")) {
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard board = manager.getNewScoreboard();
                // CREATING TEAMS
                Team red = board.registerNewTeam("red");
                Team blue = board.registerNewTeam("blue");
                // FRIENDLY FIRE
                red.setAllowFriendlyFire(false);
                blue.setAllowFriendlyFire(false);
                // SEE FRIENDLY INVIS.
                red.setCanSeeFriendlyInvisibles(true);
                blue.setCanSeeFriendlyInvisibles(true);
                // SUFFIX
                red.setSuffix(ChatColor.GRAY + "[" + ChatColor.RED + "RED" + ChatColor.GRAY + "]" + ChatColor.RESET);
                blue.setSuffix(ChatColor.GRAY + "[" + ChatColor.BLUE + "BLUE" + ChatColor.GRAY + "]" + ChatColor.RESET);
                // SUCCESS MSG
                player.sendMessage("Succesfully Created Teams!");
                // JOINING RED
                if(commandLable.equalsIgnoreCase("joinred")) {
                    red.addPlayer(player);
                    player.sendMessage(ChatColor.GREEN + "You Have Joined The" + ChatColor.RED + "RED" + ChatColor.GREEN + "Team!");
                }
                // JOINING BLUE
                if(commandLable.equalsIgnoreCase("join blue")) {
                    blue.addPlayer(player);
                    player.sendMessage(ChatColor.GREEN + "You Have Joined The" + ChatColor.BLUE + "BLUE" + ChatColor.GREEN + "Team!");
                }
            }
            // END OF SBTEAMS
     
  27. Offline

    GalaxyCraft

    chasechocolate

    I have followed this tutorial, and i have a working scoreboard :D

    However i need to get vault to show the players balance on the scoreboard, i have looked at different topics but none had the solution that i could find.

    This is my code:
    Code:java
    1. package me.unique.scoreboard;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import net.milkbowl.vault.economy.Economy;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.ChatColor;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.plugin.RegisteredServiceProvider;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13. import org.bukkit.scoreboard.DisplaySlot;
    14. import org.bukkit.scoreboard.Objective;
    15. import org.bukkit.scoreboard.Score;
    16. import org.bukkit.scoreboard.Scoreboard;
    17. import org.bukkit.scoreboard.ScoreboardManager;
    18.  
    19.  
    20. public class Main extends JavaPlugin implements Listener {
    21.  
    22. private static final Logger log = Logger.getLogger("Minecraft");
    23. public static Economy econ = null;
    24.  
    25.  
    26. public void onEnable() {
    27.  
    28. if (!setupEconomy() ) {
    29. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    30. getServer().getPluginManager().disablePlugin(this);
    31. return;
    32. }
    33.  
    34. ScoreboardManager manager = Bukkit.getScoreboardManager();
    35. Scoreboard board = manager.getNewScoreboard();
    36.  
    37. Objective objective = board.registerNewObjective("test", "dummy");
    38.  
    39. //Setting where to display the scoreboard/objective (either SIDEBAR, PLAYER_LIST or BELOW_NAME)
    40. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    41.  
    42. //Setting the display name of the scoreboard/objective
    43. objective.setDisplayName("Statistics");
    44.  
    45. for(Player online : Bukkit.getOnlinePlayers()){
    46. online.setScoreboard(board);
    47. Score scoreDeaths = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Deaths:"));
    48.  
    49. scoreDeaths.setScore(50);
    50. }
    51. }
    52.  
    53. private boolean setupEconomy() {
    54. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    55. return false;
    56. }
    57. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    58. if (rsp == null) {
    59. return false;
    60. }
    61. econ = rsp.getProvider();
    62. return econ != null;
    63. }
    64. }
    65.  


    I have imported Vault so everything is working.

    How would i get the players balance to show on the scoreboard? :(

    Thanks in advanced

    Unique
     
  28. Offline

    chasechocolate

  29. Offline

    ariaDEE

    Of course I find out about this after I make a whole custom team system already.
     
  30. Offline

    ChipDev

    500.. Yah!!
    Love this scoreboard tut.
     
Thread Status:
Not open for further replies.

Share This Page