Deposit-Command
Withdraw-Command
Java:
package me.JWH.Notes;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class DepositCommand
implements CommandExecutor
{
private BanknotePlugin plugin;
public DepositCommand(BanknotePlugin plugin) { this.plugin = plugin; }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player)) {
sender.sendMessage("Only players can deposit bank notes");
} else if (!sender.hasPermission("banknotes.deposit")) {
sender.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.insufficient-permissions")));
} else {
Player player = (Player)sender;
ItemStack item = player.getItemInHand();
if (item != null && this.plugin.isBanknote(item)) {
double amount = this.plugin.getBanknoteAmount(item);
if (amount > 0.0D) {
this.plugin.getEconomy().depositPlayer(player, amount);
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.note-redeemed").replace("[money]", this.plugin.formatDouble(amount))));
} else {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.invalid-note")));
}
if (item.getAmount() <= 1) {
player.getInventory().removeItem(new ItemStack[] { item });
} else {
item.setAmount(item.getAmount() - 1);
}
} else {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.nothing-in-hand")));
}
}
return true;
}
}
Withdraw-Command
Java:
package me.JWH.Notes;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
public class WithdrawCommand
implements CommandExecutor
{
private BanknotePlugin plugin;
public WithdrawCommand(BanknotePlugin plugin) { this.plugin = plugin; }
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (!(sender instanceof Player))
{ sender.sendMessage("Only players can withdraw bank notes"); }
else if (!sender.hasPermission("banknotes.withdraw"))
{ sender.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.insufficient-permissions"))); }
else { if (args.length == 0) {
return false;
}
Player player = (Player)sender;
try {
double amount = args[0].equalsIgnoreCase("all") ?
this.plugin.getEconomy().getBalance(player) : Double.parseDouble(args[0]);
double min = this.plugin.getConfig().getDouble("s.minimum-withdraw-amount");
double max = this.plugin.getConfig().getDouble("s.maximum-withdraw-amount");
if (Double.isNaN(amount) || Double.isInfinite(amount) || amount <= 0.0D) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.invalid-number")));
} else if (amount < min) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.less-than-minimum").replace("[money]", this.plugin.formatDouble(min))));
} else if (amount > max) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.more-than-maximum").replace("[money]", this.plugin.formatDouble(max))));
} else if (this.plugin.getEconomy().getBalance(player) < amount) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.insufficient-funds")));
} else if (player.getInventory().firstEmpty() == -1) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.inventory-full")));
} else {
ItemStack banknote = this.plugin.createBanknote(player, amount);
this.plugin.getEconomy().withdrawPlayer(player, amount);
player.getInventory().addItem(new ItemStack[] { banknote });
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.note-created").replace("[money]", this.plugin.formatDouble(amount))));
}
} catch (NumberFormatException invalidNumber) {
player.sendMessage(this.plugin.colorMessage(this.plugin.getConfig().getString("m.invalid-number")));
} }
return true;
}
}