Search in sources :

Example 86 with ItemStack

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()));
                }
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) User(com.earth2me.essentials.User) HumanEntity(org.bukkit.entity.HumanEntity) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 87 with ItemStack

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);
        }
    }
}
Also used : User(com.earth2me.essentials.User) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 88 with ItemStack

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()));
            }
        }
    }
}
Also used : User(com.earth2me.essentials.User) ItemStack(org.bukkit.inventory.ItemStack) EventHandler(org.bukkit.event.EventHandler)

Example 89 with ItemStack

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;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack) ChargeException(com.earth2me.essentials.ChargeException)

Example 90 with ItemStack

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;
}
Also used : Trade(com.earth2me.essentials.Trade) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)1420 Player (org.bukkit.entity.Player)270 EventHandler (org.bukkit.event.EventHandler)197 ItemMeta (org.bukkit.inventory.meta.ItemMeta)192 ArrayList (java.util.ArrayList)151 Inventory (org.bukkit.inventory.Inventory)127 Material (org.bukkit.Material)103 Location (org.bukkit.Location)96 PlayerInventory (org.bukkit.inventory.PlayerInventory)84 Entity (org.bukkit.entity.Entity)67 Block (org.bukkit.block.Block)54 LivingEntity (org.bukkit.entity.LivingEntity)51 TagCompound (de.keyle.knbt.TagCompound)47 HashMap (java.util.HashMap)47 Map (java.util.Map)46 Vector (org.bukkit.util.Vector)44 Enchantment (org.bukkit.enchantments.Enchantment)41 SkullMeta (org.bukkit.inventory.meta.SkullMeta)41 Mage (com.elmakers.mine.bukkit.api.magic.Mage)39 Test (org.junit.Test)38