Solved Multiple ScoreBoards Problem

Discussion in 'Plugin Development' started by vasil7112, Aug 24, 2013.

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

    vasil7112

    Dear Developers,
    I am having some problems with ScoreBoards, so i will try to explain with as much details i can, and recieve the best possible solutions:)
    What i want: A personal scoreboard for each player.
    What is my problem: When a new player joins, All players scoreboards display the stats of the last joined player.
    SOURCE:
    Code:java
    1. package me.vasil7112.<plugin>.listeners;
    2.  
    3. import me.vasil7112.<plugin>.Main;
    4. import org.bukkit.Bukkit;
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.scoreboard.DisplaySlot;
    9. import org.bukkit.scoreboard.Objective;
    10. import org.bukkit.scoreboard.Scoreboard;
    11. import org.bukkit.scoreboard.ScoreboardManager;
    12.  
    13.  
    14. public class ScoreBoards implements Listener{
    15. public static Main plugin;
    16. public static ScoreBoards Instance;
    17. ScoreboardManager manager = Bukkit.getScoreboardManager();;
    18. Scoreboard board = manager.getNewScoreboard();
    19. public Objective objective;
    20. int Time;
    21. public static void init(Main i){
    22. plugin = i;
    23. }
    24.  
    25. public ScoreBoards(){
    26. Instance = this;
    27. }
    28. public void updateScoreBoards(){
    29. for(Player player : Bukkit.getServer().getOnlinePlayers()){
    30. updateScoreBoard(player);
    31. }
    32. }
    33.  
    34. public void updateScoreBoard(Player player){
    35. if(board.getObjective("SB_" + player.getName()) == null){
    36. objective = board.registerNewObjective("SB_" + player.getName() , "dummy");
    37. }else{
    38. objective = board.getObjective("SB_" + player.getName());
    39. }
    40. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    41. objective.setDisplayName("Status");
    42. objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GREEN + "Points:")).
    43. setScore(Main.Instance.getConfig().getInt("PlayerStats." + player.getName() + ".points"));
    44. player.setScoreboard(board);
    45. }
    46. }

    And OnJoin Source:
    Code:java
    1. @EventHandler
    2. public void onJoin(PlayerJoinEvent e){
    3. final Player player = e.getPlayer();
    4. ScoreBoards.Instance.updateScoreBoard(player);
    5. }

    Errors Recieved: NONE
     
  2. Offline

    CMG

    I think i may know the problem it could be that when the first player joins it creates that player variable, and keeps it to that, adding final to the beginning makes it so that variable stays to that and can't be changed so change this:
    Code:java
    1. final Player player = e.getPlayer();

    to this:
    Code:java
    1. Player player = e.getPlayer();
     
  3. Offline

    vasil7112

    Unfortunatly, nothing changed:/
     
  4. Offline

    CMG

    Is that your main class scoreboards?
    Edit Nevermind
     
  5. Offline

    vasil7112

    No, but here is the Structure if you need it:
    me.vasil7112.<plugin>. Main.class
    -. Api.
    ------.SomeApis.class
    -. listeners.
    -----------.ScoreBoards.class
    -----------.OtherListeners.class
    Fixed using some HashMaps to save scores.
     
Thread Status:
Not open for further replies.

Share This Page