mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
fix: Craft Engine hook (Thanks Bimbo!)
This commit is contained in:
@@ -1,24 +1,46 @@
|
|||||||
package me.lojosho.hibiscuscommons.hooks.items;
|
package me.lojosho.hibiscuscommons.hooks.items;
|
||||||
|
|
||||||
|
import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload;
|
||||||
import me.lojosho.hibiscuscommons.hooks.Hook;
|
import me.lojosho.hibiscuscommons.hooks.Hook;
|
||||||
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
import me.lojosho.hibiscuscommons.hooks.HookFlag;
|
||||||
import net.momirealms.craftengine.bukkit.api.CraftEngineItems;
|
import net.momirealms.craftengine.bukkit.api.CraftEngineItems;
|
||||||
import net.momirealms.craftengine.core.item.CustomItem;
|
import net.momirealms.craftengine.core.item.CustomItem;
|
||||||
import net.momirealms.craftengine.core.util.Key;
|
import net.momirealms.craftengine.core.util.Key;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.event.EventHandler;
|
||||||
|
import org.bukkit.event.server.PluginEnableEvent;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
public class HookCraftEngine extends Hook {
|
public class HookCraftEngine extends Hook {
|
||||||
|
|
||||||
public HookCraftEngine() {
|
public HookCraftEngine() {
|
||||||
super("CraftEngine", HookFlag.ITEM_SUPPORT);
|
super("craftengine", HookFlag.ITEM_SUPPORT, HookFlag.LATE_LOAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ItemStack getItem(@NotNull String itemId) {
|
public ItemStack getItem(@NotNull String itemId) {
|
||||||
Key craftEngineKey = Key.of(itemId);
|
if (!isActive()) return new ItemStack(Material.AIR);
|
||||||
CustomItem<ItemStack> itemStack = CraftEngineItems.byId(craftEngineKey);
|
CustomItem<ItemStack> item = CraftEngineItems.byId(Key.of(itemId));
|
||||||
if (itemStack == null) return null;
|
if (item == null) return null;
|
||||||
return itemStack.buildItemStack();
|
return item.buildItemStack();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getItemString(ItemStack itemStack) {
|
||||||
|
if (!itemStack.hasItemMeta()) return null;
|
||||||
|
Key key = CraftEngineItems.getCustomItemId(itemStack);
|
||||||
|
if (key == null) return null;
|
||||||
|
return key.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onPluginEnable(PluginEnableEvent event) {
|
||||||
|
// Move to CraftEngine own event for this? Doesn't seem like they have one for post-initialization? Open for PR
|
||||||
|
if (event.getPlugin().getName().equalsIgnoreCase("CraftEngine") && !isActive()) {
|
||||||
|
setActive(true);
|
||||||
|
Bukkit.getPluginManager().callEvent(new HibiscusHookReload(this, HibiscusHookReload.ReloadType.INITIAL));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user