Solved Vault - Giving Players money on an Event

Discussion in 'Plugin Development' started by Drkmaster83, Oct 7, 2012.

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

    Drkmaster83

    I'm attempting to give players an amount (using Vault) that is listed in the configuration when a certain event (let's say a BlockBreakEvent) occurs. It also requires that the player be in a certain HashMap, which is set to add them into it when they use a certain command.

    I've listed the kinds of blocks that will allow the money to be given, all other blocks won't. But, it refuses to give the player money, even though they're in the HashMap. Then again, it also doesn't generate the config if there isn't one. Has the configuration coding changed?

    Yes, I have registered the events in the onEnable(), and yes, I have EventHandler on all the events in my Listener class. No errors occur when the event occurs, but when I check my money, there's no change. The economy system I'm getting Vault to use is iConomy. Eclipse isn't notifying me of any errors, other than a line breakpoint (blue dot on the side of eclipse, next to line numbers)...

    I've implemented Vault using the code from the tutorial, and no errors occured there. Just to make sure, I made the event send a player a message when they did it. It worked. The method from Vault I'm using to give the player money is depositPlayer(String, int). I've made the Player in the event a string with Player.getName() and that passes the method. The int, as I said before, is in the config, which I call with plugin.getConfig().getInt(<string name));. I've made sure that all the if statements have else's before them if they aren't the first if statement...

    Would someone PLEASE tell me what I'm doing wrong!?!??! :(

    Bump? :'(

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

    travja

    public Economy econ = null;
    //onEnable
    if (setupEconomy()) {
    log.info(ChatColor.AQUA + "Found Vault! Hooking in for economy!");
    }
    //Event
    plugin.econ.depositPlayer(p.getName(), 100);
    Should work...
     
  3. Offline

    Drkmaster83

    That's exactly what I'm doing. Does not work.
     
  4. Offline

    Sleaker

    Do you have some code that we can see to help?
     
  5. Offline

    Drkmaster83

    I'm anxious, one moment. I'll post it in ~2-3 min.

    Code:
    //OnEnable() method:
    @Override
        public void onEnable()
        {
            PluginManager PM = getServer().getPluginManager();
            PM.registerEvents(MainClassListener, this);
            File Config = new File(getDataFolder(), "/config.yml");
            if(!Config.exists())
            {
                try
                {
                    log.info(PluginPrefix + "No Configuration File was found; Attempting to generate a new one for you...");
                    this.saveDefaultConfig();
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                    log.severe("An exception occured while trying to generate the configuration.");
                }
            }
            this.reloadConfig();
            this.getCommand("HidingMyPluginName").setExecutor(PluginCommandExecutor);
            this.getCommand("troll").setExecutor(PluginCommandExecutor);
            this.getCommand("Blah").setExecutor(PluginCommandExecutor);
            this.getCommand("BRO").setExecutor(ClassSystemCommandExecutor);
            this.getCommand("ErMerGerd").setExecutor(PluginCommandExecutor);
            this.getCommand("Sorry").setExecutor(PluginCommandExecutor);
            this.setupEconomy();
            PDF = this.getDescription();
            log.info(PluginPrefix + PDF.getName() + " v" + PDF.getVersion() + " has been enabled!");
        }
    //BlockBreakMethod:
    @EventHandler (priority = EventPriority.HIGHEST)
        public void onPlayerBlockBreak(BlockBreakEvent event)
        {
            Block brokenBlock = event.getBlock();
            Player blockBreaker = event.getPlayer();
            String blockBreakerName = blockBreaker.getName();
            if(plugin.Miners.containsKey(blockBreakerName) && brokenBlock.getType() == Material.STONE || brokenBlock.getType() == Material.COAL_ORE
                        || brokenBlock.getType() == Material.IRON_ORE || brokenBlock.getType() == Material.ENDER_STONE
                        || brokenBlock.getType() == Material.GOLD_ORE || brokenBlock.getType() == Material.DIAMOND_ORE
                        || brokenBlock.getType() == Material.REDSTONE_ORE || brokenBlock.getType() == Material.EMERALD_ORE
                        && blockBreaker.getItemInHand() == new ItemStack(Material.WOOD_PICKAXE)
                        || blockBreaker.getItemInHand() == new ItemStack(Material.STONE_PICKAXE)
                        || blockBreaker.getItemInHand() == new ItemStack(Material.IRON_PICKAXE)
                        || blockBreaker.getItemInHand() == new ItemStack(Material.GOLD_PICKAXE)
                        || blockBreaker.getItemInHand() == new ItemStack(Material.DIAMOND_PICKAXE))
            {
                MainClass.Economy.depositPlayer(blockBreakerName, plugin.getConfig().getInt("miners-pay"));
            }
            else if(plugin.Farmers.containsKey(blockBreakerName) && brokenBlock.getType() == Material.CROPS || brokenBlock.getType() == Material.SUGAR_CANE_BLOCK
                    && blockBreaker.getItemInHand() == new ItemStack(Material.WOOD_HOE)
                    || blockBreaker.getItemInHand() == new ItemStack(Material.STONE_HOE)
                    || blockBreaker.getItemInHand() == new ItemStack(Material.IRON_HOE)
                    || blockBreaker.getItemInHand() == new ItemStack(Material.GOLD_HOE)
                    || blockBreaker.getItemInHand() == new ItemStack(Material.DIAMOND_HOE))
            {
                MainClass.Economy.depositPlayer(blockBreakerName, plugin.getConfig().getInt("farmers-pay"));
            }
            else if(plugin.Woodcutters.containsKey(blockBreakerName) && brokenBlock.getType() == Material.LOG)
            {
                MainClass.Economy.depositPlayer(blockBreakerName, plugin.getConfig().getInt("woodcutters-pay"));
            }
        }
    
    Before you even say it, Yes, I know my code format is weird. I hate how it is
    Code:
    public void (){
     
    }
    I like it when it is
    Code:
    public void ()
    {
     
    }
    
    It just makes more sense to me.
    Note: The config.yml file also isn't generating.

    EDIT: "Miners" is a HashMap that they are added to when they execute one of the command in the onEnable(). So are Woodcutters and Farmers. Also, instead of calling it "econ", I called it "Economy". I'm really obsessed with perfection like that. Nothing's perfect, however.

    ChatColor works in the Console? I thought it just gave a weird "S" looking symbol.

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

    Sleaker

    Drkmaster83 - instead of depositing I'd output the values you're pulling from your config to make sure they are actually what you think they are.

    Also, it's very odd to use Uppercase first-letter for variables Economy should probably be renamed economy to prevent confusion between a class and a variable, I don't think I've ever seen any coding style guideline ever recommend using uppercase naming for a variable (unless it's a constant in which case they recommend all uppercase)
     
  7. Offline

    Drkmaster83

    There probably was never a guideline for it, I just kind of did it. I'll keep that in mind, though.

    How so? You mean, make them an int and then refer to that int?
    Code:
    Integer int1 = plugin.getConfig().getInt("miners-pay");
    MainClass.economy.depositPlayer(blockBreakerName, int1);
    // Etc.?
    
    Thanks so much guys, It works now! Sleaker, I thank you greatly, as you may have saved my life on many future projects. Again, I just can't say how greatful I am. But thank you all! XD

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

    Sleaker

    hmm that's odd, I meant more to output the value to the console that you're trying to get from your config. You shouldn't need to create an intenger (or int) to get the value before you pass it to vault.

    Doing something like plugin.getLogger().log(Logger.INFO, "Attempting to deposit: " + int1);

    so you can see what you have in your configuration.

    What actually ended up being the issue?
     
  9. Offline

    Drkmaster83

    The Economy conflicting with a class name, I believe.
    I didn't use the Integer creation at all, and the grabbing from the config still works. Of course, the int can't be 2.5 or anything. Also, I don't want the plugin to spam. The event will occur often, and we don't need this to spam the console.
     
  10. Offline

    Sleaker

    Right that was just a suggestion for testing. Cool though, glad you got it working.
     
Thread Status:
Not open for further replies.

Share This Page