Java Code Examples for org.bukkit.inventory.Inventory#getHolder()
The following examples show how to use
org.bukkit.inventory.Inventory#getHolder() .
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: WorthListener.java From factions-top with MIT License | 6 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void checkWorth(InventoryOpenEvent event) { // Do nothing if a player did not open the inventory or if chest events // are disabled. if (!(event.getPlayer() instanceof Player) || plugin.getSettings().isDisableChestEvents()) { return; } Inventory inventory = event.getInventory(); // Set all default worth values for this chest. if (inventory.getHolder() instanceof DoubleChest) { DoubleChest chest = (DoubleChest) inventory.getHolder(); checkWorth((Chest) chest.getLeftSide()); checkWorth((Chest) chest.getRightSide()); } if (inventory.getHolder() instanceof Chest) { checkWorth((Chest) inventory.getHolder()); } }
Example 2
Source File: ItemMenuListener.java From AnnihilationPro with MIT License | 6 votes |
/** * Closes all {@link ninja.amp.ampmenus.menus.ItemMenu}s currently open. */ public static void closeOpenMenus() { for (Player player : Bukkit.getOnlinePlayers()) { if (player.getOpenInventory() != null) { Inventory inventory = player.getOpenInventory() .getTopInventory(); if (inventory.getHolder() instanceof ItemMenuHolder) { player.closeInventory(); } } } }
Example 3
Source File: ItemMenu.java From AnnihilationPro with MIT License | 6 votes |
/** * Updates the {@link com.gmail.nuclearcat1337.anniPro.itemMenus.MenuItem} for a player. * * @param player * The player to update the * {@link com.gmail.nuclearcat1337.anniPro.itemMenus.MenuItem} for. */ @SuppressWarnings("deprecation") public void update(Player player) { if (player.getOpenInventory() != null) { Inventory inventory = player.getOpenInventory().getTopInventory(); if (inventory.getHolder() instanceof ItemMenuHolder && ((ItemMenuHolder) inventory.getHolder()).getMenu() .equals(this)) { apply(inventory, player); player.updateInventory(); } } }
Example 4
Source File: InventoryMenu.java From EchoPet with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInvClick(InventoryClickEvent event) { HumanEntity human = event.getWhoClicked(); if (human instanceof Player) { Player player = (Player) human; Inventory inv = event.getView().getTopInventory(); if (inv.getHolder() != null && inv.getHolder() instanceof InventoryMenu && event.getRawSlot() >= 0 && event.getRawSlot() < size) { InventoryMenu menu = (InventoryMenu) inv.getHolder(); event.setCancelled(true); MenuIcon icon = slots.get(event.getSlot()); if (icon != null) { icon.onClick(player); player.closeInventory(); } } } }
Example 5
Source File: InventoryMenu.java From SonarPet with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInvClick(InventoryClickEvent event) { HumanEntity human = event.getWhoClicked(); if (human instanceof Player) { Player player = (Player) human; Inventory inv = event.getView().getTopInventory(); if (inv.getHolder() != null && inv.getHolder() instanceof InventoryMenu && event.getRawSlot() >= 0 && event.getRawSlot() < size) { InventoryMenu menu = (InventoryMenu) inv.getHolder(); event.setCancelled(true); MenuIcon icon = slots.get(event.getSlot()); if (icon != null) { icon.onClick(player); player.closeInventory(); } } } }
Example 6
Source File: ShopInteractListener.java From ShopChest with MIT License | 5 votes |
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onInventoryClick(InventoryClickEvent e) { if (!plugin.getHologramFormat().isDynamic()) return; Inventory chestInv = e.getInventory(); if (!(chestInv.getHolder() instanceof Chest || chestInv.getHolder() instanceof DoubleChest)) { return; } Location loc = null; if (chestInv.getHolder() instanceof Chest) { loc = ((Chest) chestInv.getHolder()).getLocation(); } else if (chestInv.getHolder() instanceof DoubleChest) { loc = ((DoubleChest) chestInv.getHolder()).getLocation(); } final Shop shop = plugin.getShopUtils().getShop(loc); if (shop == null) return; new BukkitRunnable() { @Override public void run() { shop.updateHologramText(); } }.runTaskLater(plugin, 1L); }
Example 7
Source File: RefreshMenusTask.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
@Override public void run() { for (Player player : BukkitUtils.getOnlinePlayers()) { InventoryView view = player.getOpenInventory(); if (view == null) { return; } Inventory topInventory = view.getTopInventory(); if (topInventory.getHolder() instanceof MenuInventoryHolder) { MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder(); if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) { ExtendedIconMenu extMenu = (ExtendedIconMenu) menuHolder.getIconMenu(); if (extMenu.getRefreshTicks() > 0) { if (elapsedTenths % extMenu.getRefreshTicks() == 0) { extMenu.refresh(player, topInventory); } } } } } elapsedTenths++; }
Example 8
Source File: MenuUtils.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
public static void refreshMenu(Player player) { InventoryView view = player.getOpenInventory(); if (view != null) { Inventory topInventory = view.getTopInventory(); if (topInventory.getHolder() instanceof MenuInventoryHolder) { MenuInventoryHolder menuHolder = (MenuInventoryHolder) topInventory.getHolder(); if (menuHolder.getIconMenu() instanceof ExtendedIconMenu) { ((ExtendedIconMenu) menuHolder.getIconMenu()).refresh(player, topInventory); } } } }
Example 9
Source File: ItemMenu.java From AmpMenus with GNU Lesser General Public License v3.0 | 5 votes |
/** * Updates the {@link ninja.amp.ampmenus.menus.ItemMenu} for a player. * * @param player The player to update the {@link ninja.amp.ampmenus.menus.ItemMenu} for. */ @SuppressWarnings("deprecation") public void update(Player player) { if (player.getOpenInventory() != null) { Inventory inventory = player.getOpenInventory().getTopInventory(); if (inventory.getHolder() instanceof MenuHolder && ((MenuHolder) inventory.getHolder()).getMenu().equals(this)) { apply(inventory, player); player.updateInventory(); } } }
Example 10
Source File: MenuListener.java From AmpMenus with GNU Lesser General Public License v3.0 | 5 votes |
/** * Closes all {@link ninja.amp.ampmenus.menus.ItemMenu}s currently open. */ public static void closeOpenMenus() { for (Player player : Bukkit.getOnlinePlayers()) { if (player.getOpenInventory() != null) { Inventory inventory = player.getOpenInventory().getTopInventory(); if (inventory.getHolder() instanceof MenuHolder) { player.closeInventory(); } } } }
Example 11
Source File: VanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true) public void onPreBrew(InventoryClickEvent e) { Inventory inventory = e.getInventory(); if (inventory.getType() == InventoryType.BREWING && e.getRawSlot() < inventory.getSize() && inventory.getHolder() instanceof BrewingStand) { e.setCancelled(isUnallowed(SlimefunItem.getByItem(e.getCursor()))); } }
Example 12
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 13
Source File: UnitMaterial.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void onInvItemPickup(InventoryClickEvent event, Inventory fromInv, ItemStack stack) { if (fromInv.getHolder() instanceof Player) { Player player = (Player)fromInv.getHolder(); onItemFromPlayer(player, stack); } }
Example 14
Source File: ContainerAdapter.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
public static boolean isValidContainer(Inventory inventory) { if (Version.isAtLeast(Version.MC1_12_1)) { return inventory.getHolder() instanceof Container; } else { return inventory.getHolder() instanceof Chest; } }
Example 15
Source File: ItemsListener.java From UhcCore with GNU General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onHopperEvent(InventoryMoveItemEvent event) { Inventory inv = event.getDestination(); if(inv.getType().equals(InventoryType.BREWING) && GameManager.getGameManager().getConfiguration().getBanLevelTwoPotions() && inv.getHolder() instanceof BrewingStand){ Bukkit.getScheduler().runTaskLater(UhcCore.getPlugin(), new CheckBrewingStandAfterClick((BrewingStand) inv.getHolder(), null),1); } }
Example 16
Source File: UnitMaterial.java From civcraft with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("deprecation") @Override public void onInvItemDrop(InventoryClickEvent event, Inventory toInv, ItemStack stack) { if (toInv.getHolder() instanceof Player) { //A hack to make sure we are always moving the item to the player's inv. //A player inv is always on the bottom, toInv could be the 'crafting' inv toInv = event.getView().getBottomInventory(); 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; } // Reposition item to the last quickbar slot if (event.getSlot() != LAST_SLOT) { DelayMoveInventoryItem task = new DelayMoveInventoryItem(); task.fromSlot = event.getSlot(); task.toSlot = LAST_SLOT; task.inv = toInv; task.playerName = player.getName(); TaskMaster.syncTask(task); } onItemToPlayer(player, stack); } }
Example 17
Source File: CustomInventory.java From PlayerSQL with GNU General Public License v2.0 | 4 votes |
public static boolean isInstance(Inventory inventory) { return inventory.getHolder() instanceof CustomInventory; }
Example 18
Source File: Util.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
/** * Call this to check items in inventory and remove it. * * @param inv inv */ public static void inventoryCheck(@Nullable Inventory inv) { if (inv == null) { return; } if (inv.getHolder() == null) { Util.debugLog("Skipped plugin gui inventory check."); return; } new BukkitRunnable() { @Override public void run() { try { for (int i = 0; i < inv.getSize(); i++) { ItemStack itemStack = inv.getItem(i); if (itemStack == null) { continue; } if (DisplayItem.checkIsGuardItemStack(itemStack)) { // Found Item and remove it. Location location = inv.getLocation(); if (location == null) { return; // Virtual GUI } plugin .getSyncTaskWatcher() .getInventoryEditQueue() .offer(new InventoryEditContainer(inv, i, new ItemStack(Material.AIR))); Util.debugLog("Found a displayitem in an inventory, Scheduling to removal..."); MsgUtil.sendGlobalAlert( "[InventoryCheck] Found displayItem in inventory at " + location + ", Item is " + itemStack.getType().name()); } } } catch (Throwable t) { // Ignore } } }.runTaskAsynchronously(plugin); }
Example 19
Source File: ExtraBackpackGUI.java From NyaaUtils with MIT License | 4 votes |
void open(int page) { if (tainted.get()) { close(); throw new IllegalStateException(); } Player currentOpener; //如果有玩家已经打开背包 if ((currentOpener = opened.putIfAbsent(owner, opener)) != null) { if (!currentOpener.equals(opener) && opener.getOpenInventory().getTopInventory().getHolder() instanceof ExtraBackpackGUI) { //如果是管理员打开普通玩家背包 if (opener.hasPermission("nu.bp.admin") && !currentOpener.hasPermission("nu.bp.admin")) { Inventory inventory = currentOpener.getOpenInventory().getTopInventory(); if (inventory.getHolder() instanceof ExtraBackpackGUI) { // ((ExtraBackpackGUI) inventory.getHolder()).saveAll(inventory); ((ExtraBackpackGUI) inventory.getHolder()).saveAll(extraBackpack); ((ExtraBackpackGUI) inventory.getHolder()).close(); } new Message(I18n.format("user.backpack.force_opened")).send(currentOpener); } else { //如果不是管理员打开普通玩家背包,通知已经打开 new Message(I18n.format("user.backpack.already_opened")).send(opener); return; } } } currentPage = page; maxLine = plugin.cfg.bp_default_lines; extraBackpack = getInventory(owner); if (extraBackpack == null) { new Message(I18n.format("user.backpack.disabled")).send(opener); opened.remove(owner); return; } // int pageCount = (int) Math.ceil(maxLine / 6.0); // List<ExtraBackpackLine> view = lines.stream().skip(page * 6).limit(6).collect(Collectors.toList()); // int viewSize = view.size(); // if (viewSize == 0) { // new Message(I18n.format("user.backpack.invalid_page", page, pageCount)).send(opener); // opened.remove(owner); // return; // } // int size = viewSize * 9; // ItemStack[] itemStacks = view.stream().flatMap(l -> l.getItemStacks().stream()).toArray(ItemStack[]::new); // inventory.setContents(itemStacks); saveScheduled.set(-1); // opener.openInventory(inventory); opener.openInventory(extraBackpack.inventories.get(currentPage)); saveScheduled.set(0); if (daemonTask == null) { daemonTask = new BukkitRunnable() { @Override public void run() { if (!opener.isOnline() || opener.getOpenInventory().getTopInventory().getHolder() != ExtraBackpackGUI.this) { this.cancel(); new IllegalAccessException().printStackTrace(); saveScheduled.set(1); saveAll(extraBackpack); close(); } } }.runTaskTimer(plugin, 0, 0); } }
Example 20
Source File: MenuHolder.java From TabooLib with MIT License | 4 votes |
public static MenuBuilder get(Inventory inventory) { return inventory.getHolder() instanceof MenuHolder ? ((MenuHolder) inventory.getHolder()).getBuilder() : null; }