diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java index a2a5c3b..daeecf8 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java @@ -1,11 +1,37 @@ package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener; +import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem; +import org.bukkit.Material; import org.bukkit.inventory.CraftingInventory; import org.bukkit.inventory.InventoryView; +import org.bukkit.inventory.ItemStack; public class OnPrepareItemCraftEvent { public static void onPrepareItemCraftEvent(CraftingInventory what, InventoryView view, boolean isRepair){ + ItemStack[] matrix = what.getMatrix(); + // Check if one of provided items is already LinkedBeaconTeleporterItem and use first if found + LinkedBeaconTeleporterItem lbtItem = null; + + for (ItemStack item : matrix) { + lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item); + if(lbtItem != null) break; + } + + if(lbtItem == null){ + // If none is found, create new LinkedBeaconTeleporterItem and set as crafting-result + ItemStack item = new ItemStack(Material.BEACON); + lbtItem = new LinkedBeaconTeleporterItem(item); + } + + // Generate ItemStack + ItemStack item = lbtItem.toItemStack(); + + // Exactly 2 + item.setAmount(2); + + // Set as crafting-result + what.setResult(item); } }