Vault adding, removing, checking balance

Discussion in 'Plugin Development' started by MaxFireIce, Feb 15, 2017.

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

    MaxFireIce

    So I have created a loop that finds the player specified by args[2] off of the current OnlinePlayers.
    I wanted to use the following to add to, remove from, and check balance but they were deprecated:
    Code:java
    1. econ.getBalance(player.getName());
    2. econ.withdrawPlayer(player.getName(), Integer.parseInt(args[2]));
    3. econ.depositPlayer(player.getName(), Integer.parseInt(args[2]));


    The only working function I could use accepted an OfflinePlayer object so I simply removed the .getName() off of the player objects and I got no errors, however, whenever I try to check, add to or remove from balance it doesn't do anything and I believe that the OfflinePlayer parameter is the culprit. If it's not, please let me know what the real culprit is and I may be able to figure it out :p. If you need any other code that I'm using just ask ;).
     
  2. Offline

    Mathias Eklund

    Just do
    getBalance(player);
    withdrawPlayer(player);
    depositPlayer(player);

    Should work with that.
     
  3. Offline

    MaxFireIce

    So I am working on my economy plugin and I am trying to link it into Vault, which I did successfully. However, when I try to use the commands I set to check balance, pay, etc. It doesn't throw any errors at me, but at the same time, it doesn't do anything either.

    Originally, I wanted to use these to get, add to, and remove from balances based off of my args[2]:
    Code:java
    1. econ.withdrawPlayer(player.getName(), Integer.parseInt(args[2]);
    2. econ.depositPlayer(player.getName(), Integer.parseInt(args[2]));
    3. econ.getBalance(player.getName());


    Unfortunately, all of these were deprecated so I tried using the only one that wasn't that accepted an OfflinePlayer object as a parameter. I made this loop:
    Code:java
    1. Collection<? extends Player> players = Bukkit.getServer().getOnlinePlayers();
    2. Player target = null;
    3. for (Player p : players) {
    4. if (p.getName() == args[1]) {
    5. target = p;
    6. break;
    7. }
    8. }


    To find the target player based off of args[1] and putting that in as my target object, without the .getName() part. When I get into the game and type commands in the console and as a player, nothing happens. Nothing happens when I'm passing in the sender as a player object either. Again, no errors, but nothing happens and I think having to pass in an OfflinePlayer object is the culprit. (If it isn't, please let me know ;) .) If you need any extra code that I'm using, just ask :D. Thanks Bukkiteers!
     
  4. Offline

    timtower Administrator Administrator Moderator

    Merged threads
     
  5. Offline

    MaxFireIce

    @timtower where did my old one go XD I couldn't find it, which is why I made a second XD.
    @Mathias Eklund nope, even when trying to use the Player player = (Player) sender; after checking instance doesn't do anything.

    EDIT: Ok I found the error and it was because it isn't finding Vault. Im using this to hook in but to no avail:
    Code:java
    1.  
    2. @Override
    3. public void onEnable() {
    4. if (!setupEconomy()) {
    5. log.severe(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
    6. getServer().getPluginManager().disablePlugin(this);
    7. return;
    8. }
    9.  
    10. setupEconomy();
    11. setupChat();
    12. setupPermissions();
    13. }
    14.  
    15. private boolean setupEconomy() {
    16. if (getServer().getPluginManager().getPlugin("Vault") == null) {
    17. return false;
    18. }
    19. RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    20. if (rsp == null) {
    21. return false;
    22. }
    23. econ = rsp.getProvider();
    24. return econ != null;
    25. }


    The error is coming from the registration of the economy.class thing. I imported vault's economy.class and used that. Is there something im missing?
     
    Last edited: Feb 16, 2017
Thread Status:
Not open for further replies.

Share This Page