Switched to proper Crafting-mechanics
parent
3d757a6ccf
commit
c0917a1ab6
@ -0,0 +1,27 @@
|
||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
|
||||
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
public class OnCraftItemEvent {
|
||||
|
||||
public static void onCraftItemEvent(CraftItemEvent e, LinkedBeaconTeleporterItem lbtItem){
|
||||
|
||||
// Create new LinkedBeaconTeleporterItem
|
||||
lbtItem = new LinkedBeaconTeleporterItem();
|
||||
|
||||
ItemStack item = lbtItem.item();
|
||||
// Exactly 2
|
||||
item.setAmount(2);
|
||||
|
||||
// FIXME: Changing the just-crafted-item only works for a single item, bulk-crafting (e.g. Shift-Click) will result in default-items getting crafted!
|
||||
|
||||
e.setCurrentItem(item);
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener;
|
||||
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OnPrepareItemCraftEvent {
|
||||
|
||||
public static void onPrepareItemCraftEvent(PrepareItemCraftEvent e){
|
||||
ItemStack[] matrix = e.getInventory().getMatrix();
|
||||
|
||||
// Check if one of provided items is already LinkedBeaconTeleporterItem and use first if found
|
||||
LinkedBeaconTeleporterItem lbtItem = null;
|
||||
|
||||
/*for (ItemStack item : matrix) {
|
||||
if(item == null) continue;
|
||||
lbtItem = LinkedBeaconTeleporterItem.getFromItemStack(item);
|
||||
if(lbtItem != null) break;
|
||||
}*/
|
||||
|
||||
if(lbtItem == null){
|
||||
// If none is found, create new LinkedBeaconTeleporterItem and set as crafting-result
|
||||
lbtItem = new LinkedBeaconTeleporterItem();
|
||||
}
|
||||
|
||||
ItemStack item = lbtItem.item();
|
||||
// Exactly 2
|
||||
item.setAmount(2);
|
||||
|
||||
// Set as crafting-result
|
||||
e.getInventory().setResult(item);
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
|
||||
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.Main;
|
||||
import eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.LinkedBeaconTeleporterItem;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.CraftItemEvent;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
public class OnCraftItemEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onCraftItemEvent(CraftItemEvent e){
|
||||
|
||||
Recipe recipe = e.getRecipe();
|
||||
ItemStack itemResult = recipe.getResult();
|
||||
|
||||
// Check if it has LinkedBeaconTeleporter-Data
|
||||
LinkedBeaconTeleporterItem lbtItem = Main.lbtManager.getLbtItemFromItemStack(itemResult);
|
||||
if(lbtItem != null){
|
||||
eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnCraftItemEvent.onCraftItemEvent(e, lbtItem);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package eu.ruekov.ruakij.LinkedBeaconTeleporters.listener;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.CraftingInventory;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OnPrepareItemCraftEvent implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.LOW)
|
||||
public void onPrepareItemCraftEvent(PrepareItemCraftEvent e){
|
||||
|
||||
ItemStack[] matrix = e.getInventory().getMatrix();
|
||||
|
||||
// Check if 2 beacons are in the crafting-slots
|
||||
int beaconCount = 0;
|
||||
for (ItemStack item : matrix) {
|
||||
if(item == null) continue;
|
||||
if(item.getType() == Material.BEACON)
|
||||
beaconCount++;
|
||||
}
|
||||
if(beaconCount == 2){
|
||||
// Exactly 2 beacons found
|
||||
eu.ruekov.ruakij.LinkedBeaconTeleporters.linkedBeaconTeleporter.listener.OnPrepareItemCraftEvent.onPrepareItemCraftEvent(e);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue