use of net.aufdemrand.denizen.events.player.PlayerCraftsItemScriptEvent in project Denizen-For-Bukkit by DenizenScript.
the class ItemScriptHelper method specialRecipeClick.
// When special Denizen recipes that have itemscripts as ingredients
// are being used, check crafting matrix for recipe matches whenever
// clicks are made in CRAFTING or RESULT slots
@EventHandler
public void specialRecipeClick(InventoryClickEvent event) {
// Proceed only if at least one special recipe has been stored
if (ItemScriptContainer.specialrecipesMap.isEmpty() && ItemScriptContainer.shapelessRecipesMap.isEmpty()) {
return;
}
// Proceed only if this is a CraftingInventory
if (!(event.getInventory() instanceof CraftingInventory)) {
return;
}
// Store the slot type that was clicked
SlotType slotType = event.getSlotType();
// Proceed only if a CRAFTING or RESULT slot was clicked
if (slotType.equals(InventoryType.SlotType.CRAFTING) || slotType.equals(InventoryType.SlotType.RESULT)) {
CraftingInventory inventory = (CraftingInventory) event.getInventory();
Player player = (Player) event.getWhoClicked();
if (slotType == SlotType.RESULT && inventory.getResult() != null && inventory.getResult().getData().getItemType() != Material.AIR) {
PlayerCraftsItemScriptEvent scriptEvent = PlayerCraftsItemScriptEvent.instance;
scriptEvent.inventory = inventory;
scriptEvent.result = new dItem(inventory.getResult());
dList recipeList = new dList();
for (ItemStack item : inventory.getMatrix()) {
if (item != null) {
recipeList.add(new dItem(item.clone()).identify());
} else {
recipeList.add(new dItem(Material.AIR).identify());
}
}
scriptEvent.recipe = recipeList;
scriptEvent.player = dPlayer.mirrorBukkitPlayer(player);
scriptEvent.resultChanged = false;
scriptEvent.fire();
if (scriptEvent.cancelled) {
event.setCancelled(true);
return;
} else if (scriptEvent.resultChanged) {
event.setCurrentItem(scriptEvent.result.getItemStack());
}
}
// If the RESULT slot was shift-clicked, emulate
// shift click behavior for it
boolean clicked;
if (slotType == SlotType.RESULT && event.isShiftClick()) {
clicked = emulateSpecialRecipeResultShiftClick(inventory, player);
} else // Otherwise check for special recipe matches
{
clicked = processSpecialRecipes(inventory, player);
}
if (clicked && slotType.equals(SlotType.RESULT)) {
removeOneFromEachSlot(inventory, player);
}
}
}
Aggregations