Fix event !

This commit is contained in:
Rosenthalk0 2023-05-14 11:33:28 -05:00
parent 7f8afdff65
commit 4efea5a495
2 changed files with 54 additions and 0 deletions

View File

@ -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);

View File

@ -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;
// }
//
// }
}