From 376695b46694af11780c203839d5baed1b11f76f Mon Sep 17 00:00:00 2001 From: Ruakij Date: Sun, 9 May 2021 22:50:54 +0200 Subject: [PATCH] Implemented check to detect attempt to link 2 beacons --- .../listener/OnPrepareItemCraftEvent.java | 11 +++++++++++ .../listener/OnPrepareItemCraftEvent.java | 12 ++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java 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 new file mode 100644 index 0000000..a2a5c3b --- /dev/null +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/linkedBeaconTeleporter/listener/OnPrepareItemCraftEvent.java @@ -0,0 +1,11 @@ +package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener; + +import org.bukkit.inventory.CraftingInventory; +import org.bukkit.inventory.InventoryView; + +public class OnPrepareItemCraftEvent { + + public static void onPrepareItemCraftEvent(CraftingInventory what, InventoryView view, boolean isRepair){ + + } +} diff --git a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnPrepareItemCraftEvent.java b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnPrepareItemCraftEvent.java index 045014e..83c7dbc 100644 --- a/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnPrepareItemCraftEvent.java +++ b/src/main/java/eu/ruekov/ruakij/LinkedBeaconTeleporters/listener/OnPrepareItemCraftEvent.java @@ -14,5 +14,17 @@ public class OnPrepareItemCraftEvent implements Listener { @EventHandler(priority = EventPriority.LOW) public void onPrepareItemCraftEvent(CraftingInventory what, InventoryView view, boolean isRepair){ + ItemStack[] matrix = what.getMatrix(); + + // Check if 2 beacons are in the crafting-slots + int beaconCount = 0; + for (ItemStack item : matrix) { + if(item.getType() == Material.BEACON) + beaconCount++; + } + if(beaconCount == 2){ + // Exactly 2 beacons found + eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnPrepareItemCraftEvent.onPrepareItemCraftEvent(what, view, isRepair); + } } }