Iconomy6 - Vaul - Hook

Discussion in 'Plugin Development' started by Phibedy, Feb 21, 2012.

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

    Phibedy

    Hi, I am trying to Hook Vault/Icon6 but I just dont get it, even if I copy the code from github, it just doesn´t work, that´s why it would be great if someone would put all needed code in here:
    Sry - Spellingmistake in the headline -> Vault
    Code:
    package me.phibedy.tl;
     
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
     
    public class test extends JavaPlugin {
     
        @Override
        public void onDisable() {
     
            System.out.println("test disabled!");
     
        }
     
        @Override
        public void onEnable() {
     
            System.out.println("test enable!");
     
     
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
     
     
     
            if (sender instanceof Player) {
               
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("pay")) {
            player.sendMessage("You got 5");
            // Now I want to give 5 money to the user icon account.
            }
            }
            return true;
        }
    }
    It´s just a test-plugin to understand Vault.

    I already read this thread,
    http://forums.bukkit.org/threads/iconomy-6-celtic-api.45122/#post-975651
    but I don´t know what I am doing wrong.

    best regards Phibedy
     
  2. Offline

    number1_Master

    Wouldn't you use Vault? I might of misread.
     
  3. Offline

    Sleaker

    Doesn't look like your code has any of the vault stuff in it that it would need. You need to setup the Vault hook (getting the registered service from the service manager) before you can do anything at all. The details on both the github page and the dev.bukkit.org page detail very specifically how to do this. Since you have no code yet, I can't tell you where you're going wrong.
     
  4. Offline

    Phibedy

    That´s like I think it should look like.

    Code:
    package me.phibedy.tl;
     
     
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
     
    //Vault
     
    import java.util.logging.Level; //It tells me that I need this?
     
    import java.util.logging.Logger;
     
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
     
     
    public class test extends JavaPlugin {
     
        private static final Logger log = Logger.getLogger("Minecraft");
        public static Economy econ = null;
     
        @Override
        public void onDisable() {
            System.out.println("test disabled!");
            log.info(Level.INFO, String.format("[%s] Disabled Version %s", getDescription().getName(), getDescription().getVersion()));
        } //info. is underlined
         
     
     
        @Override
        public void onEnable() {
            System.out.println("test enable!");
                if (!setupEconomy() ) {
                    log.info(Level.SEVERE, String.format("[%s] - Disabled due to no Vault dependency found!", getDescription().getName()));
                    getServer().getPluginManager().disablePlugin(this);
                    return;
                }
            }
     
          //After Dis/En
     
        private boolean setupEconomy() {
            if (getServer().getPluginManager().getPlugin("Vault") == null) {
                return false;
            }
            RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
            //RegisteredServiceProvider underlined
            if (rsp == null) {
                return false;
            }
            econ = rsp.getProvider();
            return econ != null;
        }
     
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
     
         
            if (sender instanceof Player) {
                     
            Player player = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("pay")) {
            player.sendMessage("You got 5");
            // Now I want to give 5 money to the user icon account.
            econ.depositPlayer(player.getName(), 5);
            }
            }
            return true;
        }
    }
    
     
  5. Offline

    Sleaker

    econ.depositPlayer(player.getName(), 1.05);

    will give 1.05 money to the user. depending on your currency you should be giving them either 5, or .05
     
  6. Offline

    Phibedy

    Sry just forgot to edit it,
    my problems are the underlined thinks like "info"; "RegisteredServiceProvider" etc
     
  7. Offline

    Sleaker

    You need to download and compile against Vault, just like you would bukkit.
     
  8. Offline

    Phibedy

    Yes, Vault is with bukkit in my build path.
    I was able to add one more import, but ...info... says "The method info(String) in the type Logger is not applicable for the arguments (Level, String)" what is missing? It tells me to remove "Level.INFO".
    My imports:

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.RegisteredServiceProvider;
    import org.bukkit.plugin.java.JavaPlugin;
    //Vault
    import java.util.logging.Level;
    import net.milkbowl.vault.Vault;
    import java.util.logging.Logger;
    import net.milkbowl.vault.economy.Economy;
    import net.milkbowl.vault.economy.EconomyResponse;
     
  9. when you call the function log.info you already tell the logger that this will be an info. You don't need to give the level since you already said it's info.
     
  10. Offline

    Phibedy

    I ´ve already removed it and it works, don´t know why it is in the example plugin of vault.
    Thx for support :)
     
  11. Offline

    Sleaker

    the Vault example has some logging stuff that was from another example and assumes you understand the Logger class. The RegisteredServiceProvider class is in bukkit, and shouldn't be that hard to find.
     
Thread Status:
Not open for further replies.

Share This Page