Problems with vault

Discussion in 'Plugin Development' started by Fin999888777, Oct 6, 2012.

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

    Fin999888777

    Hey, I am not able to implement the vault plugin...
    I followed this tutorial
    and now my class looks like this:
    "package me.Fin.TestValut;


    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 TestVault 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) {
    log.info("wegen kein Vault");
    return false;
    }
    RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp == null) {
    log.info("wegen kein Economy class");
    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()))));
    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;
    }
    }

    }
    "​
    and my plugin.yml looks like this:
    "depend: [Vault]
    name: TestVault
    version: 1.0
    main: me.Fin.TestValut.TestVault
    author: Fin
    website: http://www.youtube.com/debukkit
    commands:
    test-economy:
    description: Testet irgendwas
    usage: /<command>
    test-permission:
    description: Testet irgendwas
    usage: /<command>​
    "​


    but the plugin disables itself because of the economySetup method with this "if " part:
    "RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
    if (rsp == null) {
    log.info("wegen kein Economy class");
    return false;
    }"

    the variable rsp is null... I don't get what I am doing wrong I hope someone can help me :D
     
  2. do you have another vault compactable economy plugin, and is that loaded before yours?
     
  3. Offline

    Fin999888777

    nope.. does it have to?
     
Thread Status:
Not open for further replies.

Share This Page