Java Code Examples for org.bukkit.event.inventory.InventoryOpenEvent#isCancelled()
The following examples show how to use
org.bukkit.event.inventory.InventoryOpenEvent#isCancelled() .
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: CraftEventFactory.java From Kettle with GNU General Public License v3.0 | 6 votes |
public static Container callInventoryOpenEvent(EntityPlayerMP player, Container container, boolean cancelled) { if (player.openContainer != player.inventoryContainer) { // fire INVENTORY_CLOSE if one already open player.connection.processCloseWindow(new CPacketCloseWindow(player.openContainer.windowId)); } CraftServer server = player.world.getServer(); CraftPlayer craftPlayer = player.getBukkitEntity(); player.openContainer.transferTo(container, craftPlayer); InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView()); event.setCancelled(cancelled); server.getPluginManager().callEvent(event); if (event.isCancelled()) { container.transferTo(player.openContainer, craftPlayer); return null; } return container; }
Example 2
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryOpen(InventoryOpenEvent event) { if (event.isCancelled() || !(event.getPlayer() instanceof Player)) { return; } Player player = (Player) event.getPlayer(); if (Main.isPlayerInGame(player)) { GamePlayer gProfile = Main.getPlayerGameProfile(player); if (gProfile.getGame().getStatus() == GameStatus.RUNNING) { if (gProfile.isSpectator) { // TODO spectator compass exclude event.setCancelled(true); return; } if (event.getInventory().getType() == InventoryType.ENCHANTING || event.getInventory().getType() == InventoryType.CRAFTING || event.getInventory().getType() == InventoryType.ANVIL || event.getInventory().getType() == InventoryType.BREWING || event.getInventory().getType() == InventoryType.FURNACE || event.getInventory().getType() == InventoryType.WORKBENCH) { if (!gProfile.getGame().getOriginalOrInheritedCrafting()) { event.setCancelled(true); } } } } }
Example 3
Source File: PlayerListener.java From BedWars with GNU Lesser General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryOpen(InventoryOpenEvent event) { if (event.isCancelled() || !(event.getPlayer() instanceof Player)) { return; } Player player = (Player) event.getPlayer(); if (Main.isPlayerInGame(player)) { GamePlayer gProfile = Main.getPlayerGameProfile(player); if (gProfile.getGame().getStatus() == GameStatus.RUNNING) { if (gProfile.isSpectator) { // TODO spectator compass exclude event.setCancelled(true); return; } if (event.getInventory().getType() == InventoryType.ENCHANTING || event.getInventory().getType() == InventoryType.CRAFTING || event.getInventory().getType() == InventoryType.ANVIL || event.getInventory().getType() == InventoryType.BREWING || event.getInventory().getType() == InventoryType.FURNACE || event.getInventory().getType() == InventoryType.WORKBENCH) { if (!gProfile.getGame().getOriginalOrInheritedCrafting()) { event.setCancelled(true); } } } } }
Example 4
Source File: CraftEventFactory.java From Thermos with GNU General Public License v3.0 | 5 votes |
public static net.minecraft.inventory.Container callInventoryOpenEvent(net.minecraft.entity.player.EntityPlayerMP player, net.minecraft.inventory.Container container, boolean closeInv) { if (player.openContainer != player.inventoryContainer && closeInv) { // fire INVENTORY_CLOSE if one already open // Cauldron end player.playerNetServerHandler.processCloseWindow(new net.minecraft.network.play.client.C0DPacketCloseWindow(player.openContainer.windowId)); } CraftServer server = player.worldObj.getServer(); CraftPlayer craftPlayer = player.getBukkitEntity(); // Cauldron start - vanilla compatibility try { player.openContainer.transferTo(container, craftPlayer); } catch (AbstractMethodError e) { // do nothing } // Cauldron end InventoryOpenEvent event = new InventoryOpenEvent(container.getBukkitView()); if (container.getBukkitView() != null) server.getPluginManager().callEvent(event); // Cauldron - allow vanilla mods to bypass if (event.isCancelled()) { container.transferTo(player.openContainer, craftPlayer); // Cauldron start - handle close for modded containers if (!closeInv) { // fire INVENTORY_CLOSE if one already open player.openContainer = container; // make sure the right container is processed player.closeScreen(); player.openContainer = player.inventoryContainer; } // Cauldron end return null; } return container; }