Implementing Vault

Discussion in 'Plugin Development' started by KeybordPiano459, Jul 3, 2012.

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

    KeybordPiano459

    I need to implement vault. I used the tutorial that was provided, but I have an error. Here is my code:
    Code:
    package com.github.KeybordPiano459.vaulttest;
     
    import java.util.logging.Level;
    import java.util.logging.Logger;
     
    import net.milkbowl.vault.Vault;
    import net.milkbowl.vault.chat.Chat;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
    import net.milkbowl.vault.permission.Permission;
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class vaulttest extends JavaPlugin {
     
        private static final Logger log = Logger.getLogger("Minecraft");
        public static Economy econ = null;
        public static Permission perms = null;
        public static Chat chat = null;
     
        @Override
        public void onDisable() {
            log.info(String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
        }
     
        @Override
        public void onEnable() {
            if (!setupEconomy() ) {
                log.info(String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                getServer().getPluginManager().disablePlugin(this);
                return;
            }
            setupPermissions();
            setupChat();
        }
     
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
     
        private boolean setupChat() {
            RegisteredServiceProvider<Chat> rsp = getServer().getServicesManager().getRegistration(Chat.class);
            chat = rsp.getProvider();
            return chat != null;
        }
     
        private boolean setupPermissions() {
            RegisteredServiceProvider<Permission> rsp = getServer().getServicesManager().getRegistration(Permission.class);
            perms = rsp.getProvider();
            return perms != null;
        }
     
        public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
            if(!(sender instanceof Player)) {
                log.info("Only players are supported for this Example Plugin, but you should not do this!!!");
                return true;
            }
     
            Player player = (Player) sender;
     
            if(command.getLabel().equals("test-economy")) {
                // Lets give the player 1.05 currency (note that SOME economic plugins require rounding!
                sender.sendMessage(String.format("You have %s", econ.format(econ.getBalance(player.getName()).amount)));
                EconomyResponse r = econ.depositPlayer(player.getName(), 1.05);
                if(r.transactionSuccess()) {
                    sender.sendMessage(String.format("You were given %s and now have %s", econ.format(r.amount), econ.format(r.balance)));
                } else {
                    sender.sendMessage(String.format("An error occured: %s", r.errorMessage));
                }
                return true;
            } else if(command.getLabel().equals("test-permission")) {
                // Lets test if user has the node "example.plugin.awesome" to determine if they are awesome or just suck
                if(perms.has(player, "example.plugin.awesome")) {
                    sender.sendMessage("You are awesome!");
                } else {
                    sender.sendMessage("You suck!");
                }
                return true;
            } else {
                return false;
            }
        }
    }
    My error is under if (command.getLabel().equals("test-economy")) {, where it says (player.getName()).amount))); two lines below what I said above. Can someone help me out, I really need to hook vault into one of my plugins.
     
  2. Offline

    EnvisionRed

    And what exactly is the error? It's not like we can help without knowing what's wrong.
     
  3. Offline

    KeybordPiano459

    Sorry, the error is 'amount cannot be resolved or is not a field'. Also, if this helps, I'm running Eclipse Juno on a Mac 64-Bit.
     
  4. You're asking the code for the "amount" variable, which it couldn't find, I belive you wanted to use amount() which is a method.
     
  5. Offline

    KeybordPiano459

    Then I get the error 'Cannot invoke amount() on the primitive type double'.
     
  6. The econ.getBalance(player.getName()) returns a double, you don't need to use other methods on it since it's already a value you can use.

    But I notice th exact code in that tutorial, it should be edited beacuse it's invalid :}
     
  7. Offline

    KeybordPiano459

    Well do you know how to edit this? I have absolutely no clue.
     
  8. Just remove the .amount ...
    If you're planing on making plugins, you should really read on basic Java :)
     
  9. Offline

    KeybordPiano459

    I'm taking a class =/ and this is only my second day. Give me time! You've already made three plugins.

    Just out of curiosity, is there a page somewhere on the internet that shows me how to make a command cost vault money to use?

    Anyone? I need this info soon.

    Bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  10. Offline

    Sleaker

    http://mythcraft.dyndns.org/javadoc/vault - it's linked from the overview page of Vault. I realize there may be issues on the github help page, as it was updated, and hasn't had a full code check, but if you take a couple seconds to actually look at what your IDE tells you about the Economy class you should be able to deduce what is going on with little effort.
     
  11. Offline

    KeybordPiano459

    I don't think that helped much. I just want to make it so that when a person enters a command (/example) they get charged money on their iconomy, essentialseco, or whatever other economy account they have.

    Bump...

    Last time I'm bumping this. I don't want to spam these forums but I need help with this :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  12. Offline

    EnvisionRed

    You realize that http://mythcraft.dyndns.org/javadoc/vault/ is THE javadoc for vault and contains all the information you could possibly ever want on the vault api. If you don't want to take the time just to look for what you need, then yes, you are spamming these forums.
     
  13. Offline

    KeybordPiano459

    Im pretty sure that the function I would use is 'bankWithdraw'. Only because I'm a java noob and not too sure how to use these functions, I'm just going to ask you, how do I use this function?
     
  14. Offline

    EnvisionRed

    Same way you use any method. You really need to learn some basic java before coming to bukkit, otherwise the best you can do is copy off of someone else's code.
     
  15. Offline

    Sleaker

    bankWithdraw is only for banks. not player accounts. and sorry, it's a lower-case v for vault. Forgot that currently it's case-sensitive cause I haven't aliased it in my apache configs.
     
  16. Offline

    KeybordPiano459

    Dude I'm still taking a class on java. Geez, you don't have to be so rude.

    Thanks for letting me know. I think I'm going to play around with the withdrawPlayer function.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
    themammoth likes this.
  17. Offline

    desht

    I don't think he was being rude at all. It's great that you're learning Java, and I wish you every success with that, but you need to understand: this forum is for discussing development of Bukkit plugins in Java. It's not a forum to teach you about Java basics - for that, you have your class, you have web tutorials, you have books, and you have the source of many existing plugins to refer to.

    Like it or not, a certain amount of Java knowledge needs to be assumed before you start writing Bukkit plugins.
     
    ferrybig likes this.
  18. Offline

    KeybordPiano459

    Does anyone know why this isn't working?
    Code:
    if(cmd.getName().equalsIgnoreCase("test")) {
            sender.sendMessage(getConfig().getString("test"));
            EconomyResponse r = econ.withdrawPlayer(player.getName(), 0.50);
            if(r.transactionSuccess()) {
                sender.sendMessage("$0.50 has been withdrawn from your account.");
            } else {
                sender.sendMessage("An error occured: %s");
            }
            return true;
        } else {
            return false;
        }
     
  19. Offline

    coldandtired

    Did the register the command in plugin.yml?
     
  20. the economy plugin uconnected to cault dont support transaction smaller than 1?
     
  21. Offline

    KeybordPiano459

    I'm using EssentialsEco, let me try $1 or $2.

    Thanks sooooooo much that was it. :)

    When I use this I get an error (The method withdrawPlayer(String, double) in the type Economy is not applicable for the arguments (String, String)). Does anyone know why and how to fix it?
    Code:
    Player player = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
            sender.sendMessage(getConfig().getString("test"));
            EconomyResponse r = econ.withdrawPlayer(player.getName(), getConfig().getString("cost"));
            if(r.transactionSuccess()) {
                sender.sendMessage("$1 has been withdrawn from your account.");
            } else {
                sender.sendMessage("An error occured: %s");
            }
            return true;
        } else {
            return false;
        }
    Solved I got rid of player.getName()

    Wait no then it doesn't withdraw any money. Anyone? Help?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  22. Offline

    chaseoes

    You need to give it a double and not a string, from what I saw from your error:
    Code:
    Player player = (Player) sender;
        if(cmd.getName().equalsIgnoreCase("test")) {
            sender.sendMessage(getConfig().getString("test"));
            EconomyResponse r = econ.withdrawPlayer(player.getName(), getConfig().getDouble("cost"));
            if(r.transactionSuccess()) {
                sender.sendMessage("$1 has been withdrawn from your account.");
            } else {
                sender.sendMessage("An error occured: %s");
            }
            return true;
        } else {
            return false;
        }
     
  23. Offline

    KeybordPiano459

    Thanks
     
Thread Status:
Not open for further replies.

Share This Page