org.bukkit.inventory.InventoryView Java Examples
The following examples show how to use
org.bukkit.inventory.InventoryView.
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: WindowManager.java From ProjectAres with GNU Affero General Public License v3.0 | 6 votes |
/** * Register the given {@link WindowListener} to receive notifications about the given {@link InventoryView}. */ public InventoryView registerWindow(WindowListener listener, InventoryView window) { final Player player = (Player) window.getPlayer(); final View old = views.get(player); if(old == null || !old.window.equals(window)) { if(old != null) { old.notifyClose(); } final View view = new View(player, window, listener); views.put(player, view); view.notifyOpen(); } return window; }
Example #2
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 6 votes |
private PrepareItemCraftEvent mockPreCraftingEvent(ItemStack item) { Player player = server.addPlayer(); CraftingInventory inv = Mockito.mock(CraftingInventory.class); MutableObject result = new MutableObject(new ItemStack(Material.EMERALD)); Mockito.doAnswer(invocation -> { ItemStack argument = invocation.getArgument(0); result.setValue(argument); return null; }).when(inv).setResult(Mockito.any()); Mockito.when(inv.getResult()).thenAnswer(invocation -> result.getValue()); Mockito.when(inv.getContents()).thenReturn(new ItemStack[] { null, null, item, null, null, null, null, null, null }); InventoryView view = player.openInventory(inv); PrepareItemCraftEvent event = new PrepareItemCraftEvent(inv, view, false); listener.onPrepareCraft(event); return event; }
Example #3
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 #4
Source File: InventoryDragEvent.java From Kettle with GNU General Public License v3.0 | 6 votes |
public InventoryDragEvent(InventoryView what, ItemStack newCursor, ItemStack oldCursor, boolean right, Map<Integer, ItemStack> slots) { super(what); Validate.notNull(oldCursor); Validate.notNull(slots); type = right ? DragType.SINGLE : DragType.EVEN; this.newCursor = newCursor; this.oldCursor = oldCursor; this.addedItems = slots; ImmutableSet.Builder<Integer> b = ImmutableSet.builder(); for (Integer slot : slots.keySet()) { b.add(what.convertSlot(slot)); } this.containerSlots = b.build(); }
Example #5
Source File: PlayerInteractListener.java From SkyWarsReloaded with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onInventoryClose(InventoryCloseEvent e) { Inventory inv = e.getInventory(); InventoryView inView = e.getPlayer().getOpenInventory(); if (inView.getTitle().equals(new Messaging.MessageFormatter().format("event.crateInv"))) { for (GameMap gMap: GameMap.getPlayableArenas(GameType.ALL)) { for (Crate crate: gMap.getCrates()) { if(crate.getInventory().equals(inv) && inv.getViewers().size() <= 1) { if (SkyWarsReloaded.getNMS().getVersion() < 9) { e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.valueOf("CHEST_CLOSE"), 1, 1); } else { e.getPlayer().getWorld().playSound(e.getPlayer().getLocation(), Sound.BLOCK_CHEST_CLOSE, 1, 1); } SkyWarsReloaded.getNMS().playEnderChestAction(e.getPlayer().getWorld().getBlockAt(crate.getLocation()), false); return; } } } } else if (inView.getTitle().contains("chest.yml")) { SkyWarsReloaded.getCM().save(inView.getTitle()); } }
Example #6
Source File: CraftContainer.java From Kettle with GNU General Public License v3.0 | 6 votes |
public CraftContainer(final Inventory inventory, final EntityPlayer player, int id) { this(new InventoryView() { @Override public Inventory getTopInventory() { return inventory; } @Override public Inventory getBottomInventory() { return getPlayer().getInventory(); } @Override public HumanEntity getPlayer() { return player.getBukkitEntity(); } @Override public InventoryType getType() { return inventory.getType(); } }, player, id); }
Example #7
Source File: CraftContainer.java From Thermos with GNU General Public License v3.0 | 6 votes |
public CraftContainer(final Inventory inventory, final HumanEntity player, int id) { this(new InventoryView() { @Override public Inventory getTopInventory() { return inventory; } @Override public Inventory getBottomInventory() { return player.getInventory(); } @Override public HumanEntity getPlayer() { return player; } @Override public InventoryType getType() { return inventory.getType(); } }, id); }
Example #8
Source File: CraftHumanEntity.java From Thermos with GNU General Public License v3.0 | 6 votes |
public InventoryView openWorkbench(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.WORKBENCH) { return null; } } if (location == null) { location = getLocation(); } getHandle().displayGUIWorkbench(location.getBlockX(), location.getBlockY(), location.getBlockZ()); if (force) { getHandle().openContainer.checkReachable = false; } return getHandle().openContainer.getBukkitView(); }
Example #9
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 #10
Source File: CraftHumanEntity.java From Thermos with GNU General Public License v3.0 | 6 votes |
public InventoryView openEnchanting(Location location, boolean force) { if (!force) { Block block = location.getBlock(); if (block.getType() != Material.ENCHANTMENT_TABLE) { return null; } } if (location == null) { location = getLocation(); } getHandle().displayGUIEnchantment(location.getBlockX(), location.getBlockY(), location.getBlockZ(), null); if (force) { getHandle().openContainer.checkReachable = false; } return getHandle().openContainer.getBukkitView(); }
Example #11
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldAllowInventoryOpen() { // given HumanEntity player = mock(Player.class); InventoryView transaction = mock(InventoryView.class); InventoryOpenEvent event = new InventoryOpenEvent(transaction); given(event.getPlayer()).willReturn(player); given(listenerService.shouldCancelEvent(player)).willReturn(false); // when listener.onPlayerInventoryOpen(event); // then assertThat(event.isCancelled(), equalTo(false)); verifyNoInteractions(bukkitService); }
Example #12
Source File: War.java From Crazy-Crates with MIT License | 6 votes |
public static void openWarCrate(Player player, Crate crate, KeyType keyType, boolean checkHand) { String crateName = Methods.sanitizeColor(crate.getFile().getString(crateNameString)); Inventory inv = Bukkit.createInventory(null, 9, crateName); setRandomPrizes(player, inv, crate, crateName); InventoryView inventoryView = player.openInventory(inv); canPick.put(player, false); canClose.put(player, false); if (!cc.takeKeys(1, player, crate, keyType, checkHand)) { Methods.failedToTakeKey(player, crate); cc.removePlayerFromOpeningList(player); canClose.remove(player); canPick.remove(player); return; } startWar(player, inv, crate, inventoryView.getTitle()); }
Example #13
Source File: PlayerListenerTest.java From AuthMeReloaded with GNU General Public License v3.0 | 6 votes |
@Test public void shouldCancelInventoryOpen() { // given HumanEntity player = mock(Player.class); InventoryView transaction = mock(InventoryView.class); given(transaction.getTitle()).willReturn("Spawn"); given(settings.getProperty(RestrictionSettings.UNRESTRICTED_INVENTORIES)).willReturn(Collections.emptySet()); InventoryOpenEvent event = new InventoryOpenEvent(transaction); given(event.getPlayer()).willReturn(player); given(listenerService.shouldCancelEvent(player)).willReturn(true); setBukkitServiceToScheduleSyncDelayedTaskWithDelay(bukkitService); // when listener.onPlayerInventoryOpen(event); // then assertThat(event.isCancelled(), equalTo(true)); verify(player).closeInventory(); }
Example #14
Source File: AnnouncerCache.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
/** * @param gui the gui * @return the announcer that has the GUI */ public Announcer getByGUI(InventoryView gui) { for (Announcer announcer : announcers) { if ((ChatColor.DARK_RED + announcer.getName()).equals(gui.getTitle())) { return announcer; } } return null; }
Example #15
Source File: SilentOpenChest.java From SuperVanish with Mozilla Public License 2.0 | 5 votes |
private boolean isShulkerBox(InventoryView inv) { try { return inv.getType() == InventoryType.SHULKER_BOX; } catch (NoSuchFieldError e) { return false; } }
Example #16
Source File: RewardListener.java From DungeonsXL with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryOpen(InventoryOpenEvent event) { if (!(event.getPlayer() instanceof Player)) { return; } InventoryView inventory = event.getView(); DGameWorld gameWorld = (DGameWorld) plugin.getGameWorld(event.getPlayer().getWorld()); if (gameWorld == null) { return; } if (!(ContainerAdapter.isValidContainer(inventory.getTopInventory()))) { return; } for (RewardChest rewardChest : gameWorld.getRewardChests()) { if (!rewardChest.getBlock().equals(ContainerAdapter.getHolderBlock(inventory.getTopInventory().getHolder()))) { continue; } rewardChest.onOpen((Player) event.getPlayer()); event.setCancelled(true); break; } if (!plugin.getMainConfig().getOpenInventories() && !DPermission.hasPermission(event.getPlayer(), DPermission.INSECURE)) { World world = event.getPlayer().getWorld(); if (event.getInventory().getType() != InventoryType.CREATIVE && plugin.getEditWorld(world) != null) { event.setCancelled(true); } } }
Example #17
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
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 #18
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 #19
Source File: CompatibilityUtils.java From NovaGuilds with GNU General Public License v3.0 | 5 votes |
/** * Gets clicked inventory * For API older than 1.8 * * @param event inventory click event * @return inventory */ public static Inventory getClickedInventory(InventoryClickEvent event) { int slot = event.getRawSlot(); InventoryView view = event.getView(); if(slot < 0) { return null; } else if(view.getTopInventory() != null && slot < view.getTopInventory().getSize()) { return view.getTopInventory(); } else { return view.getBottomInventory(); } }
Example #20
Source File: MenuEventsTest.java From uSkyBlock with GNU General Public License v3.0 | 5 votes |
private InventoryClickEvent getEvent(InventoryHolder holder) { // These values are not checked anywhere. InventoryView inventoryView = mock(InventoryView.class); InventoryType.SlotType slotType = InventoryType.SlotType.QUICKBAR; ClickType clickType = ClickType.LEFT; InventoryAction inventoryAction = InventoryAction.NOTHING; Inventory fakeInventory = mock(Inventory.class); doReturn(holder).when(fakeInventory).getHolder(); doReturn(fakeInventory).when(inventoryView).getTopInventory(); return new InventoryClickEvent(inventoryView, slotType, 1, clickType, inventoryAction); }
Example #21
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 #22
Source File: InventoryClickEvent.java From Kettle with GNU General Public License v3.0 | 5 votes |
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 #23
Source File: CraftContainer.java From Thermos with GNU General Public License v3.0 | 5 votes |
public CraftContainer(InventoryView view, int id) { this.view = view; this.windowId = id; // TODO: Do we need to check that it really is a CraftInventory? net.minecraft.inventory.IInventory top = ((CraftInventory)view.getTopInventory()).getInventory(); net.minecraft.inventory.IInventory bottom = ((CraftInventory)view.getBottomInventory()).getInventory(); cachedType = view.getType(); cachedTitle = view.getTitle(); cachedSize = getSize(); setupSlots(top, bottom); }
Example #24
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 #25
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 #26
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 #27
Source File: InventoryForItemStorage.java From NBTEditor with GNU General Public License v3.0 | 5 votes |
@Override protected void inventoryDrag(InventoryDragEvent event) { InventoryView view = event.getView(); for (int slot : event.getRawSlots()) { if (view.getInventory(slot).getType() != InventoryType.PLAYER) { event.setCancelled(true); return; } } }
Example #28
Source File: RegionsTests.java From Civs with GNU General Public License v3.0 | 5 votes |
@Test public void regionShouldNotBeCreatedIfNotAllReqs() { loadRegionTypeCobble2(); InventoryView transaction = mock(InventoryView.class); when(transaction.getPlayer()).thenReturn(TestUtil.player); InventoryCloseEvent inventoryCloseEvent = new InventoryCloseEvent(transaction); BlockPlaceEvent event3 = mock(BlockPlaceEvent.class); when(event3.getBlockPlaced()).thenReturn(TestUtil.block4); ItemStack cobbleStack = TestUtil.createItemStack(Material.COBBLESTONE); doReturn(cobbleStack).when(event3).getItemInHand(); BlockPlaceEvent event2 = mock(BlockPlaceEvent.class); when(event2.getBlockPlaced()).thenReturn(TestUtil.block2); doReturn(cobbleStack).when(event2).getItemInHand(); BlockPlaceEvent event1 = mock(BlockPlaceEvent.class); when(event1.getPlayer()).thenReturn(TestUtil.player); when(event1.getBlockPlaced()).thenReturn(TestUtil.blockUnique); doReturn(TestUtil.createUniqueItemStack(Material.CHEST, "Civs Cobble")).when(event1).getItemInHand(); MenuManager.getInstance().onInventoryClose(inventoryCloseEvent); RegionListener regionListener = new RegionListener(); regionListener.onBlockPlace(event2); regionListener.onBlockPlace(event3); regionListener.onBlockPlace(event1); assertNull(RegionManager.getInstance().getRegionAt(TestUtil.blockUnique.getLocation())); }
Example #29
Source File: WindowListener.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
/** * Called when an open window is clicked. */ default boolean windowClicked(InventoryView window, Inventory inventory, ClickType clickType, InventoryType.SlotType slotType, int slotIndex, @Nullable ItemStack item) { return false; }
Example #30
Source File: TestVanillaMachinesListener.java From Slimefun4 with GNU General Public License v3.0 | 5 votes |
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; }