Java Code Examples for org.bukkit.event.inventory.InventoryOpenEvent#setCancelled()
The following examples show how to use
org.bukkit.event.inventory.InventoryOpenEvent#setCancelled() .
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: LWCPlayerListener.java From Modern-LWC with MIT License | 6 votes |
@EventHandler public void storageMinecraftInventoryOpen(InventoryOpenEvent event) { InventoryHolder holder = event.getInventory().getHolder(); Player player = (Player) event.getPlayer(); if ((!(holder instanceof StorageMinecart)) && (!(holder instanceof HopperMinecart))) { return; } Entity entity = (Entity) holder; if (plugin.getLWC().isProtectable(entity.getType())) { if (!plugin.getLWC().hasPermission(player, "lwc.protect") && plugin.getLWC().hasPermission(player, "lwc.deny") && !plugin.getLWC().isAdmin(player) && !plugin.getLWC().isMod(player)) { plugin.getLWC().sendLocale(player, "protection.interact.error.blocked"); event.setCancelled(true); return; } if (onPlayerEntityInteract((Player) event.getPlayer(), entity, event.isCancelled())) { event.setCancelled(true); } } }
Example 3
Source File: ListenerInventories.java From CombatLogX with GNU General Public License v3.0 | 6 votes |
@EventHandler(priority=EventPriority.HIGH, ignoreCancelled=true) public void onOpenInventory(InventoryOpenEvent e) { FileConfiguration config = this.expansion.getConfig("cheat-prevention.yml"); if(!config.getBoolean("inventories.close-on-tag")) return; HumanEntity human = e.getPlayer(); if(!(human instanceof Player)) return; Player player = (Player) human; ICombatManager manager = this.plugin.getCombatManager(); if(!manager.isInCombat(player)) return; e.setCancelled(true); String message = this.plugin.getLanguageMessageColoredWithPrefix("cheat-prevention.inventory.no-opening"); this.plugin.sendMessage(player, message); }
Example 4
Source File: ExploitEvents.java From uSkyBlock with GNU General Public License v3.0 | 6 votes |
@EventHandler public void onVillagerTrade(InventoryOpenEvent event) { if (!plugin.getWorldManager().isSkyAssociatedWorld(event.getPlayer().getWorld())) { return; } if (!(event.getPlayer() instanceof Player)) { return; } if (!anyVillagerTradingAllowed && event.getInventory().getType() == InventoryType.MERCHANT) { event.setCancelled(true); event.getPlayer().sendMessage(tr("\u00a7eVillager-trading isn't allowed.")); return; } if (visitorVillagerTradingProtected && event.getPlayer() instanceof Player && !(event.getPlayer().hasPermission("usb.mod.bypassprotection")) && event.getInventory().getType() == InventoryType.MERCHANT && !plugin.playerIsOnIsland((Player)event.getPlayer())) { event.setCancelled(true); event.getPlayer().sendMessage(tr("\u00a7eTrading isn't allowed on other islands. Do it in spawn.")); } }
Example 5
Source File: PlayerListener.java From civcraft with GNU General Public License v2.0 | 6 votes |
@EventHandler(priority = EventPriority.HIGHEST) public void onInventoryOpenEvent(InventoryOpenEvent event) { if (event.getInventory() instanceof DoubleChestInventory) { DoubleChestInventory doubleInv = (DoubleChestInventory)event.getInventory(); Chest leftChest = (Chest)doubleInv.getHolder().getLeftSide(); /*Generate a new player 'switch' event for the left and right chests. */ PlayerInteractEvent interactLeft = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, leftChest.getBlock(), null); BlockListener.OnPlayerSwitchEvent(interactLeft); if (interactLeft.isCancelled()) { event.setCancelled(true); return; } Chest rightChest = (Chest)doubleInv.getHolder().getRightSide(); PlayerInteractEvent interactRight = new PlayerInteractEvent((Player)event.getPlayer(), Action.RIGHT_CLICK_BLOCK, null, rightChest.getBlock(), null); BlockListener.OnPlayerSwitchEvent(interactRight); if (interactRight.isCancelled()) { event.setCancelled(true); return; } } }
Example 6
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 7
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 8
Source File: NPCInteractions.java From EliteMobs with GNU General Public License v3.0 | 5 votes |
@EventHandler public void onInventoryOpen(InventoryOpenEvent event) { if (!event.getInventory().getType().equals(InventoryType.MERCHANT)) return; for (NPCEntity npcEntity : EntityTracker.getNPCEntities()) if (event.getInventory().getName().equals(npcEntity.getName())) { event.setCancelled(true); return; } }
Example 9
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 10
Source File: PlayerListener.java From AuthMeReloaded with GNU General Public License v3.0 | 5 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlayerInventoryOpen(InventoryOpenEvent event) { final HumanEntity player = event.getPlayer(); if (listenerService.shouldCancelEvent(player) && !isInventoryWhitelisted(event.getView())) { event.setCancelled(true); /* * @note little hack cause InventoryOpenEvent cannot be cancelled for * real, cause no packet is sent to server by client for the main inv */ bukkitService.scheduleSyncDelayedTask(player::closeInventory, 1); } }
Example 11
Source File: PlayerLimitListener.java From BukkitDevelopmentNote with Apache License 2.0 | 4 votes |
@EventHandler public void onPlayerInventory(InventoryOpenEvent e) { e.setCancelled(needCancelled(e.getPlayer().getName())); }
Example 12
Source File: PlayerListener.java From BedwarsRel with GNU General Public License v3.0 | 4 votes |
@EventHandler public void openInventory(InventoryOpenEvent ioe) { if (!(ioe.getPlayer() instanceof Player)) { return; } Player player = (Player) ioe.getPlayer(); Game game = BedwarsRel.getInstance().getGameManager().getGameOfPlayer(player); if (game == null) { return; } if (game.getState() != GameState.RUNNING) { return; } if (ioe.getInventory().getType() == InventoryType.ENCHANTING || ioe.getInventory().getType() == InventoryType.BREWING || (ioe.getInventory().getType() == InventoryType.CRAFTING && !BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false))) { ioe.setCancelled(true); return; } else if (ioe.getInventory().getType() == InventoryType.CRAFTING && BedwarsRel.getInstance().getBooleanConfig("allow-crafting", false)) { return; } if (game.isSpectator(player)) { if (ioe.getInventory().getName().equals(BedwarsRel._l(player, "ingame.spectator"))) { return; } ioe.setCancelled(true); } if (ioe.getInventory().getHolder() == null) { return; } if (game.getRegion().getInventories().contains(ioe.getInventory())) { return; } game.getRegion().addInventory(ioe.getInventory()); }