org.bukkit.event.inventory.InventoryType.SlotType Java Examples

The following examples show how to use org.bukkit.event.inventory.InventoryType.SlotType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: VillagerTradesListener.java    From Statz with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onVillagerTrade(final InventoryClickEvent event) {

    final PlayerStat stat = PlayerStat.VILLAGER_TRADES;

    // Thanks to Lolmewn for this code (https://bitbucket
    // .org/Lolmewn/stats/src/4eae2db1b21038a91b7d39181f27bdd3cd987324/src/main/java/nl/lolmewn/stats/stats/bukkit
    // /BukkitTrades.java?at=3.0&fileviewer=file-view-default)

    if (event.getInventory().getType() != InventoryType.MERCHANT) {
        return;
    }
    if (!event.getSlotType().equals(SlotType.RESULT)) {
        return;
    }
    if (!event.getAction().equals(InventoryAction.MOVE_TO_OTHER_INVENTORY)
            && !event.getAction().equals(InventoryAction.PICKUP_ALL)) {
        return;
    }
    if (!(event.getWhoClicked() instanceof Player)) {
        return;
    }

    Player player = (Player) event.getWhoClicked();

    // Do general check
    if (!plugin.doGeneralCheck(player, stat))
        return;

    ItemStack item = event.getCurrentItem();

    // Update value to new stat.
    plugin.getDataManager().setPlayerInfo(player.getUniqueId(), stat,
            StatzUtil.makeQuery("uuid", player.getUniqueId().toString(), "value", item.getAmount(), "world",
                    player.getWorld().getName(), "trade", item.getType().toString()));

}
 
Example #2
Source File: TopTen.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory(); // The inventory that was clicked in
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    Player player = (Player) event.getWhoClicked();
    if (!inventory.getTitle().equals(plugin.myLocale().topTenGuiTitle)) {
        return;
    }
    event.setCancelled(true);
    player.updateInventory();
    if(event.getCurrentItem() != null && !event.getCurrentItem().getType().equals(Material.AIR) && event.getRawSlot() < 26) {
        event.getCurrentItem().setType(Material.AIR);
        player.closeInventory();
        String playerName = getPlayer(event.getRawSlot());
        UUID uuid = plugin.getPlayers().getUUID(playerName);
        if (uuid != null && plugin.getWarpSignsListener().getWarp(uuid) != null) {
            Util.runCommand(player, "is warp " + playerName);
        }
    }
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        return;
    }
}
 
Example #3
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private CraftItemEvent mockCraftingEvent(ItemStack item) {
    Recipe recipe = new ShapedRecipe(new NamespacedKey(plugin, "test_recipe"), new ItemStack(Material.EMERALD));
    Player player = server.addPlayer();

    CraftingInventory inv = Mockito.mock(CraftingInventory.class);
    Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { item, null, null, null, null, null, null, null, null });

    InventoryView view = player.openInventory(inv);
    CraftItemEvent event = new CraftItemEvent(recipe, view, SlotType.RESULT, 9, ClickType.LEFT, InventoryAction.PICKUP_ALL);

    listener.onCraft(event);
    return event;
}
 
Example #4
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockBrewingEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.BREWING);
    Mockito.when(inv.getHolder()).thenReturn(Mockito.mock(BrewingStand.class));
    Mockito.when(inv.getSize()).thenReturn(5);

    InventoryView view = player.openInventory(inv);
    view.setCursor(item);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 1, ClickType.LEFT, InventoryAction.PICKUP_ONE);
    listener.onPreBrew(event);
    return event;
}
 
Example #5
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockAnvilEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.ANVIL, item, null, new ItemStack(Material.IRON_CHESTPLATE));
    InventoryView view = player.openInventory(inv);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);

    listener.onAnvil(event);
    return event;
}
 
Example #6
Source File: TestVanillaMachinesListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private InventoryClickEvent mockGrindStoneEvent(ItemStack item) {
    Player player = server.addPlayer();
    Inventory inv = TestUtilities.mockInventory(InventoryType.GRINDSTONE, item, null);
    InventoryView view = player.openInventory(inv);
    InventoryClickEvent event = new InventoryClickEvent(view, SlotType.CONTAINER, 2, ClickType.LEFT, InventoryAction.PICKUP_ONE);

    listener.onGrindstone(event);
    return event;
}
 
Example #7
Source File: TestBackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@ParameterizedTest
@EnumSource(value = Material.class, names = { "AIR", "SHULKER_BOX" })
public void testHotbarKey(Material type) throws InterruptedException {
    Player player = server.addPlayer();
    openMockBackpack(player, "BACKPACK_HOTBAR_" + type.name(), 9);

    int slot = 7;
    player.getInventory().setItem(slot, new ItemStack(type));
    InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.NUMBER_KEY, InventoryAction.PICKUP_ONE, slot);
    listener.onClick(event);

    Assertions.assertEquals(type != Material.AIR, event.isCancelled());
}
 
