Help with scoreboard...

Discussion in 'Plugin Development' started by sgavster, Sep 8, 2013.

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

    sgavster

    Hi everyone, I'm making minigame plugins and scoreboard is useful. I've used this post a lot, but I can't figure something out. It's probably me just being a noob, but eh. I need it so I can access the scoreboard from somewhere different that that method, for example I have it set up on the '/start' but I need it at 'PlayerInteractEvent'. I'm not sure how I'd do it.. Thanks for any help in advance :)
    If you need code let me know, all the code is is what that post had, so it's nothing special!
     
  2. In this case, you need global variables.
    They are actually pretty "bad" but you need to use them sometimes (Why they are bad? Read here)

    Example:
    Code:java
    1. public class ScoreboardHandler
    2. {
    3. private static ScoreboardHandler instance = new ScoreboardHandler()
    4.  
    5. public static ScoreboardHandler getInstance()
    6. {
    7. return instance;
    8. }
    9. public void setScoreboard(Player p)
    10. {
    11. //blla
    12. }
    13. }


    Now you can call ScoreboardHandler.getInstance().setScoreboard(p) from anywhere

    Hope i could help
     
  3. Offline

    sgavster

  4. Offline

    Squid_Boss

    sgavster You could do a new class, or just create a method in your main class.
     
  5. Offline

    sgavster

    Johnny Crazy This may be a stupid question, but what do I put in the //blla?
    Do I put what I do to make the scoreboard or something else?
     
  6. Depends on what you want. But yes, you put the Code for the Scoreboard in it

    sgavster
     
  7. Offline

    sgavster

    Johnny Crazy I did this:
    Code:
        public static class ScoreboardHandler
        {
            private static ScoreboardHandler instance = new ScoreboardHandler();
     
            public static ScoreboardHandler getInstance()
            {
                return instance;
            }
            public void setScoreboard(Player p)
            {
                ScoreboardManager manager = Bukkit.getScoreboardManager();
                Scoreboard board = manager.getNewScoreboard();
                Team red = board.registerNewTeam("Red Team");
                Team blue = board.registerNewTeam("Blue Team");
                red.setPrefix(ChatColor.DARK_RED + "Red Team");
                blue.setPrefix(ChatColor.DARK_BLUE + "Blue Team");
                red.setSuffix(ChatColor.DARK_RED + "[Red]");
                blue.setSuffix(ChatColor.DARK_BLUE + "[Blue]");
                red.setDisplayName(ChatColor.DARK_RED + "Red Team");
                blue.setDisplayName(ChatColor.DARK_BLUE + "Blue Team");
                Objective objective = board.registerNewObjective("Team Scores", "dummy");
                objective.setDisplaySlot(DisplaySlot.SIDEBAR);
                objective.setDisplayName(ChatColor.GOLD + "Team Scores");
                Score r = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.DARK_RED + "Red Team:"));
                Score b = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.DARK_BLUE + "Blue Team:"));
                r.setScore(1);
                b.setScore(1);
                r.setScore(0);
                b.setScore(0);
            }
        }
    But there's no way I can set the score for players of r and b.. is there any way to do that? :/
     
  8. You must set the Scoreboard, and let the player join a team

    red.addPlayer(p) //same for blue,
    p.setScoreboard(board)
     
  9. Offline

    sgavster

    Johnny Crazy But how do I do it through another class? I need to set the score also
    Like
    r.setScore(score);
    I can't do any of that
     
  10. Offline

    sgavster

    bump..
    Still can't figure out how to do this through classes..
    I have this..
    Code:java
    1.  
    2. public static SimplyPaintball instance;
    3.  
    4. public Scoreboard board;
    5. public Team red;
    6. public Team blue;
    7. public Score re;
    8. public Score bl;
    9. public Objective objective;
    10.  
    11. private String sp = ChatColor.DARK_AQUA + "[" + ChatColor.GOLD + "Simply" + ChatColor.BLUE + "Paintball" + ChatColor.DARK_AQUA + "]";
    12. private String blank = " ";
    13.  
    14. private final AlwaysArmor AAListener = new AlwaysArmor(this);
    15. private final GunHandler GHListener = new GunHandler(this);
    16. private final SnowballHitHandler SHHListener = new SnowballHitHandler(this);
    17. private final SnowballThrowCancel STCListener = new SnowballThrowCancel(this);
    18. private final DeathHandler DHListener = new DeathHandler(this);
    19.  
    20. public ArrayList<String> in = new ArrayList<String>();
    21. public ArrayList<String> r = new ArrayList<String>();
    22. public ArrayList<String> b = new ArrayList<String>();
    23. public ArrayList<String> playing = new ArrayList<String>();
    24. public ArrayList<String> countdown = new ArrayList<String>();
    25. public ArrayList<String> cooldown = new ArrayList<String>();
    26. public ArrayList<String> deathcooldown = new ArrayList<String>();
    27.  
    28. public static final SimplyPaintball getInstance()
    29. {
    30. return instance;
    31. }
    32.  
    33. public static class ScoreboardHandler
    34. {
    35. private static ScoreboardHandler instance = new ScoreboardHandler();
    36.  
    37. public static ScoreboardHandler getInstance()
    38. {
    39. return instance;
    40. }
    41. public void setScoreboard(Player p)
    42. {
    43. ScoreboardManager manager = Bukkit.getScoreboardManager();
    44. Scoreboard board = manager.getNewScoreboard();
    45. Team red = board.registerNewTeam("Red Team");
    46. Team blue = board.registerNewTeam("Blue Team");
    47. red.setPrefix(ChatColor.DARK_RED + "Red Team");
    48. blue.setPrefix(ChatColor.DARK_BLUE + "Blue Team");
    49. red.setSuffix(ChatColor.DARK_RED + "[Red]");
    50. blue.setSuffix(ChatColor.DARK_BLUE + "[Blue]");
    51. red.setDisplayName(ChatColor.DARK_RED + "Red Team");
    52. blue.setDisplayName(ChatColor.DARK_BLUE + "Blue Team");
    53. Objective objective = board.registerNewObjective("Team Scores", "dummy");
    54. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    55. objective.setDisplayName(ChatColor.GOLD + "Team Scores");
    56. Score re = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.DARK_RED + "Red Team:"));
    57. Score bl = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.DARK_BLUE + "Blue Team:"));
    58. red.addPlayer(p);
    59. blue.addPlayer(p);
    60. p.setScoreboard(board);
    61. re.setScore(1);
    62. bl.setScore(1);
    63. re.setScore(0);
    64. bl.setScore(0);
    65. }
    66. }

    And I'm using this to get it, but it's an error :/
    Code:java
    1. if(SimplyPaintball.getInstance().b.contains(shooter.getName()))
    2. {
    3. SimplyPaintball.getInstance().bl.setScore(SimplyPaintball.getInstance().bl.getScore() + 1);
    4. }
    5. else if(SimplyPaintball.getInstance().r.contains(shooter.getName()))
    6. {
    7. SimplyPaintball.getInstance().re.setScore(SimplyPaintball.getInstance().re.getScore() + 1);
    8. }

    Error:
    [​IMG]

    Line #43 is
    Code:java
    1. SimplyPaintball.getInstance().re.setScore(SimplyPaintball.getInstance().re.getScore() + 1);

    And I am on the arraylist 'r'.
     
Thread Status:
Not open for further replies.

Share This Page