Search in sources :

Example 81 with ItemStack

use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.

the class Commandsetworth method run.

@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 1) {
        throw new NotEnoughArgumentsException();
    }
    ItemStack stack;
    String price;
    if (args.length == 1) {
        stack = user.getBase().getInventory().getItemInHand();
        price = args[0];
    } else {
        stack = ess.getItemDb().get(args[0]);
        price = args[1];
    }
    ess.getWorth().setPrice(stack, FloatUtil.parseDouble(price));
    user.sendMessage(tl("worthSet"));
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Example 82 with ItemStack

use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.

the class Commandsetworth method run.

@Override
public void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
    if (args.length < 2) {
        throw new NotEnoughArgumentsException();
    }
    ItemStack stack = ess.getItemDb().get(args[0]);
    ess.getWorth().setPrice(stack, FloatUtil.parseDouble(args[1]));
    sender.sendMessage(tl("worthSet"));
}
Also used : ItemStack(org.bukkit.inventory.ItemStack)

Example 83 with ItemStack

use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.

the class Trade method pay.

public Map<Integer, ItemStack> pay(final IUser user, final OverflowType type) throws MaxMoneyException {
    if (getMoney() != null && getMoney().signum() > 0) {
        if (ess.getSettings().isDebug()) {
            ess.getLogger().log(Level.INFO, "paying user " + user.getName() + " via trade " + getMoney().toPlainString());
        }
        user.giveMoney(getMoney());
    }
    if (getItemStack() != null) {
        // This stores the would be overflow
        Map<Integer, ItemStack> overFlow = InventoryWorkaround.addAllItems(user.getBase().getInventory(), getItemStack());
        if (overFlow != null) {
            switch(type) {
                case ABORT:
                    if (ess.getSettings().isDebug()) {
                        ess.getLogger().log(Level.INFO, "abort paying " + user.getName() + " itemstack " + getItemStack().toString() + " due to lack of inventory space ");
                    }
                    return overFlow;
                case RETURN:
                    // Pay the user the items, and return overflow
                    final Map<Integer, ItemStack> returnStack = InventoryWorkaround.addItems(user.getBase().getInventory(), getItemStack());
                    user.getBase().updateInventory();
                    if (ess.getSettings().isDebug()) {
                        ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " with overflow " + returnStack.get(0).toString());
                    }
                    return returnStack;
                case DROP:
                    // Pay the users the items directly, and drop the rest, will always return no overflow.
                    final Map<Integer, ItemStack> leftOver = InventoryWorkaround.addItems(user.getBase().getInventory(), getItemStack());
                    final Location loc = user.getBase().getLocation();
                    for (ItemStack loStack : leftOver.values()) {
                        final int maxStackSize = loStack.getType().getMaxStackSize();
                        final int stacks = loStack.getAmount() / maxStackSize;
                        final int leftover = loStack.getAmount() % maxStackSize;
                        final Item[] itemStacks = new Item[stacks + (leftover > 0 ? 1 : 0)];
                        for (int i = 0; i < stacks; i++) {
                            final ItemStack stack = loStack.clone();
                            stack.setAmount(maxStackSize);
                            itemStacks[i] = loc.getWorld().dropItem(loc, stack);
                        }
                        if (leftover > 0) {
                            final ItemStack stack = loStack.clone();
                            stack.setAmount(leftover);
                            itemStacks[stacks] = loc.getWorld().dropItem(loc, stack);
                        }
                    }
                    if (ess.getSettings().isDebug()) {
                        ess.getLogger().log(Level.INFO, "paying " + user.getName() + " partial itemstack " + getItemStack().toString() + " and dropping overflow " + leftOver.get(0).toString());
                    }
            }
        } else if (ess.getSettings().isDebug()) {
            ess.getLogger().log(Level.INFO, "paying " + user.getName() + " itemstack " + getItemStack().toString());
        }
        user.getBase().updateInventory();
    }
    if (getExperience() != null) {
        SetExpFix.setTotalExperience(user.getBase(), SetExpFix.getTotalExperience(user.getBase()) + getExperience());
    }
    return null;
}
Also used : Item(org.bukkit.entity.Item) ItemStack(org.bukkit.inventory.ItemStack) Location(org.bukkit.Location)

Example 84 with ItemStack

use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.

the class Settings method _getItemSpawnBlacklist.

private List<Integer> _getItemSpawnBlacklist() {
    final List<Integer> epItemSpwn = new ArrayList<Integer>();
    if (ess.getItemDb() == null) {
        logger.log(Level.FINE, "Aborting ItemSpawnBL read, itemDB not yet loaded.");
        return epItemSpwn;
    }
    for (String itemName : config.getString("item-spawn-blacklist", "").split(",")) {
        itemName = itemName.trim();
        if (itemName.isEmpty()) {
            continue;
        }
        try {
            final ItemStack iStack = ess.getItemDb().get(itemName);
            epItemSpwn.add(iStack.getTypeId());
        } catch (Exception ex) {
            logger.log(Level.SEVERE, tl("unknownItemInList", itemName, "item-spawn-blacklist"));
        }
    }
    return epItemSpwn;
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 85 with ItemStack

use of org.bukkit.inventory.ItemStack in project Essentials by drtshock.

the class Commandcondense method getStackOnRecipeMatch.

private Collection<ItemStack> getStackOnRecipeMatch(final Recipe recipe, final ItemStack stack) {
    final Collection<ItemStack> inputList;
    if (recipe instanceof ShapedRecipe) {
        ShapedRecipe sRecipe = (ShapedRecipe) recipe;
        inputList = sRecipe.getIngredientMap().values();
    } else if (recipe instanceof ShapelessRecipe) {
        ShapelessRecipe slRecipe = (ShapelessRecipe) recipe;
        inputList = slRecipe.getIngredientList();
    } else {
        return null;
    }
    boolean match = true;
    Iterator<ItemStack> iter = inputList.iterator();
    while (iter.hasNext()) {
        ItemStack inputSlot = iter.next();
        if (inputSlot == null) {
            iter.remove();
            continue;
        }
        if (inputSlot.getDurability() == Short.MAX_VALUE) {
            inputSlot.setDurability((short) 0);
        }
        if (!inputSlot.isSimilar(stack)) {
            match = false;
        }
    }
    if (match) {
        return inputList;
    }
    return null;
}
Also used : ShapedRecipe(org.bukkit.inventory.ShapedRecipe) ShapelessRecipe(org.bukkit.inventory.ShapelessRecipe) 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