Scoreboard Balance Problem

Discussion in 'Plugin Development' started by lelguy, Jul 1, 2015.

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

    lelguy

    Hey guys, I´ve tried now 3 hours..... the scoreboard works perfectly.. only one problem
    I cant get it to show the balance of the player via Vault
    I just dont get it..

    Heres my code:

    Code:
     @EventHandler
      public void onJoin(PlayerJoinEvent e) {
          Player p = e.getPlayer();
      
         
          ScoreboardManager sm = Bukkit.getServer().getScoreboardManager();
          Scoreboard board = sm.getNewScoreboard();
          Objective score = board.registerNewObjective("aaa", "bbb");
          score.setDisplayName("§aScoreboard");
          score.setDisplaySlot(DisplaySlot.SIDEBAR);
        
          score.getScore("Team:").setScore(7);      
          score.getScore(getClanTag(p.getPlayer())).setScore(6);    
          score.getScore("§a").setScore(5);  
          score.getScore("Balance:").setScore(4);
          score.getScore(econ.getBalance(p.getName())).setScore(3);   <===== PROBLEM!!!!!!
    
        
          p.setScoreboard(board);
    
        
      
    
      }
    
     
  2. Offline

    WesJD

    I'm pretty sure Vault isn't going to be using player names to store balances.
     
  3. What happens? What's this "problem"? Does it always show 0? Also what WesJD said above, Economy#getBalance(String) is deprecated, and you should use Economy#getBalance(OfflinePlayer).

    I'm not sure if getBalance() checks if the player even has an account, so you might want to do:
    Code:
    score.getScore(econ.hasAccount(p) ? econ.getBalance(p) : 0).setScore(3);
    
    If you're getting a NPE, that means you haven't set up the economy instance properly.
     
  4. Offline

    lelguy

    @KingFaris11 Thanks for the quick reply ^_^
    I tried this code but I still get an error "The method getScore(OfflinePlayer) in the type Objective is not applicable for the arguments (double)", its the same one I got before
     
  5. @lelguy It's because your economy is a double. Just add an empty string to it.

    Code:
    score.getScore(econ.getBalance(p.getName()) + "").setScore(3);
     
  6. Offline

    lelguy

    @CodePlaysMinecraft ok. Well this doesnt give me an error but still doesnt asy the balance.. so yeah xD
     
  7. Offline

    Denziz

    I did it like this in my scoreboard plugin, works fine.

    Code:
    score.setScore((int)Math.round(econ.getBalance(player.getName())));
    You could try it out and see if it works :D
     
  8. Offline

    lelguy

  9. Offline

    Denziz

    @lelguy What does it say if you hover over the red line?
     
  10. @lelguy Something like this should work...
    Code:
    int balance = (int) econ.getBalance(player.getName());
    
    score.getScore("Your balance is:").setScore(balance);
    That is if you want to set the actual score to their balance.
    Code:
    int balance = (int) econ.getBalance(player.getName());
    
    score.getScore(balance + "").setScore(3);
    That would be if you wanted the line to be the balance.
     
    Last edited: Jul 2, 2015
  11. Offline

    lelguy

  12. Offline

    Denziz

    @lelguy Hmm, I copied your code and it says the same thing for me as well :D

    Well, here is how I have done it.

    Test it and see if it works.

    Code:
    public class PlayerScoreboard extends JavaPlugin implements Listener{
    
    public ScoreboardManager manager = Bukkit.getScoreboardManager();
    
    public void onEnable(){
    
        this.manager = Bukkit.getScoreboardManager();
    
    }
    
    @EventHandler
      public void onJoin(PlayerJoinEvent e) {
          Player p = e.getPlayer();
          final Scoreboard board = this.manager.getNewScoreboard();
    
          //It sets the scoreboard after 1 second.
          getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable()
            {
                public void run()
                {
                    player.setScoreboard(board);
                }
            }, 20L);
      
            final Objective o = board.registerNewObjective("test", "dummy");
            final Score score = o.getScore(Bukkit.getOfflinePlayer("§aMoney"));
            score.setScore((int)Math.round(econ.getBalance(player.getName())));
      
            o.setDisplaySlot(DisplaySlot.SIDEBAR);
            o.setDisplayName("§aScoreboard");
        }
    }
    
     
  13. Offline

    lelguy

  14. Offline

    Denziz

    @lelguy Did you register:

    Code:
    this.manager = Bukkit.getScoreboardManager();
    in your onEnable?
     
  15. As I said, use getBalance(OfflinePlayer): score.getScore(String.valueOf(econ.hasAccount(p) ? econ.getBalance(p) : 0)).setScore(3);

    If you are getting a red line, you're not using the latest Vault.
    getBalance(String) is deprecated.
     
  16. Offline

    BagduFagdu

  17. Offline

    lelguy

    @KingFaris11 I dont get any errors, but the scoreboard wont show up

    @Denziz yes I did
    @BagduFagdu like how would I do that

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
  18. @lelguy If it's deprecated then just set the line or method to deprecated. Deprecated doesn't mean it won't work, it just means it might be removed in the next version or so.
     
Thread Status:
Not open for further replies.

Share This Page