Java Code Examples for org.bukkit.inventory.Inventory#equals()
The following examples show how to use
org.bukkit.inventory.Inventory#equals() .
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: ChestGUIListener.java From NovaGuilds with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClick(InventoryClickEvent event) { Inventory inventory = CompatibilityUtils.getClickedInventory(event); if(inventory == null || event.getCurrentItem() == null || (!inventory.equals(event.getView().getTopInventory()) && event.getClick() != ClickType.SHIFT_LEFT && event.getClick() != ClickType.SHIFT_RIGHT)) { return; } Player player = (Player) event.getWhoClicked(); NovaPlayer nPlayer = PlayerManager.getPlayer(player); GUIInventory guiInventory = nPlayer.getGuiInventory(); if(guiInventory != null) { event.setCancelled(true); if(event.getSlot() == inventory.getSize() - 1 && event.getCurrentItem().equals(Message.INVENTORY_GUI_BACK.getItemStack())) { player.closeInventory(); return; } if(event.getCurrentItem() != null && event.getCurrentItem().getType() != Material.AIR) { guiInventory.onClick(event); } } }
Example 2
Source File: GuiListener.java From IF with The Unlicense | 5 votes |
/** * Handles clicks in inventories * * @param event the event fired * @since 0.5.4 */ @EventHandler(ignoreCancelled = true) public void onInventoryClick(@NotNull InventoryClickEvent event) { if (!(event.getInventory().getHolder() instanceof Gui)) { return; } Gui gui = (Gui) event.getInventory().getHolder(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); if (inventory == null) { gui.callOnOutsideClick(event); return; } gui.callOnGlobalClick(event); if (inventory.equals(view.getTopInventory())) { gui.callOnTopClick(event); } else { gui.callOnBottomClick(event); } if ((inventory.equals(view.getBottomInventory()) && gui.getState() == Gui.State.TOP) || event.getCurrentItem() == null) { return; } List<Pane> panes = gui.getPanes(); //loop through the panes reverse, because the pane with the highest priority (last in list) is most likely to have the correct item for (int i = panes.size() - 1; i >= 0; i--) { if (panes.get(i).click(gui, event, 0, 0, 9, gui.getRows() + 4)) break; } }
Example 3
Source File: MasonryPane.java From IF with The Unlicense | 5 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } if (x < 0 || x >= length || y < 0 || y >= height) return false; callOnClick(event); boolean success = false; for (Pane pane : panes) { success = success || pane.click(gui, event, paneOffsetX + getX(), paneOffsetY + getY(), length, height); } return success; }
Example 4
Source File: PercentageBar.java From IF with The Unlicense | 5 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } if (x < 0 || x >= length || y < 0 || y >= height) { return false; } callOnClick(event); event.setCancelled(true); int newPaneOffsetX = paneOffsetX + getX(); int newPaneOffsetY = paneOffsetY + getY(); return this.fillPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height) || this.backgroundPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height); }
Example 5
Source File: GUIListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
public boolean isCreatedGUI(Inventory inventory) { for (GUIAbstract inv : GUIManager.getSet()) { if (inventory.equals(inv.getInventory())) { return true; } } return false; }
Example 6
Source File: Trade.java From TradePlus with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onDrag(InventoryDragEvent event) { if (!(event.getWhoClicked() instanceof Player)) { return; } Player player = (Player) event.getWhoClicked(); Inventory inv = event.getInventory(); if (inv1.getViewers().contains(player) || inv2.getViewers().contains(player)) { if (accept1 && accept2) { event.setCancelled(true); return; } for (int slot : event.getInventorySlots()) { if (!InvUtils.leftSlots.contains(slot)) { event.setCancelled(true); return; } } if (event.getInventorySlots().size() > 0) { if (pl.getConfig().getBoolean("antiscam.preventchangeonaccept") && ((player.equals(player1) && accept1) || (player.equals(player2) && accept2))) { event.setCancelled(true); return; } Bukkit.getScheduler().runTaskLater(pl, this::updateInventories, 1L); click(); } } else if (inv.equals(spectatorInv)) { event.setCancelled(true); } }
Example 7
Source File: UnitMaterial.java From civcraft with GNU General Public License v2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public void onInvShiftClick(InventoryClickEvent event, Inventory fromInv, Inventory toInv, ItemStack stack) { if (fromInv.equals(toInv)) { event.setCancelled(true); event.setResult(Result.DENY); return; } if (toInv.getHolder() instanceof Player) { Player player = (Player)toInv.getHolder(); if(!validateUnitUse(player, stack)) { CivMessage.sendError(player, "You cannot use this unit because it does not belong to your civlization."); event.setCancelled(true); return; } //Prevent dropping in two unit materials. ConfigUnit unit = Unit.getPlayerUnit(player); if (unit != null) { //player already has a unit item, cancel this event. CivMessage.sendError(player, "You already are a "+unit.name+" cannot pickup another unit item."); event.setCancelled(true); event.setResult(Result.DENY); event.getView().close(); player.updateInventory(); return; } onItemToPlayer(player, stack); } else if (fromInv.getHolder() instanceof Player) { onItemFromPlayer((Player)fromInv.getHolder(), stack); } }
Example 8
Source File: PaginatedPane.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { return false; } callOnClick(event); List<Pane> panes = this.panes.get(page); if (panes == null) { return false; } boolean success = false; for (Pane pane : panes) { success = success || pane.click(gui, event, paneOffsetX + getX(), paneOffsetY + getY(), length, height); } return success; }
Example 9
Source File: StaticPane.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) return false; callOnClick(event); ItemStack itemStack = event.getCurrentItem(); if (itemStack == null) { return false; } GuiItem clickedItem = findMatchingItem(items.values(), itemStack); if (clickedItem == null) { return false; } clickedItem.callAction(event); return true; }
Example 10
Source File: OutlinePane.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView inventoryView = event.getView(); Inventory inventory = inventoryView.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(inventoryView.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) return false; callOnClick(event); ItemStack itemStack = event.getCurrentItem(); if (itemStack == null) { return false; } GuiItem item = findMatchingItem(items, itemStack); if (item == null) { return false; } item.callAction(event); return true; }
Example 11
Source File: Slider.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } if (x < 0 || x >= length || y < 0 || y >= height) { return false; } callOnClick(event); int newPaneOffsetX = paneOffsetX + getX(); int newPaneOffsetY = paneOffsetY + getY(); boolean success = this.fillPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height) || this.backgroundPane.click(gui, event, newPaneOffsetX, newPaneOffsetY, length, height); if (orientation == Orientation.HORIZONTAL) { setValue((float) (x + 1) / length); } else if (orientation == Orientation.VERTICAL) { setValue((float) (y + 1) / height); } else { throw new UnsupportedOperationException("Unknown orientation"); } gui.update(); return success; }
Example 12
Source File: CycleButton.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { return false; } callOnClick(event); panes.get(position).click(gui, event, paneOffsetX + x, paneOffsetY + y, length, height); position++; if (position == panes.size()) { position = 0; } gui.update(); return true; }
Example 13
Source File: ToggleButton.java From IF with The Unlicense | 4 votes |
@Override public boolean click(@NotNull Gui gui, @NotNull InventoryClickEvent event, int paneOffsetX, int paneOffsetY, int maxLength, int maxHeight) { int length = Math.min(this.length, maxLength); int height = Math.min(this.height, maxHeight); int slot = event.getSlot(); InventoryView view = event.getView(); Inventory inventory = view.getInventory(event.getRawSlot()); int x, y; if (inventory != null && inventory.equals(view.getBottomInventory())) { x = (slot % 9) - getX() - paneOffsetX; y = ((slot / 9) + gui.getRows() - 1) - getY() - paneOffsetY; if (slot / 9 == 0) { y = (gui.getRows() + 3) - getY() - paneOffsetY; } } else { x = (slot % 9) - getX() - paneOffsetX; y = (slot / 9) - getY() - paneOffsetY; } //this isn't our item if (x < 0 || x >= length || y < 0 || y >= height) { return false; } callOnClick(event); int newX = paneOffsetX + x; int newY = paneOffsetY + y; if (enabled) { enabledPane.click(gui, event, newX, newY, length, height); } else { disabledPane.click(gui, event, newX, newY, length, height); } toggle(); gui.update(); return true; }
Example 14
Source File: Trade.java From TradePlus with GNU General Public License v3.0 | 4 votes |
@EventHandler public void onClose(InventoryCloseEvent event) { Inventory closed = event.getInventory(); if (closed == null || closed.getSize() < 54) { return; } // I keep having issues with // identifying inventories so // trying to make sure it catches // all events if (closed.equals(inv1) || closed.equals(inv2) || inv1.getViewers().contains(event.getPlayer()) || inv2.getViewers().contains(event.getPlayer())) { if ((event.getPlayer().equals(player1) && !cancelOnClose1) || (event.getPlayer().equals(player2) && !cancelOnClose2)) { return; } giveOnCursor((Player)event.getPlayer()); if (cancelled || closed.getItem(49) == null) { return; } cancel(); pl.ongoingTrades.remove(this); if (task != null) { task.cancel(); task = null; } player1.closeInventory(); player2.closeInventory(); // Return items to them giveItemsOnLeft(inv1, player1); giveItemsOnLeft(inv2, player2); MsgUtils.send( player1, pl.getLang() .getString("cancelled", "&4&l(!) &r&4The trade was cancelled") .replace("%PLAYER%", player2.getName())); MsgUtils.send( player2, pl.getLang() .getString("cancelled", "&4&l(!) &r&4The trade was cancelled") .replace("%PLAYER%", player1.getName())); new ArrayList<>(spectatorInv.getViewers()).forEach(HumanEntity::closeInventory); } }