diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java index e59c3a86..2f2bd412 100644 --- a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/MMOItemsBukkit.java @@ -15,6 +15,7 @@ public class MMOItemsBukkit { */ public MMOItemsBukkit(MMOItems plugin) { + Bukkit.getPluginManager().registerEvents(new CraftingListener(),plugin); Bukkit.getPluginManager().registerEvents(new ItemUse(), plugin); Bukkit.getPluginManager().registerEvents(new ItemListener(), plugin); Bukkit.getPluginManager().registerEvents(new PlayerListener(), plugin); diff --git a/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CraftingListener.java b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CraftingListener.java new file mode 100644 index 00000000..8d21c75d --- /dev/null +++ b/MMOItems-Dist/src/main/java/net/Indyuce/mmoitems/listener/CraftingListener.java @@ -0,0 +1,53 @@ +package net.Indyuce.mmoitems.listener; + +import io.lumine.mythic.lib.api.crafting.event.MythicCraftItemEvent; +import io.lumine.mythic.lib.api.item.NBTItem; +import net.Indyuce.mmoitems.MMOItems; +import net.Indyuce.mmoitems.api.event.CraftMMOItemEvent; +import net.Indyuce.mmoitems.api.player.PlayerData; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.inventory.ItemStack; + +public class CraftingListener implements Listener { + + @EventHandler(priority = EventPriority.MONITOR,ignoreCancelled = true) + public void onCraft(MythicCraftItemEvent event) { + + ItemStack result = null; + ItemStack firstResult = event.getCache().getResultOfOperation().getResultInventory().getFirst(); + if (firstResult != null){ + result = firstResult; + } + if (result == null){ + MMOItems.log("No Result Item!"); + return; + } + + + + if (NBTItem.get(result).hasType()){ + CraftMMOItemEvent e = new CraftMMOItemEvent(PlayerData.get(((Player) event.getTrigger().getWhoClicked())), result); + Bukkit.getPluginManager().callEvent(e); + + event.setCancelled(e.isCancelled()); + return; + } + } + +// @EventHandler(priority = EventPriority.HIGHEST,ignoreCancelled = true) +// public void onCraft(CraftMMOItemEvent event){ +// ItemStack result = event.getResult(); +// if (result == null){ +// throw new RuntimeException("No Valid Result for CraftMMOItemEvent of " + event.getPlayerData().getPlayer().getName()); +// } +// if (!NBTItem.get(result).hasType()){ +// event.setCancelled(true); +// return; +// } +// +// } +}