Example #8
Source File: TestBackpackListener.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
private boolean isAllowed(String id, ItemStack item) throws InterruptedException {
    Player player = server.addPlayer();
    Inventory inv = openMockBackpack(player, id, 9).getInventory();

    int slot = 7;
    inv.setItem(slot, item);
    InventoryClickEvent event = new InventoryClickEvent(player.getOpenInventory(), SlotType.CONTAINER, slot, ClickType.LEFT, InventoryAction.PICKUP_ONE);
    listener.onClick(event);
    return !event.isCancelled();
}
 
Example #9
Source File: InventoryClickEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public InventoryClickEvent(InventoryView view, SlotType type, int slot, ClickType click, InventoryAction action) {
    super(view);
    this.slot_type = type;
    this.rawSlot = slot;
    if (slot < 0) {
        this.clickedInventory = null;
    } else if (view.getTopInventory() != null && slot < view.getTopInventory().getSize()) {
        this.clickedInventory = view.getTopInventory();
    } else {
        this.clickedInventory = view.getBottomInventory();
    }
    this.whichSlot = view.convertSlot(slot);
    this.click = click;
    this.action = action;
}
 
Example #10
Source File: InventoryClickEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the ItemStack currently in the clicked slot.
 *
 * @param stack the item to be placed in the current slot
 */
public void setCurrentItem(ItemStack stack) {
    if (slot_type == SlotType.OUTSIDE) {
        current = stack;
    } else {
        getView().setItem(rawSlot, stack);
    }
}
 
Example #11
Source File: InventoryClickEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the ItemStack currently in the clicked slot.
 *
 * @return the item in the clicked
 */
public ItemStack getCurrentItem() {
    if (slot_type == SlotType.OUTSIDE) {
        return current;
    }
    return getView().getItem(rawSlot);
}
 
Example #12
Source File: CraftInventoryView.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public static SlotType getSlotType(InventoryView inventory, int slot) {
    SlotType type = SlotType.CONTAINER;
    if (slot >= 0 && slot < inventory.getTopInventory().getSize()) {
        switch (inventory.getType()) {
            case FURNACE:
                if (slot == 2) {
                    type = SlotType.RESULT;
                } else if (slot == 1) {
                    type = SlotType.FUEL;
                } else {
                    type = SlotType.CRAFTING;
                }
                break;
            case BREWING:
                if (slot == 3) {
                    type = SlotType.FUEL;
                } else {
                    type = SlotType.CRAFTING;
                }
                break;
            case ENCHANTING:
                type = SlotType.CRAFTING;
                break;
            case WORKBENCH:
            case CRAFTING:
                if (slot == 0) {
                    type = SlotType.RESULT;
                } else {
                    type = SlotType.CRAFTING;
                }
                break;
            case MERCHANT:
                if (slot == 2) {
                    type = SlotType.RESULT;
                } else {
                    type = SlotType.CRAFTING;
                }
                break;
            case BEACON:
                type = SlotType.CRAFTING;
                break;
            case ANVIL:
                if (slot == 2) {
                    type = SlotType.RESULT;
                } else {
                    type = SlotType.CRAFTING;
                }
                break;
            default:
                // Nothing to do, it's a CONTAINER slot
        }
    } else {
        if (slot == -999 || slot == -1) {
            type = SlotType.OUTSIDE;
        } else if (inventory.getType() == InventoryType.CRAFTING) { // Also includes creative inventory
            if (slot < 9) {
                type = SlotType.ARMOR;
            } else if (slot > 35) {
                type = SlotType.QUICKBAR;
            }
        } else if (slot >= (inventory.countSlots() - (9 + 4 + 1))) { // Quickbar, Armor, Offhand
            type = SlotType.QUICKBAR;
        }
    }
    return type;
}
 
