类org.bukkit.event.inventory.InventoryType.SlotType源码实例Demo

下面列出了怎么用org.bukkit.event.inventory.InventoryType.SlotType的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: Kettle   文件: InventoryClickEvent.java
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;
}
 
源代码2 项目: Kettle   文件: InventoryClickEvent.java
/**
 * 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);
}
 
源代码3 项目: Kettle   文件: InventoryClickEvent.java
/**
 * 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);
    }
}
 
源代码4 项目: Statz   文件: VillagerTradesListener.java
@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()));

}
 
源代码5 项目: Slimefun4   文件: TestBackpackListener.java
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();
}
 
源代码6 项目: Slimefun4   文件: TestBackpackListener.java
@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());
}
 
源代码7 项目: Slimefun4   文件: TestVanillaMachinesListener.java
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;
}
 
源代码8 项目: Slimefun4   文件: TestVanillaMachinesListener.java
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;
}
 
源代码9 项目: Slimefun4   文件: TestVanillaMachinesListener.java
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;
}
 
源代码10 项目: Slimefun4   文件: TestVanillaMachinesListener.java
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;
}
 
源代码11 项目: askyblock   文件: TopTen.java
@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;
    }
}
 
源代码12 项目: Kettle   文件: InventoryClickEvent.java
public InventoryClickEvent(InventoryView view, SlotType type, int slot, ClickType click, InventoryAction action, int key) {
    this(view, type, slot, click, action);
    this.hotbarKey = key;
}
 
源代码13 项目: Kettle   文件: CraftItemEvent.java
public CraftItemEvent(Recipe recipe, InventoryView what, SlotType type, int slot, ClickType click, InventoryAction action) {
    super(what, type, slot, click, action);
    this.recipe = recipe;
}
 
源代码14 项目: Kettle   文件: CraftItemEvent.java
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;
}
 
源代码15 项目: Kettle   文件: InventoryCreativeEvent.java
public InventoryCreativeEvent(InventoryView what, SlotType type, int slot, ItemStack newItem) {
    super(what, type, slot, ClickType.CREATIVE, InventoryAction.PLACE_ALL);
    this.item = newItem;
}
 
源代码16 项目: Kettle   文件: CraftInventoryView.java
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;
}
 
源代码17 项目: Thermos   文件: CraftInventoryView.java
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;
}
 
源代码18 项目: askyblock   文件: WarpPanel.java
@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);
            }
        }
    }
}
 
源代码19 项目: Kettle   文件: InventoryClickEvent.java
/**
 * Gets the type of slot that was clicked.
 *
 * @return the slot type
 */
public SlotType getSlotType() {
    return slot_type;
}
 
 类所在包
 同包方法