Search in sources :

Example 6 with SlotType

use of org.bukkit.event.inventory.InventoryType.SlotType in project Glowstone by GlowstoneMC.

the class GlowInventory method toString.

@Override
public String toString() {
    StringBuilder sb = new StringBuilder(getClass().getSimpleName());
    sb.append(" for ").append(getHolder()).append(":\n");
    for (GlowInventorySlot slot : slots) {
        ItemStack item = slot.getItem();
        SlotType type = slot.getType();
        if (type != SlotType.CONTAINER || !InventoryUtil.isEmpty(item)) {
            sb.append(item).append(" in ").append(slot.getType()).append('\n');
        }
    }
    return sb.toString();
}
Also used : ItemStack(org.bukkit.inventory.ItemStack) SlotType(org.bukkit.event.inventory.InventoryType.SlotType)

Example 7 with SlotType

use of org.bukkit.event.inventory.InventoryType.SlotType in project Glowstone by GlowstoneMC.

the class CreativeItemHandler method handle.

@Override
public void handle(GlowSession session, CreativeItemMessage message) {
    GlowPlayer player = session.getPlayer();
    // CraftBukkit does use a inventory view with both inventories set to the player's inventory
    // for the creative inventory as there is no second inventory (no crafting) visible for the
    // client
    InventoryView view = player.getOpenInventory();
    // only if creative mode; only if default (player) inventory
    if (player.getGameMode() != GameMode.CREATIVE || !GlowInventoryView.isDefault(player.getOpenInventory())) {
        player.kickPlayer(GlowstoneMessages.Kick.CREATIVE_ITEM.get());
        return;
    }
    ItemStack stack = ItemIds.sanitize(message.getItem());
    // clicking outside drops the item
    EventFactory eventFactory = EventFactory.getInstance();
    if (message.getSlot() < 0) {
        InventoryCreativeEvent event = eventFactory.callEvent(new InventoryCreativeEvent(view, SlotType.OUTSIDE, -999, stack));
        if (event.isCancelled()) {
            session.send(new SetWindowSlotMessage(-1, -1, stack));
        } else {
            player.drop(event.getCursor());
        }
        return;
    }
    int viewSlot = message.getSlot();
    // this happens quiet often as the client tends to update the whole inventory at once
    if (Objects.equals(stack, view.getItem(viewSlot))) {
        return;
    }
    GlowInventory inv = player.getInventory();
    int slot = view.convertSlot(viewSlot);
    SlotType type = inv.getSlotType(slot);
    InventoryCreativeEvent event = eventFactory.callEvent(new InventoryCreativeEvent(view, type, viewSlot, stack));
    if (event.isCancelled()) {
        // send original slot to player to prevent async inventories
        player.sendItemChange(viewSlot, view.getItem(viewSlot));
        // don't keep track of player's current item, just give them back what they tried to
        // place
        session.send(new SetWindowSlotMessage(-1, -1, stack));
        return;
    }
    view.setItem(viewSlot, stack);
}
Also used : GlowInventoryView(net.glowstone.inventory.GlowInventoryView) InventoryView(org.bukkit.inventory.InventoryView) InventoryCreativeEvent(org.bukkit.event.inventory.InventoryCreativeEvent) GlowPlayer(net.glowstone.entity.GlowPlayer) SetWindowSlotMessage(net.glowstone.net.message.play.inv.SetWindowSlotMessage) GlowInventory(net.glowstone.inventory.GlowInventory) EventFactory(net.glowstone.EventFactory) ItemStack(org.bukkit.inventory.ItemStack) SlotType(org.bukkit.event.inventory.InventoryType.SlotType)

Example 8 with SlotType

use of org.bukkit.event.inventory.InventoryType.SlotType in project MassiveCore by MassiveCraft.

the class InventoryUtil method isEquipping.

// -------------------------------------------- //
// EVENT INTERPRETATION > EQUIPPING
// -------------------------------------------- //
/**
 * This method will return the ItemStack the player is trying to equip.
 * If the click event would not result in equipping something null will be returned.
 * Note that this algorithm is not perfect. It's an adequate guess.
 *
 * @param event The InventoryClickEvent to analyze.
 * @return The ItemStack the player is trying to equip.
 */
public static ItemStack isEquipping(InventoryClickEvent event) {
    boolean isShiftClick = event.isShiftClick();
    InventoryType inventoryType = event.getInventory().getType();
    SlotType slotType = event.getSlotType();
    ItemStack cursor = event.getCursor();
    ItemStack currentItem = event.getCurrentItem();
    if (isShiftClick) {
        if (inventoryType != InventoryType.CRAFTING)
            return null;
        if (slotType == SlotType.CRAFTING)
            return null;
        if (slotType == SlotType.ARMOR)
            return null;
        if (slotType == SlotType.RESULT)
            return null;
        if (currentItem.getType() == Material.AIR)
            return null;
        return currentItem;
    } else {
        if (slotType == SlotType.ARMOR) {
            return cursor;
        }
        return null;
    }
}
Also used : InventoryType(org.bukkit.event.inventory.InventoryType) ItemStack(org.bukkit.inventory.ItemStack) SlotType(org.bukkit.event.inventory.InventoryType.SlotType)

Aggregations

SlotType (org.bukkit.event.inventory.InventoryType.SlotType)8 ItemStack (org.bukkit.inventory.ItemStack)8 Player (org.bukkit.entity.Player)4 EventHandler (org.bukkit.event.EventHandler)4 InventoryType (org.bukkit.event.inventory.InventoryType)4 Wand (com.elmakers.mine.bukkit.wand.Wand)2 GlowInventory (net.glowstone.inventory.GlowInventory)2 SetWindowSlotMessage (net.glowstone.net.message.play.inv.SetWindowSlotMessage)2 InventoryAction (org.bukkit.event.inventory.InventoryAction)2 CraftingInventory (org.bukkit.inventory.CraftingInventory)2 Inventory (org.bukkit.inventory.Inventory)2 InventoryView (org.bukkit.inventory.InventoryView)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 HashMap (java.util.HashMap)1 PlayerCraftsItemScriptEvent (net.aufdemrand.denizen.events.player.PlayerCraftsItemScriptEvent)1 net.aufdemrand.denizen.objects.dItem (net.aufdemrand.denizen.objects.dItem)1 net.aufdemrand.denizen.objects.dPlayer (net.aufdemrand.denizen.objects.dPlayer)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 EventFactory (net.glowstone.EventFactory)1 GlowPlayer (net.glowstone.entity.GlowPlayer)1