Java Code Examples for org.bukkit.entity.Player#getOpenInventory()
The following examples show how to use
org.bukkit.entity.Player#getOpenInventory() .
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: 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 2
Source File: VaultOperations.java From PlayerVaults with GNU General Public License v3.0 | 6 votes |
/** * Sets whether or not player vaults are locked. If set to true, this will kick anyone who is currently using their * vaults out. * * @param locked true for locked, false otherwise */ public static void setLocked(boolean locked) { LOCKED.set(locked); if (locked) { for (Player player : PlayerVaults.getInstance().getServer().getOnlinePlayers()) { if (player.getOpenInventory() != null) { InventoryView view = player.getOpenInventory(); if (view.getTopInventory().getHolder() instanceof VaultHolder) { player.closeInventory(); player.sendMessage(Lang.TITLE + Lang.LOCKED.toString()); } } } } }
Example 3
Source File: TradeInventoryListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@Override public void run() { try { Player otherPlayer = CivGlobal.getPlayer(otherResident); if (otherPlayer.getOpenInventory() != this.otherInventory) { return; } if (otherInventory != null) { int k = OTHERS_SLOTS_START; for (int i = MY_SLOTS_START; i < MY_SLOTS_END; i++) { otherInventory.setItem(k, sourceInventory.getItem(i)); k++; } } } catch (CivException e) { } }
Example 4
Source File: ClearInventoryAction.java From UHC with MIT License | 6 votes |
@Override protected void run(Player player) { final PlayerInventory inv = player.getInventory(); // clear main inventory contents = inv.getContents(); inv.clear(); // clear armour slots armourContents = inv.getArmorContents(); inv.setArmorContents(null); // clear if they have something on their cursour currently onCursor = player.getItemOnCursor(); player.setItemOnCursor(new ItemStack(Material.AIR)); // if they have a crafting inventory open clear items from it too // stops storing items in crafting slots bypassing clear inventories final InventoryView openInventory = player.getOpenInventory(); if (openInventory.getType() == InventoryType.CRAFTING) { crafting = Optional.of(openInventory.getTopInventory().getContents()); openInventory.getTopInventory().clear(); } else { crafting = Optional.absent(); } }
Example 5
Source File: ListenerInventories.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true) public void onTag(PlayerTagEvent e) { Player player = e.getPlayer(); InventoryView openView = player.getOpenInventory(); if(openView == null) return; Inventory topInv = openView.getTopInventory(); if(topInv == null) return; InventoryType type = openView.getType(); if(type == InventoryType.CRAFTING) return; player.closeInventory(); String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.force-closed"); this.plugin.sendMessage(player, message); }
Example 6
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 7
Source File: IconMenu.java From SkyWarsReloaded with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") public void update(Player player) { InventoryView inventory = player.getOpenInventory(); if (inventory != null) { for (int iii = 0; iii < this.optionIcons.length; iii++) { if (this.optionIcons[iii] != null) { inventory.setItem(iii, this.optionIcons[iii]); } } player.updateInventory(); } }
Example 8
Source File: TradeInventoryListener.java From civcraft with GNU General Public License v2.0 | 5 votes |
@Override public void run() { try { Player otherPlayer = CivGlobal.getPlayer(otherResident); if (otherPlayer.getOpenInventory() != otherInventory) { return; } if (otherInventory != null) { otherInventory.setItem(destSlot, sourceInventory.getItem(sourceSlot)); } } catch (CivException e) { } }
Example 9
Source File: ExtraBackpackGUI.java From NyaaUtils with MIT License | 5 votes |
public static void closeAll() { Collection<Player> openers = opened.values(); for (Player p : openers) { InventoryView view = p.getOpenInventory(); Inventory inventory = view.getTopInventory(); if (inventory.getHolder() instanceof ExtraBackpackGUI) { ExtraBackpackGUI holder = (ExtraBackpackGUI) inventory.getHolder(); // holder.saveAll(inventory); holder.saveAll(holder.extraBackpack); holder.close(); } } }
Example 10
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@Test public void testOpenBackpack() throws InterruptedException { Player player = server.addPlayer(); PlayerBackpack backpack = openMockBackpack(player, "TEST_OPEN_BACKPACK", 27); InventoryView view = player.getOpenInventory(); Assertions.assertEquals(backpack.getInventory(), view.getTopInventory()); }
Example 11
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
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 12
Source File: TestBackpackListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
@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 13
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 14
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 15
Source File: ChestCommands.java From ChestCommands with GNU General Public License v3.0 | 5 votes |
public static void closeAllMenus() { for (Player player : BukkitUtils.getOnlinePlayers()) { if (player.getOpenInventory() != null) { if (player.getOpenInventory().getTopInventory().getHolder() instanceof MenuInventoryHolder || player.getOpenInventory().getBottomInventory().getHolder() instanceof MenuInventoryHolder) { player.closeInventory(); } } } }
Example 16
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 17
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++; }