import net.milkbowl.vault.economy.EconomyResponse;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
public class ShopCommand implements CommandExecutor {
private final SimpleEconomy eco;
public ShopCommand(SimpleEconomy eco) {
this.eco = eco;
}
@Override
public boolean onCommand(CommandSender s, Command c, String l, String[] a) {
if (!(s instanceof Player)) return true;
Player p = (Player) s;
if (a.length == 0) {
p.sendMessage("Use: /shop <buy>");
return true;
}
if ("buy".equalsIgnoreCase(a[0])) {
double price = 250.00;
if (!eco.has(p, price)) {
p.sendMessage("&cYou need " + eco.format(price));
return true;
}
EconomyResponse r = eco.withdrawPlayer(p, price);
if (r.transactionSuccess()) {
p.getInventory().addItem(Material.DIAMOND_SWORD.asItemStack());
p.sendMessage("&aYou bought a diamond sword");
p.sendMessage("&fBalance: " + eco.format(r.balance));
}
}
return true;
}
}