[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

    serfma

    Using the 1.5.2R0.1 Bukkit version and whenever I do "Scoreboard board = manager.getNewScoreboard();" I get "Incompatible types; Required: net.minecraft.server.v1_5_R3.Scoreboard, Found: org.bukkit.scoreboard.Scoreboard"

    imgur link: http://i.imgur.com/dl5BC36.png
     
  2. Offline

    chasechocolate

    serfma import the org.bukkit.scoreboard.
     
  3. Offline

    serfma


    Doesn't work. Says it can't be found.
     
  4. Offline

    chasechocolate

    Well it found it in up the picture you posted... Use "import org.bukkit.scoreboard.Scoreboard;"
     
  5. Offline

    serfma


    Brb, gotta facepalm pretty hard. Scrolled up one extra line and noticed the net.minecraft.etcetc was imported already somehow. Fixed. >_> Lol
     
  6. Offline

    CaLxCyMru

    Hello everyone, Im going to sound like a noob here, But how can I add more than one fake Player and make it count something ( Deaths or Kills ) Please help me :)

    P.S Where is the best place to put the code? in a Event or in a command, Or onEnable?
     
  7. Offline

    chasechocolate

    CaLxCyMru in the original post I put something for custom names on scores, just copy-and-paste that multiple times. For counting kills and deaths you can save them in a HashMap<String, Integer>. You would put the scoreboard code in different places depending on when you want players to get the scoreboard.
     
  8. Offline

    CaLxCyMru

    @chasechocolate Thank you for the help. :)

    @chasechocolate Thank you for the help. :)

    Sorry to bother again but How do I make the health ( While its a dummy ) change according to the player's health ( Player takes damage, But it does not update on the SIDEBAR list type, Is there a way so this updates, While using the dummy, Or is there way I can use a Dummy and the Heath type together on the SIDEBAR )

    My code -- http://pastebin.com/rWRKMgcM

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

    nitrousspark

    chasechocolate when do you run this?

    Code:
     
    org.bukkit.scoreboard.ScoreboardManager manager = Bukkit.getScoreboardManager();
    org.bukkit.scoreboard.Scoreboard board = manager.getNewScoreboard();
     
    Objective objective = board.registerNewObjective("showhealth", "health");
    objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    objective.setDisplayName("/ 20");
     
    for(Player online : Bukkit.getOnlinePlayers())
    {
    online.setScoreboard(board);
    online.setHealth(online.getHealth());
    }
    
    i run this when the player joins and sometimes it works, but most of the time it just shows 0 / 20
     
  10. Offline

    chasechocolate

    nitrousspark yeah, I've had that happen before also... maybe update the player's health in a sync task after a few ticks?
     
  11. Offline

    nitrousspark

    and this is how you update a players health?

    player.setHealth(player.getHealth());
     
  12. Offline

    chasechocolate

    Yeah.
     
  13. Offline

    Meowlupus123

    I'm so sorry but I just started coding and using the BukkitAPI, but in what area do you call for this? I tried after if statements and onEnable() but it doesn't seem to work. All I want to do with it is make it so There are two teams that can be joined and left by commands. (Such as /tdmjoin or /tdmleave) But this, for me, is really high level. Could you please show me an example of how to set up the teams so I can see where to put things?
    Thank you so much,
    Meowlupus123 - Head Admin - EpiphanyRealms
    < play.epiphanyrealms.com >
     
  14. Offline

    nitrousspark

    chasechocolate

    why doesnt this work?

    Code:
    Team team = board.registerNewTeam("staff");
    team.setAllowFriendlyFire(true);
    team.setCanSeeFriendlyInvisibles(false);
    team.setPrefix(ChatColor.DARK_RED + "Staff");
    OpportunityCraft.staff = team;
    then when the player joins i do OpportunityCraft.staff.addPlayer(player);
    shouldnt this add a [Staff] prefix to the player?
     
  15. Offline

    chasechocolate

    nitrousspark I think you also need to set the player's scoreboard.
     
  16. Offline

    nitrousspark

    it still doesnt work, do i need to create the team and add them when they join instead of when the server starts?
     
  17. Offline

    ritipinheiro

    How can i update every 5 seconds?
     
  18. Offline

    kreashenz

    ritipinheiro Create a method that sets the scoreboard, and run it in a scheduler.
     
    ritipinheiro likes this.
  19. Offline

    ritipinheiro

    but if you update like 1 tick each time its so fast updating that you cant see
     
  20. Offline

    kreashenz

    ritipinheiro Then do 5*20 as the time. Also, it flickers when you have it do that.
     
    ritipinheiro likes this.
  21. Offline

    ritipinheiro

    kreashenz

    Thanks, i put 100 = 5 seconds to update because it flicks you solved my problem :p
     
  22. Offline

    KittyKatt

    Is there a way to not auto sort the scoreboard?
     
  23. Offline

    whatapigdoes

    Hw do you get a player's Score?
     
  24. Offline

    chasechocolate

    Nope :(
    objective.getScore(player).
     
  25. Offline

    whatapigdoes

  26. Offline

    macmc

    I don't know about you guys, but a sidebar dummy scoreboard won't display unless I set a score (which I don't necessary feel like doing), do you have the same issue?
     
  27. Offline

    chasechocolate

    macmc what is your code? What are you trying to do?
     
  28. Offline

    macmc

    chasechocolate Well I modified it so I don't have it anymore, but when I create a new scoreboard exactly like in your tutorial, and if I don't add a score to the Objective, it won't display on the sidebar for the player.
    I send you the code as soon as I try again; that's pretty annoying cause I can't display exactly what I want :(
     
  29. Offline

    chasechocolate

    macmc So you want to only show the display name and have no scores? I don't think you can do that, I think you have to have at least 1 objective to show up.
     
  30. Offline

    MineoxFX

    Whats wrong in this:


    Code:java
    1. package com.MineoxFX.SelectTeam;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11. import org.bukkit.scoreboard.Scoreboard;
    12. import org.bukkit.scoreboard.ScoreboardManager;
    13. import org.bukkit.scoreboard.Team;
    14.  
    15. public class SelectTeam extends JavaPlugin {
    16. public final Logger logger = Logger.getLogger("Minecraft");
    17. public static SelectTeam plugin;
    18.  
    19. @Override
    20. public void onEnable(){
    21. team1.setPrefix("[" + ChatColor.RED + "Team1" + ChatColor.WHITE + "]");
    22. team2.setPrefix("[" + ChatColor.BLUE + "Team2" + ChatColor.WHITE + "]");
    23. team1.setAllowFriendlyFire(false);
    24. team2.setAllowFriendlyFire(false);
    25. }
    26.  
    27. ScoreboardManager manager = Bukkit.getScoreboardManager();
    28. Scoreboard board = manager.getNewScoreboard();
    29. Team team1 = board.registerNewTeam("Team1");
    30. Team team2 = board.registerNewTeam("Team2");
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd,
    33. String commandLabel, String[] args) {
    34. Player player = (Player) sender;
    35. if (commandLabel.equalsIgnoreCase("join" + args[0])) {
    36. if (args[0].equalsIgnoreCase("1")){
    37. team1.addPlayer(player);
    38. player.sendMessage(ChatColor.YELLOW + "You have joined team" + args[0]);
    39. }
    40. else if (args[0].equalsIgnoreCase("2")){
    41. team2.addPlayer(player);
    42. player.sendMessage(ChatColor.YELLOW + "You have joined team" + args[0]);
    43. } else {
    44. player.sendMessage(ChatColor.RED + "Select a valid Team!");
    45. }
    46. }
    47. if (commandLabel.equalsIgnoreCase("teamlist" + args[0])){
    48. if (args[0].equalsIgnoreCase("1")) {
    49. player.sendMessage("Team 1 Players:" + team1.getPlayers());
    50. }
    51. else if (args[0].equalsIgnoreCase("2")){
    52. player.sendMessage("Team 2 Players:" + team2.getPlayers());
    53. }
    54. else {
    55. player.sendMessage(ChatColor.RED + "Enter a valid Team #");
    56. }
    57. }
    58. return false;
    59.  
    60. }
    61. }
    62.  
    63.  
    64.  
     
Thread Status:
Not open for further replies.

Share This Page