Economy (Money) stats on scoreboard

Discussion in 'Plugin Development' started by AppleMen, Oct 21, 2013.

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

    AppleMen

    Hello,

    I am trying to implement the money status in a exiting plugin. I already got this:
    Code:java
    1. private void setupEconomy() {
    2. RegisteredServiceProvider<Economy> chatProvider = getServer().getServicesManager().getRegistration(Economy.class);
    3. if (chatProvider != null) {
    4. economy = chatProvider.getProvider();
    5. }
    6. }
    7. private void setupScoreboard() {
    8. objective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("skywars");
    9. if (objective == null) {
    10. objective = Bukkit.getScoreboardManager().getMainScoreboard().registerNewObjective("skywars", "dummy");
    11. }
    12. objective.setDisplayName("\2476\247lSkyWars");
    13. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    14. updateScoreboard();
    15. }
    16.  
    17. public void updateScoreboard() {
    18. objective.getScore(Bukkit.getOfflinePlayer("\2479Online")).setScore(Bukkit.getOnlinePlayers().length);
    19. }


    How can I implement the money status under:
    Code:java
    1. objective.getScore(Bukkit.getOfflinePlayer("\2479Online")).setScore(Bukkit.getOnlinePlayers().length);
     
  2. AppleMen
    I've never worked with Scoreboards before, but I guess you'd want something like this
    Code:java
    1. objective.getScore(Bukkit.getOfflinePlayer("Balance")).setScore(economy.getBalance(player));

    You'd need to somehow transfer a player variable in the method.
     
  3. Offline

    AppleMen

    How can i define the player then? Cause there is no variable of..

    Anyone?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  4. Offline

    blablubbabc

    If you want to show each player a different scoreboard with different, player-specific money on it, you will have to create a new scoreboard for each player. Or, if you want to display all the balances of a few players in the scoreboard for everybody, then you have to add a new score for each fo those players.
     
  5. Offline

    AppleMen

    I want it like people can see there own money (points)

    Anyone knows how?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 5, 2016
  6. Offline

    MCTutorialist

    AppleMen
    You need to create the variable of the player like this:
    Player player = (Player) Bukkit.getPlayer();

    So basically

    player.getBalance :D

    Hope this helped
     
  7. Offline

    AppleMen

    I got this errors now:
    Code:
    The method getPlayer(String) in the type Bukkit is not applicable for the arguments ()
    Code:
    The method getBalance(String) in the type Economy is not applicable for the arguments (Player)
     
  8. Offline

    MCTutorialist

    Did you not hook Vault or any other economy plugin into your plugin?
     
  9. Offline

    AppleMen

    I am using Vault yes.
    ( And essentials )
     
  10. Offline

    Minecrell

    AppleMen
    Where did you add the line? :confused:
     
  11. Offline

    AppleMen


    Code:java
    1. public void updateScoreboard() {
    2. Player player = (Player) Bukkit.getPlayer();
    3. objective.getScore(Bukkit.getOfflinePlayer("\2479Online")).setScore(Bukkit.getOnlinePlayers().length);
    4. objective.getScore(Bukkit.getOfflinePlayer("Balance")).setScore(economy.getBalance(player));
    5. }
     
  12. Offline

    Minecrell

    AppleMen
    Ah wait, so you only want to show the player his balance? (I thought you wanted to list the players with the most money)
     
  13. Offline

    AppleMen

    No :p, only there balance.
     
  14. Offline

    Minecrell

    AppleMen
    Well, you will have to use separate scoreboards for each player then. Because if you use one scoreboard for each player they will all have the same balance displayed. ;)
     
  15. Offline

    AppleMen

    And how can i do that?
     
  16. Offline

    Minecrell

    You need to change your setupScoreboard() method, to have a player argument. Then, instead of using the main scoreboard, create a new scoreboard with Bukkit.getScoreboardManager().getNewScoreboard(). Setup your objective like in your code above.
    Then you can update the scoreboard like this:
    Code:java
    1. public void updateScoreboard(Player player) {
    2. Scoreboard scoreboard = player.getScoreboard();
    3. Objective objective = scoreboard.getObjective("skywars");
    4.  
    5. objective.getScore(Bukkit.getOfflinePlayer("\2479Online")).setScore(Bukkit.getOnlinePlayers().length);
    6. objective.getScore(Bukkit.getOfflinePlayer("Balance")).setScore((int) economy.getBalance(player.getName()));
    7. }

    Edit: Make sure setting the player's scoreboard with player.setScoreboard(scoreboard) in the setupScoreboard() method before calling updateScoreboard()!
     
  17. Offline

    AppleMen

    I kinda have it,

    Only this error on player.setScoreboard(scoreboard)
    The method updateScoreboard(Player) in the type SkyWars is not applicable for the arguments ()
     
  18. Offline

    Minecrell

    You need to use updateScoreboard(player) instead of updateScoreboard() ;)
     
  19. Offline

    AppleMen

    player cannot be resolved to a variable
     
  20. Offline

    Minecrell

    Can you post your setupScoreboard method here?
     
  21. Offline

    AppleMen


    Code:java
    1. private void setupScoreboard() {
    2. objective = Bukkit.getScoreboardManager().getMainScoreboard().getObjective("skywars");
    3. if (objective == null) {
    4. objective = Bukkit.getScoreboardManager().getMainScoreboard().registerNewObjective("skywars", "dummy");
    5. }
    6. objective.setDisplayName("\2476\247lSkyWars \247a\247lServer");
    7. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    8. updateScoreboard(player);
    9. }
     
  22. Offline

    Minecrell

    AppleMen
     
  23. Offline

    AppleMen

    I don't know how :(
     
  24. Offline

    Minecrell

    Do you know how to add the player argument to the method? :eek:
     
  25. Offline

    AppleMen

    Nop .

    This is not my code, i am customize it with the permissions of the maker. He told me it is possible to do.
     
  26. Offline

    Minecrell

    I think you should learn some Java... :'( Replace the method setupScoreboard method:
    Code:java
    1. private void setupScoreboard(Player player) {
    2. // Create the new Scoreboard
    3. Scoreboard scoreboard = Bukkit.getScoreboardManager().getNewScoreboard();
    4. Objective objective = scoreboard.registerNewObjective("skywars", "dummy");
    5.  
    6. objective.setDisplayName("\2476\247lSkyWars \247a\247lServer");
    7. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
    8.  
    9. player.setScoreboard(scoreboard);
    10. updateScoreboard(player);
    11. }
     
  27. Offline

    AppleMen

    I did that, now somewhere else in the code it says

    On the code:
    Code:java
    1. setupScoreboard();


    The method setupScoreboard(Player) in the type SkyWars is not applicable for the arguments ()
     
  28. Offline

    Minecrell

    AppleMen
    Where does it say that? (Post the method)
     
  29. Offline

    AppleMen

  30. Offline

    Minecrell

    AppleMen
    Okay, as of you need to set the scoreboard for every player separate, you need to call the setupScoreboard on every player yourself. So you need to add a PlayerJoinEvent and call the setupScoreboard method there.
    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. setupScoreboard(event.getPlayer());
    4. }

    If you copy this into the plugin class you need to add implements Listener behind extends JavaPlugin, then replace setupScoreboard() in the onEnable() method using this:
    Code:java
    1. Bukkit.getPluginManager().registerEvents(this, this);

    It should work now. ;)
     
Thread Status:
Not open for further replies.

Share This Page