use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class EssentialsAntiBuildListener method onCraftItemEvent.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onCraftItemEvent(final CraftItemEvent event) {
HumanEntity entity = event.getWhoClicked();
if (entity instanceof Player) {
final User user = ess.getUser((Player) entity);
final ItemStack item = event.getRecipe().getResult();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "craft", item.getTypeId(), item.getDurability())) {
event.setCancelled(true);
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildCraft", item.getType().toString()));
}
}
}
}
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class EssentialsAntiBuildListener method onPlayerPickupItem.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerPickupItem(PlayerPickupItemEvent event) {
final User user = ess.getUser(event.getPlayer());
final ItemStack item = event.getItem().getItemStack();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "pickup", item.getTypeId(), item.getDurability())) {
event.setCancelled(true);
event.getItem().setPickupDelay(50);
}
}
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class EssentialsAntiBuildListener method onPlayerDropItem.
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onPlayerDropItem(final PlayerDropItemEvent event) {
final User user = ess.getUser(event.getPlayer());
final ItemStack item = event.getItemDrop().getItemStack();
if (prot.getSettingBool(AntiBuildConfig.disable_use) && !user.canBuild() && !user.isAuthorized("essentials.build")) {
if (!metaPermCheck(user, "drop", item.getTypeId(), item.getDurability())) {
event.setCancelled(true);
user.getBase().updateInventory();
if (ess.getSettings().warnOnBuildDisallow()) {
user.sendMessage(tl("antiBuildDrop", item.getType().toString()));
}
}
}
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class SignTrade method onSignInteract.
@Override
protected boolean onSignInteract(final ISign sign, final User player, final String username, final IEssentials ess) throws SignException, ChargeException, MaxMoneyException {
if (sign.getLine(3).substring(2).equalsIgnoreCase(username)) {
final Trade store = rechargeSign(sign, ess, player);
Trade stored;
try {
stored = getTrade(sign, 1, AmountType.TOTAL, true, ess);
subtractAmount(sign, 1, stored, ess);
Map<Integer, ItemStack> withdraw = stored.pay(player, OverflowType.RETURN);
if (withdraw == null) {
Trade.log("Sign", "Trade", "Withdraw", username, store, username, null, sign.getBlock().getLocation(), ess);
} else {
setAmount(sign, 1, BigDecimal.valueOf(withdraw.get(0).getAmount()), ess);
Trade.log("Sign", "Trade", "Withdraw", username, stored, username, new Trade(withdraw.get(0), ess), sign.getBlock().getLocation(), ess);
}
} catch (SignException e) {
if (store == null) {
throw new SignException(tl("tradeSignEmptyOwner"), e);
}
}
Trade.log("Sign", "Trade", "Deposit", username, store, username, null, sign.getBlock().getLocation(), ess);
} else {
final Trade charge = getTrade(sign, 1, AmountType.COST, false, ess);
final Trade trade = getTrade(sign, 2, AmountType.COST, true, ess);
charge.isAffordableFor(player);
addAmount(sign, 1, charge, ess);
subtractAmount(sign, 2, trade, ess);
if (!trade.pay(player)) {
subtractAmount(sign, 1, charge, ess);
addAmount(sign, 2, trade, ess);
throw new ChargeException("Full inventory");
}
charge.charge(player);
Trade.log("Sign", "Trade", "Interact", sign.getLine(3), charge, username, trade, sign.getBlock().getLocation(), ess);
}
sign.updateSign();
return true;
}
use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.
the class SignTrade method rechargeSign.
private Trade rechargeSign(final ISign sign, final IEssentials ess, final User player) throws SignException, ChargeException {
final Trade trade = getTrade(sign, 2, AmountType.COST, false, ess);
if (trade.getItemStack() != null && player.getBase().getItemInHand() != null && trade.getItemStack().getType() == player.getBase().getItemInHand().getType() && trade.getItemStack().getDurability() == player.getBase().getItemInHand().getDurability() && trade.getItemStack().getEnchantments().equals(player.getBase().getItemInHand().getEnchantments())) {
int amount = player.getBase().getItemInHand().getAmount();
amount -= amount % trade.getItemStack().getAmount();
if (amount > 0) {
final ItemStack stack = player.getBase().getItemInHand().clone();
stack.setAmount(amount);
final Trade store = new Trade(stack, ess);
addAmount(sign, 2, store, ess);
store.charge(player);
return store;
}
}
return null;
}
Aggregations