@EventHandler(priority = EventPriority.MONITOR) public void onInventoryCraft(InventoryCraftEvent event) { // make sure plugin is enabled if (!plugin.isEnabled()) return; // make sure event is not canceled if (event.isCancelled()) return; // restricted area multiplier double multiplier = plugin.getJobsConfiguration().getRestrictedMultiplier(event.getPlayer()); if (event.getResult() == null) return; Player player = event.getPlayer(); if (plugin.hasWorldPermission(player, player.getWorld())) { plugin.getJobsPlayer(player.getName()).crafted(event.getResult(), multiplier); } }
@Override public void a(Packet102WindowClick packet) { if (this.player.dead) return; if (this.player.activeContainer.windowId == packet.a && this.player.activeContainer.c(this.player)) { Inventory inventory = getActiveInventory(); CraftPlayer player = (CraftPlayer) this.player.getBukkitEntity(); ItemStack before = ItemStack.b(packet.e); ItemStack cursorBefore = this.player.inventory.l(); SpoutCraftItemStack slot = SpoutCraftItemStack.fromItemStack(before); SpoutCraftItemStack cursor = SpoutCraftItemStack.fromItemStack(cursorBefore); InventorySlotType type = getActiveInventorySlotType(packet.b); boolean clickSuccessful = true; final int windowId = packet.a; // alert of a newly opened inventory if (!activeInventory) { activeInventory = true; InventoryOpenEvent event = new InventoryOpenEvent(player, inventory, getDefaultInventory(), activeLocation); Bukkit.getServer().getPluginManager().callEvent(event); if (event.isCancelled()) { this.player.D(); activeInventory = false; activeLocation = null; return; } } // Fire InventoryChange or InventoryCraft event if (packet.b != -999) { if (inventory instanceof CraftingInventory) { CraftingInventory crafting = (CraftingInventory) inventory; InventoryCrafting recipe = null; if (inventory instanceof SpoutCraftingInventory) { recipe = ((SpoutCraftingInventory) crafting).getMatrixHandle(); } else { recipe = (InventoryCrafting) ((SpoutCraftInventoryPlayer) crafting).getMatrixHandle(); } SpoutCraftItemStack craftResult = SpoutCraftItemStack.fromItemStack(CraftingManager.getInstance().craft(recipe)); SpoutCraftItemStack[] recipeContents = new SpoutCraftItemStack[recipe.getSize()]; for (int i = 0; i < recipe.getSize(); i++) { org.bukkit.inventory.ItemStack temp = crafting.getMatrix()[i]; recipeContents[i] = SpoutCraftItemStack.getCraftItemStack(temp); } SpoutCraftItemStack[][] matrix = null; if (recipe.getSize() == 4) { matrix = new SpoutCraftItemStack[][] { Arrays.copyOfRange(recipeContents, 0, 2), Arrays.copyOfRange(recipeContents, 2, 4) }; } else if (recipe.getSize() == 9) { matrix = new SpoutCraftItemStack[][] { Arrays.copyOfRange(recipeContents, 0, 3), Arrays.copyOfRange(recipeContents, 3, 6), Arrays.copyOfRange(recipeContents, 6, 9) }; } // Clicking to grab the crafting result if (type == InventorySlotType.RESULT) { InventoryCraftEvent craftEvent = new InventoryCraftEvent( this.getPlayer(), crafting, this.activeLocation, type, packet.b, matrix, craftResult, cursor, packet.c == 0, packet.f); Bukkit.getServer().getPluginManager().callEvent(craftEvent); craftEvent.getInventory().setResult(craftEvent.getResult()); cursor = SpoutCraftItemStack.getCraftItemStack(craftEvent.getCursor()); if (craftEvent.isCancelled()) { craftEvent.getInventory().setMatrix(recipeContents); setCursorSlot(cursor != null ? cursor.getHandle() : null); clickSuccessful = false; } } } } if (clickSuccessful) { clickSuccessful = handleInventoryClick(packet, type, slot, cursor, inventory); } if (clickSuccessful) { this.player.netServerHandler.sendPacket(new Packet106Transaction(windowId, packet.d, true)); this.player.h = true; this.player.activeContainer.a(); this.player.D(); this.player.h = false; } else { this.getEntityList() .a(Integer.valueOf(this.player.activeContainer.windowId), Short.valueOf(packet.d)); this.player.netServerHandler.sendPacket( new Packet106Transaction(windowId, packet.d, false)); this.player.activeContainer.a(this.player, false); ArrayList<ItemStack> arraylist = new ArrayList<ItemStack>(); for (int i = 0; i < this.player.activeContainer.e.size(); ++i) { arraylist.add(((Slot) this.player.activeContainer.e.get(i)).getItem()); } this.player.a(this.player.activeContainer, arraylist); } } }