use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class Commandworth method run.
@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
ItemStack stack = ess.getItemDb().get(args[0]);
itemWorth(sender, null, stack, args);
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class SignSell method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException {
Trade charge = getTrade(sign, 1, 2, player, ess);
Trade money = getTrade(sign, 3, ess);
// Check if the player is trying to sell in bulk.
if (ess.getSettings().isAllowBulkBuySell() && player.getBase().isSneaking()) {
ItemStack heldItem = player.getItemInHand();
if (charge.getItemStack().isSimilar(heldItem)) {
int initialItemAmount = charge.getItemStack().getAmount();
int newItemAmount = heldItem.getAmount();
ItemStack item = charge.getItemStack();
item.setAmount(newItemAmount);
charge = new Trade(item, ess);
BigDecimal chargeAmount = money.getMoney();
BigDecimal pricePerSingleItem = chargeAmount.divide(new BigDecimal(initialItemAmount));
pricePerSingleItem = pricePerSingleItem.multiply(new BigDecimal(newItemAmount));
money = new Trade(pricePerSingleItem, ess);
}
}
charge.isAffordableFor(player);
money.pay(player, OverflowType.DROP);
charge.charge(player);
Trade.log("Sign", "Sell", "Interact", username, charge, username, money, sign.getBlock().getLocation(), ess);
return true;
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class EssentialsSign method getItemMeta.
protected final ItemStack getItemMeta(final ItemStack item, final String meta, final IEssentials ess) throws SignException {
ItemStack stack = item;
try {
if (!meta.isEmpty()) {
MetaItemStack metaStack = new MetaItemStack(stack);
final boolean allowUnsafe = ess.getSettings().allowUnsafeEnchantments();
metaStack.addStringMeta(null, allowUnsafe, meta, ess);
stack = metaStack.getItemStack();
}
} catch (Exception ex) {
throw new SignException(ex.getMessage(), ex);
}
return stack;
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class Commandrepair method repairItems.
private void repairItems(final ItemStack[] items, final IUser user, final List<String> repaired) {
for (ItemStack item : items) {
if (item == null || item.getType().isBlock() || item.getDurability() == 0) {
continue;
}
final String itemName = item.getType().toString().toLowerCase(Locale.ENGLISH);
final Trade charge = new Trade("repair-" + itemName.replace('_', '-'), new Trade("repair-" + item.getTypeId(), new Trade("repair-item", ess), ess), ess);
try {
charge.isAffordableFor(user);
} catch (ChargeException ex) {
user.sendMessage(ex.getMessage());
continue;
}
if (!item.getEnchantments().isEmpty() && !ess.getSettings().getRepairEnchanted() && !user.isAuthorized("essentials.repair.enchanted")) {
continue;
}
try {
repairItem(item);
} catch (Exception e) {
continue;
}
try {
charge.charge(user);
} catch (ChargeException ex) {
user.sendMessage(ex.getMessage());
}
repaired.add(itemName.replace('_', ' '));
}
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class Commandsell method run.
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
BigDecimal totalWorth = BigDecimal.ZERO;
String type = "";
if (args.length < 1) {
throw new NotEnoughArgumentsException();
}
if (args[0].equalsIgnoreCase("hand") && !user.isAuthorized("essentials.sell.hand")) {
throw new Exception(tl("sellHandPermission"));
} else if ((args[0].equalsIgnoreCase("inventory") || args[0].equalsIgnoreCase("invent") || args[0].equalsIgnoreCase("all")) && !user.isAuthorized("essentials.sell.bulk")) {
throw new Exception(tl("sellBulkPermission"));
}
List<ItemStack> is = ess.getItemDb().getMatching(user, args);
int count = 0;
boolean isBulk = is.size() > 1;
for (ItemStack stack : is) {
try {
if (stack.getAmount() > 0) {
totalWorth = totalWorth.add(sellItem(user, stack, args, isBulk));
stack = stack.clone();
count++;
for (ItemStack zeroStack : is) {
if (zeroStack.isSimilar(stack)) {
zeroStack.setAmount(0);
}
}
}
} catch (Exception e) {
if (!isBulk) {
throw e;
}
}
}
if (count != 1) {
if (args[0].equalsIgnoreCase("blocks")) {
user.sendMessage(tl("totalWorthBlocks", type, NumberUtil.displayCurrency(totalWorth, ess)));
} else {
user.sendMessage(tl("totalWorthAll", type, NumberUtil.displayCurrency(totalWorth, ess)));
}
}
}
Aggregations