Implementing Vault

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

  1. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    And what exactly is the error? It's not like we can help without knowing what's wrong.
  3. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Then I get the error 'Cannot invoke amount() on the primitive type double'.
  6. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Well do you know how to edit this? I have absolutely no clue.
  8. Offline

    Digi

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Just remove the .amount ...
    If you're planing on making plugins, you should really read on basic Java :)
  9. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm taking a class =/ and this is only my second day. Give me time! You've already made three plugins.
  10. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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?
  11. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Anyone? I need this info soon.
  12. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  13. Offline

    Sleaker

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.

    This post has been edited 1 time. It was last edited by Sleaker Jul 5, 2012.
  14. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  15. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
  16. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Last time I'm bumping this. I don't want to spam these forums but I need help with this :(
  17. Offline

    EnvisionRed

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  18. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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?
  19. Offline

    EnvisionRed

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  20. Offline

    Sleaker

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.

    This post has been edited 2 times. It was last edited by Sleaker Jul 5, 2012.
  21. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Dude I'm still taking a class on java. Geez, you don't have to be so rude.
  22. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks for letting me know. I think I'm going to play around with the withdrawPlayer function.
  23. Offline

    desht

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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.
  24. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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;
        }
  25. Offline

    coldandtired

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Did the register the command in plugin.yml?
  26. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    the economy plugin uconnected to cault dont support transaction smaller than 1?
  27. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm using EssentialsEco, let me try $1 or $2.
  28. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Thanks sooooooo much that was it. :)
  29. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    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;
        }
  30. Online

    KeybordPiano459

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Solved I got rid of player.getName()

Share This Page