Implemented linking of beacons in crafting
parent
b1169f48db
commit
a7a8a4b037
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue