Getting Player's Balance on Item Name

Discussion in 'Plugin Development' started by Jamser52, Apr 3, 2015.

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

    Jamser52

    I'm trying to use vault to get a player's balance and display it on an item name.

    However I d0n't know how to retrieve the player. Please help.

    Code:
     ItemStack Balance = new ItemStack(Material.GOLD_INGOT); {
    
            ItemMeta BalanceMeta = Balance.getItemMeta();
            ArrayList<String> balance = new ArrayList<String> ();
            BalanceMeta.setDisplayName(ChatColor.GOLD+ "Balance: " + ChatColor.GREEN + plugin.economy.getBalance(player.getName()));
            BalanceMeta.setLore(balance);
            Balance.setItemMeta(BalanceMeta);
        }
     
  2. Offline

    nverdier

  3. Offline

    Jamser52

    I want to get the player and retrieve their balance using vault..
     
  4. Offline

    nverdier

  5. Offline

    Jamser52

    Yeah but how do I get the player? @nverdier
     
  6. Offline

    justin_393

    Well, you would need some type of a method.
    public void myMethod(String name) {
    Player p = name;
    //your code here
    }
     
  7. Offline

    Jamser52

    I know @justin_393 but what's a good method of getting the player for this situation.
     
  8. Offline

    justin_393

    Depends on how you want to set your plugin up. There are many different ways you can do this.
     
  9. Offline

    Jamser52

  10. Offline

    justin_393

    @Jamser52
    you could check if the player is holding the item, you could give it on join, when they die, when they respawn, when they move. You just have to pick according to what you're trying to do.
     
  11. Offline

    Jamser52

    So basically this command is, you type /tutorial and it opens an interface. I'm trying to have them able to hover over an item to view their balance, how do I check for that? @justin_393
     
  12. Offline

    justin_393

    well, if you use the in-built onCommand method you can just use sender.getName() or cast it to a player if you wish, but check that it's a player before you cast.
    if (sender instanceof Player ){
    Player p = (Player) sender;
    //your code here
    }
     
  13. Offline

    Jamser52

  14. Offline

    justin_393

    @Jamser52
    Yeah, just open your GUI on a certain command and then when you hover over the item set the player's name and balance based off of the player who opened the inventory.
     
  15. Offline

    Jamser52

    So I opened the GUI and I clicked an item to open another inventory without a command. That's my current issue.
     
  16. Offline

    WeeSkilz

    Use the InventoryClickEvent with #getPlayer()
     
Thread Status:
Not open for further replies.

Share This Page