Search in sources :

Example 21 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class InventoryUtil method getChangesClick.

protected static List<Entry<ItemStack, Integer>> getChangesClick(InventoryClickEvent event) {
    // Create
    List<Entry<ItemStack, Integer>> ret = new MassiveList<>();
    // Fill
    final InventoryAlter alter = InventoryUtil.getAlter(event);
    final InventoryAction action = event.getAction();
    ItemStack item;
    int amount;
    // Give
    if (alter.isGiving()) {
        // Special > MOVE_TO_OTHER_INVENTORY
        if (action == InventoryAction.MOVE_TO_OTHER_INVENTORY) {
            item = event.getCurrentItem();
            ItemStack compare = item.clone();
            compare.setAmount(1);
            amount = InventoryUtil.roomLeft(event.getInventory(), compare, item.getAmount());
        } else // Special > HOTBAR_SWAP
        if (action == InventoryAction.HOTBAR_SWAP) {
            item = event.getView().getBottomInventory().getItem(event.getHotbarButton());
            amount = item.getAmount();
        } else // Normal
        {
            item = event.getCursor();
            amount = item.getAmount();
            if (action == InventoryAction.PLACE_ONE) {
                amount = 1;
            } else if (action == InventoryAction.PLACE_SOME) {
                int max = event.getCurrentItem().getType().getMaxStackSize();
                amount = max - event.getCurrentItem().getAmount();
            }
        }
        amount *= -1;
        ret.add(new SimpleEntry<>(item, amount));
    }
    // Take
    if (alter.isTaking()) {
        item = event.getCurrentItem();
        amount = item.getAmount();
        if (action == InventoryAction.PICKUP_ONE)
            amount = 1;
        if (action == InventoryAction.PICKUP_HALF)
            amount = (int) Math.ceil(amount / 2.0);
        ret.add(new SimpleEntry<>(item, amount));
    }
    // Return
    return ret;
}
Also used : SimpleEntry(java.util.AbstractMap.SimpleEntry) Entry(java.util.Map.Entry) MassiveList(com.massivecraft.massivecore.collections.MassiveList) ItemStack(org.bukkit.inventory.ItemStack) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Example 22 with MassiveList

use of com.massivecraft.massivecore.collections.MassiveList in project MassiveCore by MassiveCraft.

the class EventMassiveCoreLorePriority method getLoreEntries.

private static List<Entry<String, Integer>> getLoreEntries(ItemStack item) {
    ItemMeta meta = item.getItemMeta();
    if (!meta.hasLore())
        return Collections.emptyList();
    List<Entry<String, Integer>> ret = new MassiveList<>();
    for (String line : meta.getLore()) {
        ret.add(new SimpleEntry<>(line, PRIORITY_DEFAULT));
    }
    return ret;
}
Also used : Entry(java.util.Map.Entry) SimpleEntry(java.util.AbstractMap.SimpleEntry) MassiveList(com.massivecraft.massivecore.collections.MassiveList) ItemMeta(org.bukkit.inventory.meta.ItemMeta)

Aggregations

MassiveList (com.massivecraft.massivecore.collections.MassiveList)22 Mson (com.massivecraft.massivecore.mson.Mson)7 SimpleEntry (java.util.AbstractMap.SimpleEntry)4 Entry (java.util.Map.Entry)4 ItemStack (org.bukkit.inventory.ItemStack)3 ChatColor (org.bukkit.ChatColor)2 ItemMeta (org.bukkit.inventory.meta.ItemMeta)2 MassiveException (com.massivecraft.massivecore.MassiveException)1 EditorType (com.massivecraft.massivecore.command.editor.annotation.EditorType)1 EditorTypeInner (com.massivecraft.massivecore.command.editor.annotation.EditorTypeInner)1 Requirement (com.massivecraft.massivecore.command.requirement.Requirement)1 Type (com.massivecraft.massivecore.command.type.Type)1 TypeEnchantment (com.massivecraft.massivecore.command.type.TypeEnchantment)1 TypeEntityType (com.massivecraft.massivecore.command.type.enumeration.TypeEntityType)1 TypeFireworkEffectType (com.massivecraft.massivecore.command.type.enumeration.TypeFireworkEffectType)1 TypeOcelotType (com.massivecraft.massivecore.command.type.enumeration.TypeOcelotType)1 TypeRabbitType (com.massivecraft.massivecore.command.type.enumeration.TypeRabbitType)1 TypeSkeletonType (com.massivecraft.massivecore.command.type.enumeration.TypeSkeletonType)1 TypeWorldType (com.massivecraft.massivecore.command.type.enumeration.TypeWorldType)1 EventMassiveCoreLorePriority (com.massivecraft.massivecore.event.EventMassiveCoreLorePriority)1