[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

    Desle

    Dubehh
    .... Yes?
    team.addPlayer(((Player) sender);
     
  2. Offline

    Dubehh

    It doesnt work.
     
  3. Offline

    legoman519

    When I add maxPlayers ingame in says 0 players when theres 2
     
  4. Offline

    SuperOmegaCow

    Captain Dory no one is on for the onEnable...
    EDIT: noticed I said only instead of on
     
  5. Offline

    Captain Dory

    I fixed this a while ago :p
     
  6. Offline

    HeavyMine13

    How can I make a scoreboard to get all online players and put them on a sidebar?
     
  7. Offline

    Captain Dory

    Loop through all online players and make a new score/objective with their name perhaps?
     
  8. Offline

    HeavyMine13

  9. Offline

    Captain Dory

    It should be something like:
    PHP:
    Objective objective board.registerNewObjective("test""dummy");
    objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    objective.setDisplayName("Players");
    for (
    Player p Bukkit.getOnlinePlayers) {
    Score score objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN p.getName()));
    score.setScore(1);
    }
     
  10. Offline

    sportsziggy

    Can anyone help me get an objective (breaking a flower) to update from?
    I'm not sure if I even this this up correctly... :
    PHP:
    @EventHandler
        
    public void onBrokenFlower(PlayerInteractEvent e)
    {
            
    Player player e.getEntity();
     
            if (
    player instanceof Player){
                
    int flowerBroken this.configFile.getInt("Flower :" + .get + ); 
                
    SOMETHING_UPDATED++;
         
                
    this.configFile.set("Players." player.getName() + ".flower"Integer.valueOf(flowerBroken));
         
              
    savePlayerConfig();
            }
        }
     
  11. Offline

    PratamaJr

    Great Tutorial

    Bookmark :)
     
  12. Offline

    ToastHelmi

    chasechocolate
    Im trying to use scorebords to display a Text under the players NameTag.

    Is that posible because im not able to display and text without setting a score
     
  13. Offline

    Wizehh

    Set the score name as something, and set the score to 0?
     
  14. Offline

    chasechocolate

    ToastHelmi no, it's not possible to remove the score value.
     
  15. Offline

    Acer_Mortem

    Code:
            for(Player p : Bukkit.getOnlinePlayers()){
               
                Scoreboard board = manager.getNewScoreboard();
                Objective Aobjective = board.registerNewObjective(p.getName() "dummy");
                Aobjective.setDisplaySlot(DisplaySlot.BELOW_NAME);
                Aobjective.setDisplayName(dfs.getClass(p.getUniqueId()));
                Score cooldown1 = Aobjective.getScore(Bukkit.getOfflinePlayer(dfs.getClass(p.getUniqueId())));
                cooldown1.setScore(dfs.getLevel(p.getUniqueId()));
               
                p.setScoreboard(board);
    Okay, allow me to explain all of this code.

    On the onEnable of the plugin, it for loops through all Online Players.

    Then a board is created for every single players.

    An objective is registered for that board.

    The objective is set in the Below_Name display slot.

    Then, the Objective sets it's display name from a string (dfs.getClass(p.getUniqueId()) returns a string, either being: "Mage" or "Archer").

    Then,the objective gets a score, and sets the score to the players level in their class (dfs.getLevel(p.getUniqueId()) returns an integer).

    Finally, it sets the players scoreboard.


    Now, there are two problems with this:

    Player A - Archer
    Player B - Mage

    Player A has a scoreboard with the class name "Mage" (even though Player A is an Archer), and Player B has a scoreboard with the class name "Archer" (even though Player B is a Mage).

    Secondly, the scores never show up, they only show as 0 (zero)'s.

    Anyone know what's going wrong?
     
  16. Offline

    The Fancy Whale


  17. I also tried to do something like this, but it doesn't work at all.

    It seems like everybody who is using the "belowname" slot uses it for health.

    It seems like if you send a board with below name slot to a player it means that this player will see this below the names of the other players and not (how I excepted) below his own name visible for all other players.

    So my question is:

    How can I set the level of the player into the slot below the name?

    I want that other players are able to see the level of me below my name !
    It doesn't look like this is possible.
     
    Acer_Mortem likes this.
  18. Offline

    mr_snake302

    Hi! I need help, I should take player with HighestScorer and tp him!

    How I can do this?
     
  19. what bukkit build supports scoreboards? can i please have a link?
     
  20. Offline

    Qwahchees

    chasechocolate
    Great guide! I just wanna make a note that if you use Craftbukkit, sometimes importing via IDE will import the net.minecraft version of "Scoreboard", which won't allow you to do manager.getNewScoreboard();
    To fix, org.bukkit.scoreboard.Scoreboard; should be the import, I think this should be noted.
     
  21. Offline

    akabarblake

    Hey Nauss. (I've seen you on Hypixel, and you friended me, Im the luckiest man ever),
    If I make a ton of teams (5), One is named Pig.
    Code:java
    1. Team Pig = sboard.registerNewTeam("Pig");

    then how do I add someone?
    Pig.addPlayer(player); ?
    thanks.
     
  22. Offline

    Garris0n

    Yes, that's how. Did you actually try it? Or check the JavaDocs?

    Also, you should not have a variable named "Pig". Please read through the Java naming conventions.
     
  23. Offline

    akabarblake

    I just thought that would be it. It says "Pig cannot be resolved.", weird. Ill check the naming'.
     
  24. Offline

    Garris0n

    Might be an issue with the class pig because you didn't follow the naming conventions :p
     
    AoH_Ruthless likes this.
  25. Offline

    akabarblake

    Idea?

    Player winner = If player gets X score;
    teleport winner to xyz

    Fixed. I needed to add a class to each one.

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

    seanlego7

    I'm not sure if you figured this out yet, but if you didn't then you want to put in this piece of code in your onDisable.
    Code:
     teamname.unregister();  
    If it isn't working, have you got a static for your TeamName?
    Code:
     public static Team teamname;
     
  27. Offline

    akabarblake

    @chasechocolate
    Need to know, How do I show team specific objectives? Its possible in vanilla .
    Like this:
    Team X has X below name, and team X+ has X+ below their name; do you know how to do that? thanks.
     
  28. Offline

    Meatiex

    @chasechocolate
    is their a way to get the player's team color?
    I'm trying to make a chat plugin that uses the player's name color and it isn't working...
    How I set the color:
    Code:java
    1. if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(player.getName()) == null){
    2. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams add " + player.getName() + " " + player.getName());
    3. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams join " + player.getName() + " " + player.getName());
    4. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams option " + player.getName() + " color GREEN");}

    Code:java
    1. if (cmd.getName().equalsIgnoreCase("color")) {
    2. if (sender.hasPermission("meatie.color")) {
    3. if (args.length >= 1) {
    4. if (!args[0].toUpperCase().equals("STRIKETHROUGH")&& !args[0].toUpperCase().equals("BOLD") && !args[0].toUpperCase().equals("ITALICIZE")
    5. && !args[0].toUpperCase().equals("RANDOM")) {
    6. if(Bukkit.getScoreboardManager().getMainScoreboard().getTeam(sender.getName()) == null){
    7. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams add " + sender.getName() + " " + sender.getName());
    8. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams join " + sender.getName() + " " + sender.getName());}
    9. try {
    10. ChatColor.valueOf(args[0].toUpperCase());
    11. if (args.length == 2) {
    12. Player target = Bukkit.getPlayer(args[1]);
    13. if (sender.hasPermission("meatie.setcolor")) {
    14. if(target != null) {
    15. sender.sendMessage(target.getName() + "'s Name color is now " + args[0]);
    16. target.sendMessage("You'r Name color is now " + args[0]);
    17. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams option " + target.getName() + " color " + args[0]);
    18. } else {sender.sendMessage("Player " + args[0] + " not online");}
    19. }
    20. } else {
    21. sender.sendMessage("You'r Name color is now " + args[0]);
    22. Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "scoreboard teams option " + sender.getName() + " color " + args[0]);
    23. }
    24.  
    25.  
    26. if (sender.hasPermission("meatie.setcolor")) {
    27. sender.sendMessage(ChatColor.GREEN + "/color color player");
    28. } else {sender.sendMessage(ChatColor.GREEN + "/color color");}
    29.  
    30. sender.sendMessage(ChatColor.WHITE + "White " + ChatColor.BLACK + "Black " + ChatColor.DARK_BLUE + "Dark_Blue " + ChatColor.DARK_GREEN + "Dark_Green "+
    31. ChatColor.DARK_AQUA + "Dark_Aqua " + ChatColor.DARK_RED + "Dark_Red " + ChatColor.DARK_PURPLE + "Dark_Purple " + ChatColor.LIGHT_PURPLE + "Light_Purple " +
    32. ChatColor.GOLD + "Gold " + ChatColor.GRAY + "Gray " + ChatColor.DARK_GRAY + "Dark_Gray " + ChatColor.GREEN + "Green " + ChatColor.AQUA + "Aqua " +
    33. ChatColor.RED + "Red " + ChatColor.YELLOW + "Yellow " + ChatColor.BLUE + "Blue");
    34. }
    35. }
    36. }
    37. }
    38. return true;}

    The part that doesn't accept the color:
    When i run this code I get this message:
    BOSS Meatie bla (My color when I press tab is blue and i did /color blue)

    Any help will be awesome, right now everyone has green names :p
    Code:java
    1. @EventHandler
    2. public void Chatevent(AsyncPlayerChatEvent event) {
    3. Player player = event.getPlayer();
    4. String msg = event.getMessage();
    5. //String format = "pre" + player.getDisplayName() + " " + msg;
    6. if (!player.hasPermission("group.vip") && player.hasPermission("group.guest")) {
    7. String format = ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + ":" + msg;
    8. event.setFormat(format);
    9. } else if (player.hasPermission("group.vip") && !player.hasPermission("group.epic")) {
    10. String format = ChatColor.DARK_BLUE + "" + ChatColor.BOLD + "[VIP] " + ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + " " + msg;
    11. event.setFormat(format);
    12. } else if (player.hasPermission("group.epic") && !player.hasPermission("group.elite")) {
    13. String format = ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "[Epic] " + ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + " " + msg;
    14. event.setFormat(format);
    15. } else if (player.hasPermission("group.elite") && !player.hasPermission("group.mod")) {
    16. String format = ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "[Elite] " + ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + " " + msg;
    17. event.setFormat(format);
    18. } else if (player.hasPermission("group.mod") && !player.hasPermission("group.boss")) {
    19. String format = ChatColor.LIGHT_PURPLE + "" + ChatColor.BOLD + "[Moderator] " + ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + " " + msg;
    20. event.setFormat(format);
    21. } else if (player.hasPermission("group.boss")) {
    22. String format = ChatColor.DARK_RED + "" + ChatColor.BOLD + "[BOSS] " + ChatColor.GREEN + player.getDisplayName() + ChatColor.WHITE + " " + msg;
    23. event.setFormat(format);
    24. }
    25.  
    26. event.setMessage("" + msg);
    27. }
     
  29. Offline

    LCastr0

    chasechocolate How would I make something like this:
    The player joins, then it displays before the players nametag his prefix?
    I know how to get the prefix, and everything else, but how would I add the team prefix to the player's nametag?
     

  30. @chasechocolate How would you "update each player's board from there"? Sorry i am fairly new to coding

    EDIT: I have created a thread on this, if anyone could reply, that'd be great. :)
     
Thread Status:
Not open for further replies.

Share This Page