Java Code Examples for org.bukkit.event.inventory.InventoryType#CRAFTING
The following examples show how to use
org.bukkit.event.inventory.InventoryType#CRAFTING .
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: 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 2
Source File: AntiGriefListener.java From PGM with GNU Affero General Public License v3.0 | 6 votes |
@EventHandler(priority = EventPriority.MONITOR) public void cloneCraftingWindow(final PlayerInteractEvent event) { if (!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) { Block block = event.getClickedBlock(); if (block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) { // create the window ourself event.setCancelled(true); event.getPlayer().openWorkbench(null, true); // doesn't check reachable } } }
Example 3
Source File: EnhancedItemListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 6 votes |
/** * Prevents enhanced item from storing. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onInventoryClick(InventoryClickEvent e) { if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) { if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) { ItemStack itemMoved = e.getWhoClicked().getInventory().getItem(e.getHotbarButton()); if ((itemMoved.hasItemMeta()) && (itemMoved.getItemMeta().hasLore())) { if (itemMoved.getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { e.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked()); } } } if (e.getCurrentItem() != null) { if ((e.getCurrentItem().hasItemMeta()) && (e.getCurrentItem().getItemMeta().hasLore())) { if (e.getCurrentItem().getItemMeta().getLore().contains(Util.UNIQUEID + Util.toColor(SettingsManager.lang.getString("lore.untradeableLore")))) { e.setCancelled(true); Util.sendMessage(SettingsManager.lang.getString("messages.noStorage"), e.getWhoClicked()); } } } } }
Example 4
Source File: KitLoading.java From AnnihilationPro with MIT License | 6 votes |
@EventHandler(priority=EventPriority.HIGHEST, ignoreCancelled=true) public void StopClicking(InventoryClickEvent event) { HumanEntity entity = event.getWhoClicked(); ItemStack stack = event.getCurrentItem(); InventoryType top = event.getView().getTopInventory().getType(); if (stack != null && (entity instanceof Player)) { if (top == InventoryType.PLAYER || top == InventoryType.WORKBENCH || top == InventoryType.CRAFTING) return; if(KitUtils.isSoulbound(stack)) event.setCancelled(true); } }
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: 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: CraftInventory.java From Thermos with GNU General Public License v3.0 | 5 votes |
public InventoryType getType() { // Thanks to Droppers extending Dispensers, order is important. if (inventory instanceof net.minecraft.inventory.InventoryCrafting) { return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING; } else if (inventory instanceof net.minecraft.entity.player.InventoryPlayer) { return InventoryType.PLAYER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityDropper) { return InventoryType.DROPPER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityDispenser) { return InventoryType.DISPENSER; } else if (inventory instanceof net.minecraft.tileentity.TileEntityFurnace) { return InventoryType.FURNACE; } else if (inventory instanceof net.minecraft.inventory.ContainerEnchantTableInventory) { return InventoryType.ENCHANTING; } else if (inventory instanceof net.minecraft.tileentity.TileEntityBrewingStand) { return InventoryType.BREWING; } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) { return ((CraftInventoryCustom.MinecraftInventory) inventory).getType(); } else if (inventory instanceof net.minecraft.inventory.InventoryEnderChest) { return InventoryType.ENDER_CHEST; } else if (inventory instanceof net.minecraft.inventory.InventoryMerchant) { return InventoryType.MERCHANT; } else if (inventory instanceof net.minecraft.tileentity.TileEntityBeacon) { return InventoryType.BEACON; } else if (inventory instanceof net.minecraft.inventory.ContainerRepairInventory) { return InventoryType.ANVIL; } else if (inventory instanceof net.minecraft.tileentity.IHopper) { return InventoryType.HOPPER; } else { return InventoryType.CHEST; } }
Example 8
Source File: CraftInventoryView.java From Kettle with GNU General Public License v3.0 | 5 votes |
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
Example 9
Source File: CraftInventory.java From Kettle with GNU General Public License v3.0 | 5 votes |
public InventoryType getType() { // Thanks to Droppers extending Dispensers, order is important. if (inventory instanceof InventoryCrafting) { return inventory.getSizeInventory() >= 9 ? InventoryType.WORKBENCH : InventoryType.CRAFTING; } else if (inventory instanceof InventoryPlayer) { return InventoryType.PLAYER; } else if (inventory instanceof TileEntityDropper) { return InventoryType.DROPPER; } else if (inventory instanceof TileEntityDispenser) { return InventoryType.DISPENSER; } else if (inventory instanceof TileEntityFurnace) { return InventoryType.FURNACE; } else if (this instanceof CraftInventoryEnchanting) { return InventoryType.ENCHANTING; } else if (inventory instanceof TileEntityBrewingStand) { return InventoryType.BREWING; } else if (inventory instanceof CraftInventoryCustom.MinecraftInventory) { return ((CraftInventoryCustom.MinecraftInventory) inventory).getType(); } else if (inventory instanceof InventoryEnderChest) { return InventoryType.ENDER_CHEST; } else if (inventory instanceof InventoryMerchant) { return InventoryType.MERCHANT; } else if (inventory instanceof TileEntityBeacon) { return InventoryType.BEACON; } else if (this instanceof CraftInventoryAnvil) { return InventoryType.ANVIL; } else if (inventory instanceof IHopper) { return InventoryType.HOPPER; } else if (inventory instanceof TileEntityShulkerBox) { return InventoryType.SHULKER_BOX; } else { return InventoryType.CHEST; } }
Example 10
Source File: CraftingProtect.java From ProjectAres with GNU Affero General Public License v3.0 | 5 votes |
@EventHandler(priority = EventPriority.MONITOR) public void cloneCraftingWindow(final PlayerInteractEvent event) { if(!AntiGrief.CraftProtect.enabled()) { return; } if(!event.isCancelled() && event.getAction() == Action.RIGHT_CLICK_BLOCK && event.getPlayer().getOpenInventory().getType() == InventoryType.CRAFTING /* nothing open */) { Block block = event.getClickedBlock(); if(block != null && block.getType() == Material.WORKBENCH && !event.getPlayer().isSneaking()) { // create the window ourself event.setCancelled(true); event.getPlayer().openWorkbench(null, true); // doesn't check reachable } } }
Example 11
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 12
Source File: GUIListener.java From EnchantmentsEnhance with GNU General Public License v3.0 | 5 votes |
/** * Prevents item glitched into menu. * * @param e */ @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGH) public void onInventoryClick(InventoryClickEvent e) { if ((e.getInventory().getType() != InventoryType.CRAFTING) && (e.getInventory().getType() != InventoryType.PLAYER)) { if ((e.getClick().equals(ClickType.NUMBER_KEY)) && (e.getWhoClicked().getInventory().getItem(e.getHotbarButton()) != null)) { Player player = (Player) e.getWhoClicked(); String playerName = player.getName(); GUIAbstract gui = GUIManager.getMap().get(playerName); if (gui != null && gui.getInventory().equals(e.getInventory())) { e.setCancelled(true); } } } }
Example 13
Source File: CraftInventoryView.java From Thermos with GNU General Public License v3.0 | 5 votes |
@Override public InventoryType getType() { InventoryType type = viewing.getType(); if (type == InventoryType.CRAFTING && player.getGameMode() == GameMode.CREATIVE) { return InventoryType.CREATIVE; } return type; }
Example 14
Source File: ViewInventoryMatchModule.java From ProjectAres with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void updateMonitoredClick(final InventoryClickedEvent event) { if(event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); boolean playerInventory = event.getInventory().getType() == InventoryType.CRAFTING; // cb bug fix Inventory inventory; if(playerInventory) { inventory = player.getInventory(); } else { inventory = event.getInventory(); } invLoop: for(Map.Entry<Player, View> entry : new HashSet<>(this.views.entrySet())) { // avoid ConcurrentModificationException final Player viewer = entry.getKey(); View view = entry.getValue(); // because a player can only be viewing one inventory at a time, // this is how we determine if we have a match if(inventory.getViewers().isEmpty() || view.watched.getViewers().isEmpty() || inventory.getViewers().size() > view.watched.getViewers().size()) continue invLoop; for(int i = 0; i < inventory.getViewers().size(); i++) { if(!inventory.getViewers().get(i).equals(view.watched.getViewers().get(i))) { continue invLoop; } } // a watched user is in a chest if(view.isPlayerInventory() && !playerInventory) { inventory = view.getPlayerInventory().getHolder().getInventory(); playerInventory = true; } if(playerInventory) { this.previewPlayerInventory(viewer, (PlayerInventory) inventory); } else { this.previewInventory(viewer, inventory); } } } }
Example 15
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()); }
Example 16
Source File: CraftInventoryView.java From Thermos with GNU General Public License v3.0 | 4 votes |
public static SlotType getSlotType(InventoryView inventory, int slot) { SlotType type = SlotType.CONTAINER; if (inventory == null) return type; // Cauldron - modded inventories with no Bukkit wrapper if (slot >= 0 && slot < inventory.getTopInventory().getSize()) { switch(inventory.getType()) { case FURNACE: if (slot == 2) { type = SlotType.RESULT; } else if(slot == 1) { type = SlotType.FUEL; } else { type = SlotType.CRAFTING; } break; case BREWING: if (slot == 3) { type = SlotType.FUEL; } else { type = SlotType.CRAFTING; } break; case ENCHANTING: type = SlotType.CRAFTING; break; case WORKBENCH: case CRAFTING: if (slot == 0) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; case MERCHANT: if (slot == 2) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; case BEACON: type = SlotType.CRAFTING; break; case ANVIL: if (slot == 2) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; default: // Nothing to do, it's a CONTAINER slot } } else { if (slot == -999) { type = SlotType.OUTSIDE; } else if (inventory.getType() == InventoryType.CRAFTING) { if (slot < 9) { type = SlotType.ARMOR; } else if (slot > 35) { type = SlotType.QUICKBAR; } } else if (slot >= (inventory.countSlots() - 9)) { type = SlotType.QUICKBAR; } } return type; }
Example 17
Source File: CraftInventoryView.java From Kettle with GNU General Public License v3.0 | 4 votes |
public static SlotType getSlotType(InventoryView inventory, int slot) { SlotType type = SlotType.CONTAINER; if (slot >= 0 && slot < inventory.getTopInventory().getSize()) { switch (inventory.getType()) { case FURNACE: if (slot == 2) { type = SlotType.RESULT; } else if (slot == 1) { type = SlotType.FUEL; } else { type = SlotType.CRAFTING; } break; case BREWING: if (slot == 3) { type = SlotType.FUEL; } else { type = SlotType.CRAFTING; } break; case ENCHANTING: type = SlotType.CRAFTING; break; case WORKBENCH: case CRAFTING: if (slot == 0) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; case MERCHANT: if (slot == 2) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; case BEACON: type = SlotType.CRAFTING; break; case ANVIL: if (slot == 2) { type = SlotType.RESULT; } else { type = SlotType.CRAFTING; } break; default: // Nothing to do, it's a CONTAINER slot } } else { if (slot == -999 || slot == -1) { type = SlotType.OUTSIDE; } else if (inventory.getType() == InventoryType.CRAFTING) { // Also includes creative inventory if (slot < 9) { type = SlotType.ARMOR; } else if (slot > 35) { type = SlotType.QUICKBAR; } } else if (slot >= (inventory.countSlots() - (9 + 4 + 1))) { // Quickbar, Armor, Offhand type = SlotType.QUICKBAR; } } return type; }
Example 18
Source File: InventoryView.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * Converts a raw slot ID into its local slot ID into whichever of the two * inventories the slot points to. * <p> * If the raw slot refers to the upper inventory, it will be returned * unchanged and thus be suitable for getTopInventory().getItem(); if it * refers to the lower inventory, the output will differ from the input * and be suitable for getBottomInventory().getItem(). * * @param rawSlot The raw slot ID. * @return The converted slot ID. */ public final int convertSlot(int rawSlot) { int numInTop = getTopInventory().getSize(); // Index from the top inventory as having slots from [0,size] if (rawSlot < numInTop) { return rawSlot; } // Move down the slot index by the top size int slot = rawSlot - numInTop; // Player crafting slots are indexed differently. The matrix is caught by the first return. // Creative mode is the same, except that you can't see the crafting slots (but the IDs are still used) if (getType() == InventoryType.CRAFTING || getType() == InventoryType.CREATIVE) { /** * Raw Slots: * * 5 1 2 0 * 6 3 4 * 7 * 8 45 * 9 10 11 12 13 14 15 16 17 * 18 19 20 21 22 23 24 25 26 * 27 28 29 30 31 32 33 34 35 * 36 37 38 39 40 41 42 43 44 */ /** * Converted Slots: * * 39 1 2 0 * 38 3 4 * 37 * 36 40 * 9 10 11 12 13 14 15 16 17 * 18 19 20 21 22 23 24 25 26 * 27 28 29 30 31 32 33 34 35 * 0 1 2 3 4 5 6 7 8 */ if (slot < 4) { // Send [5,8] to [39,36] return 39 - slot; } else if (slot > 39) { // Slot lives in the extra slot section return slot; } else { // Reset index so 9 -> 0 slot -= 4; } } // 27 = 36 - 9 if (slot >= 27) { // Put into hotbar section slot -= 27; } else { // Take out of hotbar section // 9 = 36 - 27 slot += 9; } return slot; }
Example 19
Source File: TrMenuNmsModern.java From TrMenu with MIT License | 4 votes |
private Containers<?> getByInventory(Inventory inventory) { InventoryType type = inventory.getType(); int size = inventory.getSize(); if (type == InventoryType.CHEST) { if (size == 9) { return Containers.GENERIC_9X1; } else if (size == 18) { return Containers.GENERIC_9X2; } else if (size == 27) { return Containers.GENERIC_9X3; } else if (size == 36) { return Containers.GENERIC_9X4; } else if (size == 45) { return Containers.GENERIC_9X5; } else { return Containers.GENERIC_9X6; } } else if (type == InventoryType.DROPPER || type == InventoryType.DISPENSER) { return Containers.GENERIC_3X3; } else if (type == InventoryType.BARREL || type == InventoryType.ENDER_CHEST) { return Containers.GENERIC_9X3; } else if (type == InventoryType.CRAFTING || type == InventoryType.WORKBENCH) { return Containers.CRAFTING; } else if (type == InventoryType.HOPPER) { return Containers.HOPPER; } else if (type == InventoryType.LOOM) { return Containers.LOOM; } else if (type == InventoryType.ANVIL) { return Containers.ANVIL; } else if (type == InventoryType.BEACON) { return Containers.BEACON; } else if (type == InventoryType.SMOKER) { return Containers.SMOKER; } else if (type == InventoryType.BREWING) { return Containers.BREWING_STAND; } else if (type == InventoryType.FURNACE) { return Containers.FURNACE; } else if (type == InventoryType.LECTERN) { return Containers.LECTERN; } else if (type == InventoryType.MERCHANT) { return Containers.MERCHANT; } else if (type == InventoryType.ENCHANTING) { return Containers.ENCHANTMENT; } else if (type == InventoryType.GRINDSTONE) { return Containers.GRINDSTONE; } else if (type == InventoryType.CARTOGRAPHY) { return Containers.CARTOGRAPHY_TABLE; } else if (type == InventoryType.SHULKER_BOX) { return Containers.SHULKER_BOX; } else if (type == InventoryType.STONECUTTER) { return Containers.STONECUTTER; } else if (type == InventoryType.BLAST_FURNACE) { return Containers.BLAST_FURNACE; } else { return Containers.GENERIC_3X3; } }
Example 20
Source File: ViewInventoryMatchModule.java From PGM with GNU Affero General Public License v3.0 | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void updateMonitoredClick(final InventoryClickedEvent event) { if (event.getWhoClicked() instanceof Player) { Player player = (Player) event.getWhoClicked(); boolean playerInventory = event.getInventory().getType() == InventoryType.CRAFTING; // cb bug fix Inventory inventory; if (playerInventory) { inventory = player.getInventory(); } else { inventory = event.getInventory(); } invLoop: for (Map.Entry<String, InventoryTrackerEntry> entry : new HashSet<>( this.monitoredInventories.entrySet())) { // avoid ConcurrentModificationException String pl = entry.getKey(); InventoryTrackerEntry tracker = entry.getValue(); // because a player can only be viewing one inventory at a time, // this is how we determine if we have a match if (inventory.getViewers().isEmpty() || tracker.getWatched().getViewers().isEmpty() || inventory.getViewers().size() > tracker.getWatched().getViewers().size()) continue invLoop; for (int i = 0; i < inventory.getViewers().size(); i++) { if (!inventory.getViewers().get(i).equals(tracker.getWatched().getViewers().get(i))) { continue invLoop; } } // a watched user is in a chest if (tracker.isPlayerInventory() && !playerInventory) { inventory = tracker.getPlayerInventory().getHolder().getInventory(); playerInventory = true; } if (playerInventory) { this.previewPlayerInventory( Bukkit.getServer().getPlayerExact(pl), (PlayerInventory) inventory); } else { this.previewInventory(Bukkit.getServer().getPlayerExact(pl), inventory); } } } }