[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

    GalaxyCraft

  2. Offline

    ariaDEE

  3. Offline

    MrDplugins

    chasechocolate WARNING I'M NEW FOR BUKKIT CODING!!
    How do I make the teams out of the onEnable()? whenever I try to put my code somewhere else it always gives me errors? but in other posts they do not have their team creation in the onEnable(). Please Help!
     
  4. Offline

    Onlineids

    MrDplugins onEnable runs the code when the plugin is enabled some people are using seperate classes with constructors so they can simply call new Class()
     
    MrDplugins likes this.
  5. Offline

    ScriptJunkie


    Nobody has an answer to this? Trying to setup money and see the money in the scoreboard on left but i cannot use a command block to testfor the money... Is this a problem with bukkit or should it be able to interface? I have tried spawning scoreboard at the onEnable and OnPlayerJoin and both ways i cannot see my currency when doing a testfor.
     
  6. Offline

    MrDplugins

    Onlineids So, I need to make a class named (for example) TeamSutff pust all my code in some sort of constructor so I can call it in my Main class?
     
  7. Offline

    CytrixMC

    chasechocolate how could I make a personal scoreboard for each player. Like to show statistics such as kills, deaths, and etc.
     
    GrandmaJam likes this.
  8. Offline

    ChipDev


    Code:java
    1. for(Player p : getServer().getOnlinePlayers() {
    2. }

    Get online players.
    Code:java
    1. //Online player stuff so you won't Copy paste {
    2. int deaths = 1
    3. string name = p.getName();
    4. //Show scoreboard to 'p' and show strings like 'name';
    5. }

    Show scoreboard
     
  9. Offline

    CrispyCookie

    Creating a fake offline player doesn't work for me. What's wrong?

    [​IMG]
     
    GrandmaJam likes this.
  10. Offline

    LCastr0

    No, it does. You have used a String inside (). You should use Bukkit.getOfflinePlayer("Kills:")
     
  11. Offline

    wydgabriel

    Code:java
    1. @EventHandler(priority=EventPriority.HIGH)
    2. public void onPlayerJoin(PlayerJoinEvent e)
    3. {
    4. Player p = e.getPlayer();
    5.  
    6. ScoreboardManager manager = Bukkit.getScoreboardManager();
    7. Scoreboard board = manager.getNewScoreboard();
    8.  
    9. Objective objective = board.registerNewObjective("Kills", "dummy");
    10. objective.setDisplaySlot(DisplaySlot.BELOW_NAME);
    11. objective.setDisplayName(" "+ChatColor.BOLD +"Kills");
    12.  
    13.  
    14.  
    15.  
    16. Score core = objective.getScore(p);
    17.  
    18. core.setScore(Configuraciones.getInstance().getData().getInt(p.getName()+".PontosDeGladiador".toString()));
    19.  
    20. p.setScoreboard(board);
    21.  
    22.  
    23. }

    How to make it work? It stays 0 Kills below every name, even if PontoDeGladiador: 10 for example..
     
  12. Offline

    JoshKeighley

    chasechocolate is there any way to show more than 1 scoreboard at a time?
    eg. 1 in the tablist and 1 in the sidebar?
    Thanks, and great tutorial <3
     
  13. Offline

    teej107

    JoshKeighley Register your objectives with the same scoreboard, just change the display slot of the objective.
     
    JoshKeighley likes this.
  14. Offline

    martin0leung

    Code:java
    1. @SuppressWarnings("deprecation")
    2. public void setupScoreboard() {
    3. board = Bukkit.getScoreboardManager().getNewScoreboard();
    4.  
    5. Objective stats = board.registerNewObjective("thronch", "dummy");
    6. stats.setDisplaySlot(DisplaySlot.SIDEBAR);
    7. stats.setDisplayName(ChatColor.RED + "" + ChatColor.BOLD + "Thronch Arena" + ChatColor.AQUA + ChatColor.BOLD + "[ALPHA]");
    8.  
    9. Score kills = stats.getScore(Bukkit.getServer().getOfflinePlayer(ChatColor.RED + "" + ChatColor.BOLD + "Kills:" + ChatColor.AQUA + ChatColor.BOLD + TotalKills));
    10. kills.setScore(0);
    11. }

    Why doesn't it make a new Objective? or what happened? This doesn't work for some reason... Please answer this!
     
  15. Offline

    metincasper

    How do i acces all the players on a team, so i can teleport them to a spawnpoint? or send them a message
     
  16. Offline

    567legodude

    I know that this has the setScore() method, but what do I do if I want to add a score? So instead of setting the score to 5 I will add 5 to the current score.
     
  17. Offline

    teej107

  18. Offline

    567legodude

    teej107 But it says "The operator + is undefined for the type(s) Score, int" which is why I can't figure out how to do it.
     
  19. Offline

    teej107

  20. Offline

    567legodude

    teej107 That doesn't help, if I do
    Code:java
    1. Score score = objective.getScore(name);
    2. score.setScore(score + int);

    It says "The operator + is undefined for the type(s) Score, int"
    If I do
    Code:java
    1. Score score = objective.getScore(name);
    2. int sc = (int) score;

    It says "Can't convert from Score to int"
    If I do
    Code:java
    1. Score score = objective.getScore(name);
    2. int sc = Integer.parseInt(score);

    It says "The method parseInt(String) is not applicable for the arguments (Score)"

    Now, with all that being said, it appears you can't convert a score to an int. So how do I add to the score?

    teej107 Nvm, I found out that I could do it like this.
    Code:java
    1. Score score = objective.getScore(name);
    2. score.setScore(Integer.parseInt(score.toString()) + int);


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

    teej107

    No. Did you even take a look at the links I posted? Especially the first one?
     
  22. Offline

    567legodude

    teej107 The only thing it says is that getScore() "Returns the current score"
    Since that didn't help, I figured out how to do it.
     
  23. Offline

    RingOfStorms

    Please delete the code you've made and never use it, "Score" is an object and does not represent an integer value by itself. It does however have a method, linked teej, that returns the integer representation of the score. So you would do score.getScore() to get the integer value.

    Serializing the Score object and then parsing it back as an integer is incredibly inefficient and just all around horrible looking, not to mention it was a complete shot in the dark and incredibly lucky that it worked to begin with. I strongly suggest learning java basics as well as learning how to read javadocs before you continue much further in your coding career.
     
    teej107 likes this.
  24. Offline

    567legodude

    RingOfStorms Okay, first of all, I am not new to coding, I have done it for a long time.
    And second, the very first thing that I tried was the following:
    Code:java
    1. Score score = objective.getScore(name);
    2. score.setScore(score + int);

    Because that it what should be the case, but for some reason, I am getting an error when I do that.
    Out of all 4 methods that I presented, none of them worked, so if you would like to tell me how to make this work, then go ahead.
    The above code is the first thing I tried, and it said "The operator + is undefined for the type(s) Score, int"

    RingOfStorms I also found that in my case, it would be easier to make a HashMap to hold the scores. And just read the value from there.

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

    RingOfStorms

    *facepalm*

    SCORE is not an integer, so of course you can't add a score to an integer. Guess what, you can use the method that I said the first time, and that the guy linked the first time to get the integer. I'll just give you the code snippet again and hope you actually can read it and figure it out.

    Code:
    score.getScore();
    
    In other words, with your code exactly it would be:
    Code:java
    1. Score score = objective.getScore(name);
    2. score.setScore(score.getScore() + int);


    The Score object is not an integer, obviously it won't simply add itself to int.
     
  26. Offline

    567legodude

    RingOfStorms In that case, this could have been solved in one post by saying
    "Use getScore() on the score object that you are adding to the int"

    It was like 11 at night when I was doing that, so I had a brain fart and didn't realize that.
     
  27. Offline

    RingOfStorms

    There was one post that said that. teej linked to the javadoc method that was EXACTLY that. And the very first post I said had the score.getScore() in it. We did say that and you ignored us because of your "super awesome wisdom from your long time in coding".
     
  28. Offline

    567legodude

    RingOfStorms When he said "get the score", I thought I had already gotten the score with the first line, I didn't know he wanted me to get the score again.
     
  29. Offline

    teej107

    567legodude I then gave you links to the JavaDocs which should have been good enough if you knew how to read them.
     
  30. Offline

    RyuGamer97

    i have this error and write "objective.setDisplaySlot(DisplaySlot.SIDEBAR);" in thes objective. <---- ( . ) have syntax erro because ?
     
Thread Status:
Not open for further replies.

Share This Page