Hey i developing a plugin that works with signs and charges players money when they right click a sign(certain sign) and i need to how i can block the regular function of the plugin if the player doesn't have enough money. Lemme explain better with a code snippet: PHP: f(player.hasPermission("mclevelup.buy." + s.getLine(0).toLowerCase()) || player.hasPermission("mclevelup.buy.*")){ if(McLevelUp.econ.getBalance(e.getPlayer().getName()) > 0) { e.setCancelled(true); mcMMO.getPlayerProfile(player).addXPOverrideNoBonus( SkillType.valueOf(s.getLine(1).toUpperCase()), Integer.valueOf(s.getLine(2))); mcMMO.checkXp(player, SkillType.valueOf(s.getLine(1).toUpperCase())); player.sendMessage(ChatColor.GREEN + " Successfully Bought " + s.getLine(2) + " of " + s.getLine(1).toLowerCase() + " xp"); if(!player.hasPermission("mclevelup.bypass.charge")) { McLevelUp.econ.withdrawPlayer(e.getPlayer().getName(), Double.valueOf(s.getLine(3))); return; } } else { player.sendMessage(ChatColor.RED + " Insufficient funds"); } } else { player.sendMessage(ChatColor.RED + "You dont have permission for " + s.getLine(1).toLowerCase() + " signs"); }
For examples check this page (scroll down!) https://github.com/MilkBowl/Vault Getting the balance of a player: vault.getEconomy().getBalance(player.getName()).amount
Yeah i know but with essentials economy, it still lets you buy stuff when you shouldn't be able to be cause vault doesn't go in negatives.
You can add a check for this: Code: if(balance > cost) { balance -= cost; // And set the balance back to Vault } else { player.sendMessage("You don't have enough money!"); }
It only lets you go negative because Essentials allows Loans. It wont let your account go negative if you turn off loans in essentials.
Yeah thats what i was thinking this morning in school. Sleaker I know but i wasn't op'd when i tried that.