private void commandDeposit(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "The console does not have an XP bank account."); return; } if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /xpbank deposit <amount>"); return; } Player p = (Player) sender; Integer depositAmount; if (args[1].equals("all")) { depositAmount = MinebotXPBank.calculateXP(p); } else { try { depositAmount = Integer.parseInt(args[1]); } catch (NumberFormatException e) { sender.sendMessage( ChatColor.RED + "Please provide a valid number amount of XP to deposit!"); return; } } Integer currentBalance = MinebotXPBank.getBalance(p.getName()); if (currentBalance == null) { MinebotXPBank.initAccount(p.getName()); currentBalance = 0; } int oldExp = MinebotXPBank.calculateXP(p); if (depositAmount > oldExp) { sender.sendMessage(ChatColor.RED + "You don't have that many XP to deposit."); } else { int newBalance = currentBalance + depositAmount; MinebotXPBank.setBalance(p.getName(), newBalance); sender.sendMessage(depositAmount.toString() + " XP " + ChatColor.GREEN + "deposited."); sender.sendMessage(ChatColor.GREEN + "New balance: " + ChatColor.WHITE + newBalance + " XP"); p.setLevel(0); p.setExp(0); p.giveExp(oldExp - depositAmount); } }
private void commandWithdraw(CommandSender sender, String[] args) { if (!(sender instanceof Player)) { sender.sendMessage(ChatColor.RED + "The console does not have an XP bank account."); return; } if (args.length < 2) { sender.sendMessage(ChatColor.RED + "Usage: /xpbank withdraw <amount>"); return; } Player p = (Player) sender; Integer currentBalance = MinebotXPBank.getBalance(p.getName()); if (currentBalance == null) { MinebotXPBank.initAccount(p.getName()); currentBalance = 0; } Integer withdrawAmount; if (args[1].equals("all")) { withdrawAmount = currentBalance; } else { try { withdrawAmount = Integer.parseInt(args[1]); } catch (NumberFormatException e) { sender.sendMessage(ChatColor.RED + "Please provide a valid number amount to withdraw!"); return; } } int newBalance = currentBalance - withdrawAmount; if (newBalance < 0) { sender.sendMessage(ChatColor.RED + "You don't have that many XP to withdraw."); } else { MinebotXPBank.setBalance(p.getName(), newBalance); sender.sendMessage(withdrawAmount.toString() + " XP " + ChatColor.GREEN + "withdrawn."); sender.sendMessage( ChatColor.GREEN + "Remaining balance: " + ChatColor.WHITE + newBalance + " XP"); int oldExp = MinebotXPBank.calculateXP(p); p.setLevel(0); p.setExp(0); p.giveExp(oldExp + withdrawAmount); } }
private void commandBalance(CommandSender sender, String[] args) { String acct = null; Player target = null; if (args.length >= 2) acct = args[1]; else if (args.length < 2 && sender instanceof Player) { target = (Player) sender; acct = target.getName(); } if (acct == null) { sender.sendMessage( ChatColor.RED + "The console does not have an XP bank account. Use xpbank bal <player>"); return; } // Get amount Integer amount = MinebotXPBank.getBalance(acct); if (amount == null && target == null) { sender.sendMessage(ChatColor.GREEN + acct + " does not have an XP bank account."); return; } else if (amount == null && target != null) { MinebotXPBank.initAccount(acct); amount = 0; } sender.sendMessage( ChatColor.GREEN + "XP bank balance for " + acct + ": " + ChatColor.WHITE + amount + " XP"); if (target != null) { sender.sendMessage( ChatColor.GREEN + "XP on hand: " + ChatColor.WHITE + MinebotXPBank.calculateXP(target) + " XP "); } }