public boolean pay(Player p) { if (!plugin.useVault) { return true; } Economy econ; RegisteredServiceProvider<Economy> rsp = plugin.getServer().getServicesManager().getRegistration(Economy.class); if (rsp == null) { return true; // No Vault found } econ = rsp.getProvider(); if (econ == null) { return true; // No Vault found } int money = plugin.warpCreatePrice; if (money == 0) { return true; } if (!econ.has(p.getName(), money)) { p.sendMessage("You do not have enough money! You need " + econ.format(money) + "!"); return false; } econ.withdrawPlayer(p.getName(), money); p.sendMessage("Withdrawing " + econ.format(money) + " from your account!"); return true; }
@Override public boolean execute() throws MissingOrIncorrectArgumentException, InsufficientPermissionException { if (errorCheck()) return true; // /xp price <amount|bank|me> String name = player.getName().toLowerCase(); // int currentXP = player.getTotalExperience(); int currentXP = Utilities.getTotalExp(player); int bankXP = XPBank.getBank().getBalance(name); int xp; EconomyResponse er; // Parse arguments if (args[1].equalsIgnoreCase("me")) xp = currentXP; else if (args[1].equalsIgnoreCase("bank")) xp = bankXP; else { try { xp = Integer.parseInt(args[1]); } catch (NumberFormatException nfe) { throw new MissingOrIncorrectArgumentException(); } } double dPrice = Properties.flatFeeDeposit + (Properties.perXPDeposit * xp); double wPrice = Properties.flatFeeWithdrawl + (Properties.perXPWithdrawl * xp); Messaging.send( player, "`pIt would cost `w" + economy.format(dPrice) + "`p to deposit `w" + xp + "`p XP."); Messaging.send( player, "`pIt would cost `w" + economy.format(wPrice) + "`p to withdraw `w" + xp + "`p XP."); return true; }
@EventHandler public void winGame(DeathSwapWinEvent event) { int payloser = getConfig().getInt("loseramount"); int paywinner = getConfig().getInt("paywinneramount"); Player loser = Bukkit.getServer().getPlayer(event.getLoser()); Player winner = Bukkit.getServer().getPlayer(event.getWinner()); String payloseroption = getConfig().getString("payloser"); if (payloseroption.equalsIgnoreCase("give")) { econ.depositPlayer(event.getLoser(), payloser); loser.sendMessage( ChatColor.YELLOW + "[" + ChatColor.GREEN + "DeathSwap Payout" + ChatColor.YELLOW + "]" + ChatColor.RED + " You've received an award of $" + payloser + " for participating in the match. Well done."); } else if (payloseroption.equalsIgnoreCase("take")) { econ.withdrawPlayer(event.getLoser(), payloser); loser.sendMessage( ChatColor.YELLOW + "[" + ChatColor.GREEN + "DeathSwap Payout" + ChatColor.YELLOW + "]" + ChatColor.RED + " Unfortunately, because you lost the last match, the amount of $" + payloser + " has been taken from your account. Better luck next time."); } if (getConfig().getBoolean("paywinner")) { econ.depositPlayer(event.getWinner(), paywinner); winner.sendMessage( "" + ChatColor.YELLOW + "[" + ChatColor.GREEN + "DeathSwap Payout" + ChatColor.YELLOW + "]" + ChatColor.RED + " You've received an award of $" + paywinner + " for winning the match. Well done."); } }
// Bank public boolean setBank(String player, String bankName) { // does we support banks? if (!economy.hasBankSupport()) return false; // check if the given bank belongs to the traders owner if (!economy.isBankOwner(bank, player).equals(ResponseType.SUCCESS)) return false; // set the bank bank = bankName; return true; }
public static void add(String name, double amount) { if (!hasEconomy()) { throw new IllegalStateException( "Tried to perform economy actions but no economy service installed!"); } if (amount > 0) { economy.depositPlayer(name, amount); } else if (amount < 0) { economy.withdrawPlayer(name, Math.abs(amount)); } }
public boolean ensureExists(String accountId) { Economy economy = this.getEconomy(); if (economy.hasAccount(accountId)) return true; if (!economy.createPlayerAccount(accountId)) return false; if (MUtil.isValidPlayerName(accountId)) return true; double balance = economy.getBalance(accountId); economy.withdrawPlayer(accountId, balance); return true; }
// depositing money public void deposit(String p, double m) { switch (type) { case OWNER: economy.depositPlayer(p, m); break; case BANK: economy.bankDeposit(bank, m); break; case NPC: money += m; break; default: break; } }
private void checkPluginVault() { if (vault != null) return; Plugin vaultCheck = pm.getPlugin("Vault"); if (vaultCheck != null && vaultCheck.isEnabled()) { vault = vaultCheck; core.log.info(core.getNameBrackets() + "found Vault plugin."); RegisteredServiceProvider<Permission> permissionProvider = core.getServer() .getServicesManager() .getRegistration(net.milkbowl.vault.permission.Permission.class); if (permissionProvider != null) { permission = permissionProvider.getProvider(); core.log.info( core.getNameBrackets() + "Reported permission provider: " + permission.getName()); } RegisteredServiceProvider<Economy> economyProvider = core.getServer() .getServicesManager() .getRegistration(net.milkbowl.vault.economy.Economy.class); if (economyProvider != null) { economy = economyProvider.getProvider(); core.log.info(core.getNameBrackets() + "Reported economy provider: " + economy.getName()); } } }
public static boolean hasBalance(String name, double balance) { if (!hasEconomy()) { throw new IllegalStateException( "Tried to perform economy actions but no economy service installed!"); } return economy.has(name, balance); }
public static Object getRubies(Player p) { int x = (int) econ.getBalance(p); if (p == null) { return null; } return x; }
public boolean withdraw(String p, double m) { switch (type) { case OWNER: return economy.withdrawPlayer(p, m).transactionSuccess(); case BANK: return economy.bankWithdraw(bank, m).transactionSuccess(); case NPC: if (money >= m) { money -= m; return true; } return false; default: return true; } }
private void infoCommand(CommandSender sender) { // Get String of Registered Economy Services String registeredEcons = null; Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class); for (RegisteredServiceProvider<Economy> econ : econs) { Economy e = econ.getProvider(); if (registeredEcons == null) { registeredEcons = e.getName(); } else { registeredEcons += ", " + e.getName(); } } // Get String of Registered Permission Services String registeredPerms = null; Collection<RegisteredServiceProvider<Permission>> perms = this.getServer().getServicesManager().getRegistrations(Permission.class); for (RegisteredServiceProvider<Permission> perm : perms) { Permission p = perm.getProvider(); if (registeredPerms == null) { registeredPerms = p.getName(); } else { registeredPerms += ", " + p.getName(); } } // Get Economy & Permission primary Services Economy econ = getServer().getServicesManager().getRegistration(Economy.class).getProvider(); Permission perm = getServer().getServicesManager().getRegistration(Permission.class).getProvider(); // Send user some info! sender.sendMessage( String.format( "[%s] Vault v%s Information", getDescription().getName(), getDescription().getVersion())); sender.sendMessage( String.format( "[%s] Economy: %s [%s]", getDescription().getName(), econ.getName(), registeredEcons)); sender.sendMessage( String.format( "[%s] Permission: %s [%s]", getDescription().getName(), perm.getName(), registeredPerms)); }
@Override public boolean move( String fromId, String toId, String byId, double amount, Collection<String> categories, Object message) { Economy economy = this.getEconomy(); // Ensure positive direction if (amount < 0) { amount *= -1; String temp = fromId; fromId = toId; toId = temp; } // Ensure the accounts exist if (fromId != null) this.ensureExists(fromId); if (toId != null) this.ensureExists(toId); // Subtract From if (fromId != null) { if (!economy.withdrawPlayer(fromId, amount).transactionSuccess()) { return false; } } // Add To if (toId != null) { if (!economy.depositPlayer(toId, amount).transactionSuccess()) { if (fromId != null) { // Undo the withdraw economy.depositPlayer(fromId, amount); } return false; } } return true; }
public void handlePayment(Player p, double i) { if (i > 0) { EconomyResponse r = econ.depositPlayer(p.getName(), i); if (r.transactionSuccess()) { p.sendMessage(ChatColor.GREEN + "You have been awarded $" + i); } else { p.sendMessage(ChatColor.RED + "PAYMENT FAILED!"); } } else if (i < 0) { i = Math.abs(i); double bal = econ.getBalance(p.getName()); if (bal < i) { i = bal; } EconomyResponse r = econ.withdrawPlayer(p.getName(), i); if (r.transactionSuccess()) { p.sendMessage(ChatColor.RED + "You have been fined $" + i); } else { p.sendMessage(ChatColor.RED + "PAYMENT FAILED!"); } } }
// Handles death related events. @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.NORMAL) public void onDeath(EntityDeathEvent event) { if (event.getEntity() instanceof Player) { Player player = (Player) event.getEntity(); // Players lose 5% of their money on death. Double loss; Double amount = econ.getBalance(player.getDisplayName()); loss = amount * 0.05; econ.withdrawPlayer(player.getDisplayName(), loss); } // Powered Creepers drop diamond when killed. if (event.getEntity() instanceof Creeper) { if (((Creeper) event.getEntity()).isPowered()) { ItemStack item = new ItemStack(Material.DIAMOND); event.getDrops().add(item); } } }
public TransactionResponse ecoPay(Player sender, String reciverName, double amount) { if (econ != null && amount > 0) { EconomyResponse withdrawResponse = econ.withdrawPlayer(sender.getName(), amount); if (withdrawResponse.transactionSuccess()) { EconomyResponse depositResponse = econ.depositPlayer(reciverName, amount); if (depositResponse.transactionSuccess()) { return new TransactionResponse(true, "Transaction success", amount); } else { return new TransactionResponse(false, depositResponse.errorMessage, 0); } } else { return new TransactionResponse(false, withdrawResponse.errorMessage, 0); } } else { if (amount > 0) return new TransactionResponse(false, "No economy plugin found", 0); else { return new TransactionResponse(false, "Transction amount is 0", amount); } } }
private void convertCommand(CommandSender sender, String[] args) { Collection<RegisteredServiceProvider<Economy>> econs = this.getServer().getServicesManager().getRegistrations(Economy.class); if (econs == null || econs.size() < 2) { sender.sendMessage("You must have at least 2 economies loaded to convert."); return; } else if (args.length != 2) { sender.sendMessage( "You must specify only the economy to convert from and the economy to convert to. (without spaces)"); return; } Economy econ1 = null; Economy econ2 = null; for (RegisteredServiceProvider<Economy> econ : econs) { String econName = econ.getProvider().getName().replace(" ", ""); if (econName.equalsIgnoreCase(args[0])) { econ1 = econ.getProvider(); } else if (econName.equalsIgnoreCase(args[1])) { econ2 = econ.getProvider(); } } if (econ1 == null) { sender.sendMessage( "Could not find " + args[0] + " loaded on the server, check your spelling"); return; } else if (econ2 == null) { sender.sendMessage( "Could not find " + args[1] + " loaded on the server, check your spelling"); return; } sender.sendMessage("This may take some time to convert, expect server lag."); for (OfflinePlayer op : Bukkit.getServer().getOfflinePlayers()) { String pName = op.getName(); if (econ1.hasAccount(pName)) { if (econ2.hasAccount(pName)) { continue; } econ2.createPlayerAccount(pName); econ2.depositPlayer(pName, econ1.getBalance(pName)); } } }
@EventHandler public void newGame(DeathSwapNewGameEvent event) { if (getConfig().getBoolean("paytoplay")) { int cost = getConfig().getInt("costtoplay"); econ.withdrawPlayer(event.getNameOne(), cost); econ.withdrawPlayer(event.getNameTwo(), cost); Player one = Bukkit.getServer().getPlayer(event.getNameOne()); Player two = Bukkit.getServer().getPlayer(event.getNameTwo()); one.sendMessage( "" + ChatColor.YELLOW + "[" + ChatColor.GREEN + "DeathSwap Payout" + ChatColor.YELLOW + "]" + ChatColor.RED + "This game costs $" + cost + ". $" + cost + " has been taken out of your account."); two.sendMessage( "" + ChatColor.YELLOW + "[" + ChatColor.GREEN + "DeathSwap Payout" + ChatColor.YELLOW + "]" + ChatColor.RED + "This game costs $" + cost + ". $" + cost + " has been taken out of your account."); } }
// Handles selling items with left-click. @SuppressWarnings("deprecation") @EventHandler(priority = EventPriority.HIGHEST) public void sellClick(PlayerInteractEvent event) { final Player player = event.getPlayer(); // Sell Items: if (event.getAction() == Action.LEFT_CLICK_AIR || event.getAction() == Action.LEFT_CLICK_BLOCK) { for (int a = 0; a < sellingItems.size(); a++) if (sellingItems.containsKey(player.getItemInHand().getType().toString())) { // If the item is a custom or renamed item. if (player.getItemInHand().hasItemMeta()) return; String itemName = player.getItemInHand().getType().toString(); double dropPrice = Double.parseDouble(sellingItems.get(itemName).toString()); dropPrice *= player.getItemInHand().getAmount(); player.setItemInHand(new ItemStack(Material.AIR)); econ.depositPlayer(player.getDisplayName(), dropPrice); player.sendMessage(ChatColor.GREEN + "Sold " + itemName + " for: $" + dropPrice); } } }
/** Attempts to load Economy Addons */ private void loadEconomy() { // Try to load MultiCurrency if (packageExists("me.ashtheking.currency.Currency", "me.ashtheking.currency.CurrencyList")) { Economy econ = new Economy_MultiCurrency(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] MultiCurrency found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try Loading MineConomy if (packageExists("me.mjolnir.mineconomy.MineConomy")) { Economy econ = new Economy_MineConomy(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] MineConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try Loading AEco if (packageExists("org.neocraft.AEco.AEco")) { Economy econ = new Economy_AEco(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] AEco found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try Loading McMoney if (packageExists("boardinggamer.mcmoney.McMoneyAPI")) { Economy econ = new Economy_McMoney(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] McMoney found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try Loading Craftconomy if (packageExists("me.greatman.Craftconomy.Craftconomy")) { Economy econ = new Economy_Craftconomy(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] CraftConomy found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try loading eWallet if (packageExists("me.ethan.eWallet.ECO")) { Economy econ = new Economy_eWallet(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] eWallet found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try to load 3co if (packageExists("me.ic3d.eco.ECO")) { Economy econ = new Economy_3co(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] 3co found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try to load BOSEconomy if (packageExists("cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandManager")) { Economy bose6 = new Economy_BOSE6(this); sm.register(Economy.class, bose6, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] BOSEconomy6 found: %s", getDescription().getName(), bose6.isEnabled() ? "Loaded" : "Waiting")); } // Try to load BOSEconomy if (packageExists("cosine.boseconomy.BOSEconomy", "cosine.boseconomy.CommandHandler")) { Economy bose7 = new Economy_BOSE7(this); sm.register(net.milkbowl.vault.economy.Economy.class, bose7, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] BOSEconomy7 found: %s", getDescription().getName(), bose7.isEnabled() ? "Loaded" : "Waiting")); } // Try to load CurrencyCore if (packageExists("is.currency.Currency")) { Economy cCore = new Economy_CurrencyCore(this); sm.register(net.milkbowl.vault.economy.Economy.class, cCore, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] CurrencyCore found: %s", getDescription().getName(), cCore.isEnabled() ? "Loaded" : "Waiting")); } // Try to load Essentials Economy if (packageExists( "com.earth2me.essentials.api.Economy", "com.earth2me.essentials.api.NoLoanPermittedException", "com.earth2me.essentials.api.UserDoesNotExistException")) { Economy essentials = new Economy_Essentials(this); sm.register(net.milkbowl.vault.economy.Economy.class, essentials, this, ServicePriority.Low); log.info( String.format( "[%s][Economy] Essentials Economy found: %s", getDescription().getName(), essentials.isEnabled() ? "Loaded" : "Waiting")); } // Try to load iConomy 4 if (packageExists( "com.nijiko.coelho.iConomy.iConomy", "com.nijiko.coelho.iConomy.system.Account")) { Economy icon4 = new Economy_iConomy4(this); sm.register(net.milkbowl.vault.economy.Economy.class, icon4, this, ServicePriority.High); log.info( String.format( "[%s][Economy] iConomy 4 found: ", getDescription().getName(), icon4.isEnabled() ? "Loaded" : "Waiting")); } // Try to load iConomy 5 if (packageExists( "com.iConomy.iConomy", "com.iConomy.system.Account", "com.iConomy.system.Holdings")) { Economy icon5 = new Economy_iConomy5(this); sm.register(net.milkbowl.vault.economy.Economy.class, icon5, this, ServicePriority.High); log.info( String.format( "[%s][Economy] iConomy 5 found: %s", getDescription().getName(), icon5.isEnabled() ? "Loaded" : "Waiting")); } // Try to load iConomy 6 if (packageExists("com.iCo6.iConomy")) { Economy icon6 = new Economy_iConomy6(this); sm.register(Economy.class, icon6, this, ServicePriority.High); log.info( String.format( "[%s][Economy] iConomy 6 found: %s", getDescription().getName(), icon6.isEnabled() ? "Loaded" : "Waiting")); } // Try loading EconXP if (packageExists("ca.agnate.EconXP.EconXP")) { Economy econ = new Economy_EconXP(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] EconXP found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } // Try to load Exchequer if (packageExists("name.richardson.james.bukkit.exchequer")) { Economy econ = new Economy_Exchequer(this); sm.register(Economy.class, econ, this, ServicePriority.Normal); log.info( String.format( "[%s][Economy] Exchequer found: %s", getDescription().getName(), econ.isEnabled() ? "Loaded" : "Waiting")); } }
@Override public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("party")) { Surprise.party((Player) sender); } else if (cmd.getName().equalsIgnoreCase("votepay")) { econ.depositPlayer( Bukkit.getPlayer(args[0]), Allowance.CURRENT_HOURLY_RATE * Allowance.CURRENT_VOTE_BONUS); } else if (cmd.getName().equalsIgnoreCase("lunaria")) { if (args.length == 1) { switch (args[0].toLowerCase()) { case "econ": sender.sendMessage("Current Hourly Rate: " + Allowance.CURRENT_HOURLY_RATE); sender.sendMessage("Current Hourly Bonus: " + Allowance.CURRENT_HOURLY_BONUS); sender.sendMessage("Current Vote Bonus: " + Allowance.CURRENT_VOTE_BONUS); break; default: break; } } else if (args.length == 2) { if (args[1].equalsIgnoreCase("reset")) { Allowance.CURRENT_HOURLY_BONUS = Allowance.BASE_HOURLY_BONUS; Allowance.CURRENT_HOURLY_RATE = Allowance.BASE_HOURLY_RATE; Allowance.CURRENT_VOTE_BONUS = Allowance.BASE_VOTE_BONUS; sender.sendMessage("Reset Successful!"); } } else if (args.length == 3) { switch (args[1].toLowerCase()) { case "hourlyrate": Allowance.CURRENT_HOURLY_RATE = Double.parseDouble(args[2]); sender.sendMessage("Hourly Rate Adjustment Successful!"); break; case "hourlybonus": Allowance.CURRENT_HOURLY_BONUS = Double.parseDouble(args[2]); sender.sendMessage("Hourly Bonus Adjustment Successful!"); break; case "votebonus": Allowance.CURRENT_VOTE_BONUS = Double.parseDouble(args[2]); sender.sendMessage("Vote Bonus Adjustment Successful!"); break; default: break; } } } else if (cmd.getName().equalsIgnoreCase("cake")) { sender.sendMessage("Tis a lie!"); } else if (cmd.getName().equalsIgnoreCase("usa")) { Surprise.usa((Player) sender); sender.sendMessage("Look Up!"); } else if (cmd.getName().equalsIgnoreCase("cookout")) { Surprise.cookout((Player) sender); } else if (cmd.getName().equalsIgnoreCase("funitems")) { if (sender instanceof Player) { if (sender.hasPermission("funitems")) { Player player = (Player) sender; boolean breakable = args.length < 2 || args[1].equalsIgnoreCase("false"); if (args.length == 0) { sender.sendMessage(FunItem.getList()); return false; } switch (args[0].toUpperCase()) { // case "MAIL": // if (args.length >= 3) { // UUID reciever; // try { // reciever = UUIDFetcher.getUUIDOf(args[1]); // if (Bukkit.getOfflinePlayer(reciever).isOnline()) { // Player rPlayer = Bukkit.getPlayer(reciever); // FunItem f = FunItem.getConstant(args[2]); // rPlayer.getWorld().dropItemNaturally(rPlayer.getLocation(), // ItemGenerator.generateFunItem(f, true)); // } // else { // Mail mail = new Mail(reciever, FunItem.getConstant(args[2])); // if (!funItems.contains(mail)) { // funItems.add(mail); // } // } // } catch (Exception e) { // sender.sendMessage("Unable to find player or invalid command!"); // } // } // break; case "SLY": player .getWorld() .dropItemNaturally( player.getLocation(), ItemGenerator.generateFunItem("Sly", breakable)); player .getWorld() .dropItemNaturally(player.getLocation(), new ItemStack(Material.ARROW)); sender.sendMessage("Have fun! :D"); break; case "MAMZ": player .getWorld() .dropItemNaturally( player.getLocation(), ItemGenerator.generateFunItem("Mamz", breakable)); sender.sendMessage("DO NOT ABUSE"); break; case "CLOCK": break; case "CONVERT": if (ItemGenerator.convert(player.getItemInHand())) { sender.sendMessage("Have fun :)"); } else { sender.sendMessage("Not a Fun Item!"); } break; case "LIST": default: sender.sendMessage(FunItem.getList()); } } } } return false; }
@Override public double addMoney(Player player, double money) { economy.depositPlayer(player.getName(), money); return getBalance(player); }
@Override public boolean canAfford(Player player, double money) { return economy.has(player.getName(), money); }
@Override public String getMoneyName() { return economy.currencyNameSingular(); }
@Override public String format(double money) { return economy.format(money); }
@Override public double removeMoney(Player player, double money) { economy.withdrawPlayer(player.getName(), money); return getBalance(player); }
public void addMoney(Player player, float money) { if (economy != null) { economy.depositPlayer(player.getName(), money); } }
public void removeMoney(Player player, float money) { if (economy != null) { economy.withdrawPlayer(player.getName(), money); } }
public boolean hasMoney(Player player, float money) { if (economy == null) return false; return economy.has(player.getName(), money); }
@Override public double getBalance(Player player) { return economy.getBalance(player.getName()); }