Solved Scoreboard

Discussion in 'Plugin Development' started by Wantsome909, Dec 23, 2013.

Thread Status:
Not open for further replies.
  1. Offline

    Wantsome909

    how can i make it so the in-game scoreboard will display my tokens?

    Code:java
    1. public static Map<String, Integer> tokenss = new HashMap<String, Integer>();
    2.  
    3. @Override
    4. public void onEnable() {
    5. //save for tokens
    6. }
    7. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    8. @Override
    9. public void run() {
    10. for(Player p : Bukkit.getOnlinePlayers()){
    11. tokens.createScoreboard(p);
    12. }
    13. }
    14. }, 0, 200);
    15. }
    16.  
    17. @Override
    18. public void onDisable() {
    19. //load for tokens
    20. }
    21.  
    22. public static void createScoreboard(Player player){
    23. ScoreboardManager sm = player.getServer().getScoreboardManager();
    24. Scoreboard sb = sm.getNewScoreboard();
    25. Objective score = sb.registerNewObjective("aaa", "bbb");
    26. score.setDisplayName("GreatArms");
    27. score.setDisplaySlot(DisplaySlot.SIDEBAR);
    28.  
    29. Score tokens1 = score.getScore(Bukkit.getOfflinePlayer(ChatColor.RED + "Tokens: "));
    30. tokens1.setScore(/*if i put tokens here it wont work i need to make the hashmaps an int*/);
    31.  
    32. player.setScoreboard(sb);
    33. }
     
  2. Offline

    negative_codezZ

    Wantsome909
    tokens1.setScore(this.tokens.get(player.getName()));
     
  3. Offline

    Wantsome909

  4. Offline

    negative_codezZ

    Don't make the method static. It's not accessing outer variables.
     
  5. Offline

    BeYkeRYkt

    Wantsome909

    Code:java
    1. @Override
    2.  
    3. public void onEnable() {
    4.  
    5. //save for tokens
    6.  
    7. }
    8.  
    9. //this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    10. //@Override
    11. //public void run() {
    12. //for(Player p : Bukkit.getOnlinePlayers()){
    13. //tokens.createScoreboard(p);
    14. //}
    15. //}
    16. //}, 0, 200);
    17.  
    18.  
    19.  
    20. }


    It doing here? Maybe:

    Code:java
    1. @Override
    2.  
    3. public void onEnable() {
    4.  
    5.  
    6. this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable(){
    7. @Override
    8. public void run() {
    9. for(Player p : Bukkit.getOnlinePlayers()){
    10. tokens.createScoreboard(p);
    11. }
    12. }
    13. }, 0, 200);
    14. }
    15.  
    16.  
    17. }
     
  6. Offline

    Wantsome909

    negative_codezZ if i make the method non-static the tokens.createScoreboard(player) ; is underline in red
     
  7. Offline

    1Rogue

    You're in the same class, you don't need to prefix the method with the class name (which should be uppercase).
     
  8. Offline

    Wantsome909

  9. Why making a loop? I think it's much more efficient to execute the code by PlayerJoinEvent.
     
  10. Offline

    1Rogue

    Code:java
    1. tokens.createScoreboard(p);


    I'm assuming your class is named tokens, in which case, you don't need the class name to call the method from within it. You can just use:

    Code:java
    1. createSccoreboard(p);
     
  11. Offline

    Wantsome909

Thread Status:
Not open for further replies.

Share This Page