Example #13
Source File: CraftInventoryView.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
public static SlotType getSlotType(InventoryView inventory, int slot) {
    SlotType type = SlotType.CONTAINER;
    if (inventory == null) return type; // Cauldron - modded inventories with no Bukkit wrapper
    if (slot >= 0 && slot < inventory.getTopInventory().getSize()) {
        switch(inventory.getType()) {
        case FURNACE:
            if (slot == 2) {
                type = SlotType.RESULT;
            } else if(slot == 1) {
                type = SlotType.FUEL;
            } else {
                type = SlotType.CRAFTING;
            }
            break;
        case BREWING:
            if (slot == 3) {
                type = SlotType.FUEL;
            } else {
                type = SlotType.CRAFTING;
            }
            break;
        case ENCHANTING:
            type = SlotType.CRAFTING;
            break;
        case WORKBENCH:
        case CRAFTING:
            if (slot == 0) {
                type = SlotType.RESULT;
            } else {
                type = SlotType.CRAFTING;
            }
            break;
        case MERCHANT:
            if (slot == 2) {
                type = SlotType.RESULT;
            } else {
                type = SlotType.CRAFTING;
            }
            break;
        case BEACON:
            type = SlotType.CRAFTING;
            break;
        case ANVIL:
            if (slot == 2) {
                type = SlotType.RESULT;
            } else {
                type = SlotType.CRAFTING;
            }
            break;
        default:
            // Nothing to do, it's a CONTAINER slot
        }
    } else {
        if (slot == -999) {
            type = SlotType.OUTSIDE;
        } else if (inventory.getType() == InventoryType.CRAFTING) {
            if (slot < 9) {
            type = SlotType.ARMOR;
            } else if (slot > 35) {
                type = SlotType.QUICKBAR;
            }
        } else if (slot >= (inventory.countSlots() - 9)) {
            type = SlotType.QUICKBAR;
        }
    }
    return type;
}
 
Example #14
Source File: InventoryCreativeEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public InventoryCreativeEvent(InventoryView what, SlotType type, int slot, ItemStack newItem) {
    super(what, type, slot, ClickType.CREATIVE, InventoryAction.PLACE_ALL);
    this.item = newItem;
}
 
Example #15
Source File: CraftItemEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftItemEvent(Recipe recipe, InventoryView what, SlotType type, int slot, ClickType click, InventoryAction action, int key) {
    super(what, type, slot, click, action, key);
    this.recipe = recipe;
}
 
Example #16
Source File: CraftItemEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public CraftItemEvent(Recipe recipe, InventoryView what, SlotType type, int slot, ClickType click, InventoryAction action) {
    super(what, type, slot, click, action);
    this.recipe = recipe;
}
 
Example #17
Source File: WarpPanel.java    From askyblock with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
    Inventory inventory = event.getInventory(); // The inventory that was clicked in
    if (inventory.getName() == null) {
        return;
    }
    // The player that clicked the item
    final Player player = (Player) event.getWhoClicked();
    String title = inventory.getTitle();
    if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
        return;
    }
    event.setCancelled(true);
    if (event.getSlotType().equals(SlotType.OUTSIDE)) {
        player.closeInventory();
        return;
    }
    if (event.getClick().equals(ClickType.SHIFT_RIGHT)) {
        player.closeInventory();
        player.updateInventory();
        return;
    }
    ItemStack clicked = event.getCurrentItem(); // The item that was clicked
    if (DEBUG)
        plugin.getLogger().info("DEBUG: inventory size = " + inventory.getSize());
    if (DEBUG)
        plugin.getLogger().info("DEBUG: clicked = " + clicked);
    if (DEBUG)
        plugin.getLogger().info("DEBUG: rawslot = " + event.getRawSlot());
    if (event.getRawSlot() >= event.getInventory().getSize() || clicked.getType() == Material.AIR) {
        return;
    }
    int panelNumber = 0;
    try {
        panelNumber = Integer.valueOf(title.substring(title.indexOf('#')+ 1));
    } catch (Exception e) {
        panelNumber = 0;
    }
    if (clicked.getItemMeta().hasDisplayName()) {
        String command = ChatColor.stripColor(clicked.getItemMeta().getDisplayName());
        if (DEBUG)
            plugin.getLogger().info("DEBUG: command = " + command);
        if (command != null) {
            if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsNext))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber+1));
            } else if (command.equalsIgnoreCase(ChatColor.stripColor(plugin.myLocale().warpsPrevious))) {
                player.closeInventory();
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warps " + (panelNumber-1));
            } else {
                player.closeInventory();
                Util.sendMessage(player, ChatColor.GREEN + plugin.myLocale(player.getUniqueId()).warpswarpToPlayersSign.replace("<player>", command));
                Util.runCommand(player, Settings.ISLANDCOMMAND + " warp " + command);
            }
        }
    }
}
 
Example #18
Source File: InventoryClickEvent.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
public InventoryClickEvent(InventoryView view, SlotType type, int slot, ClickType click, InventoryAction action, int key) {
    this(view, type, slot, click, action);
    this.hotbarKey = key;
}
 
Example #19
Source File: InventoryClickEvent.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the type of slot that was clicked.
 *
 * @return the slot type
 */
public SlotType getSlotType() {
    return slot_type;
}