diff --git a/build.gradle.kts b/build.gradle.kts index 3ff4c18..58265fa 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { } group = "me.lojosho" -version = "0.5.0" +version = "0.5.1" allprojects { apply(plugin = "java") @@ -26,6 +26,9 @@ allprojects { // UpdateChecker maven("https://repo.jeff-media.com/public") + // Nexo + maven("https://repo.nexomc.com/snapshots/") + // Geary & Backup ProtocolLib repo maven("https://repo.mineinabyss.com/releases/") maven("https://repo.mineinabyss.com/snapshots/") @@ -74,6 +77,7 @@ allprojects { compileOnly("org.spigotmc:spigot-api:1.19.4-R0.1-SNAPSHOT") compileOnly("org.jetbrains:annotations:24.1.0") compileOnly("io.th0rgal:oraxen:1.182.0") + compileOnly("com.nexomc:nexo:0.1.0-dev.0") compileOnly("com.github.LoneDev6:API-ItemsAdder:3.6.3-beta-14") compileOnly("com.mineinabyss:geary-papermc:0.31.0-dev.4") compileOnly("it.unimi.dsi:fastutil:8.5.13") @@ -193,7 +197,8 @@ bukkit { "LibsDisguises", "Denizen", "MMOItems", - "Eco" + "Eco", + "Nexo" ) version = "${project.version}" loadBefore = listOf( diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hooks.java b/common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hooks.java index eaf8bbd..db555dd 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hooks.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/hooks/Hooks.java @@ -19,6 +19,7 @@ import java.util.HashMap; public class Hooks { private static final HashMap hooks = new HashMap<>(); + private static final HookNexo NEXO_HOOK = new HookNexo(); private static final HookOraxen ORAXEN_HOOK = new HookOraxen(); private static final HookItemAdder ITEMADDER_HOOK = new HookItemAdder(); private static final HookGeary GEARY_HOOK = new HookGeary(); diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/hooks/items/HookNexo.java b/common/src/main/java/me/lojosho/hibiscuscommons/hooks/items/HookNexo.java new file mode 100644 index 0000000..b5e2067 --- /dev/null +++ b/common/src/main/java/me/lojosho/hibiscuscommons/hooks/items/HookNexo.java @@ -0,0 +1,47 @@ +package me.lojosho.hibiscuscommons.hooks.items; + +import com.nexomc.nexo.api.NexoItems; +import com.nexomc.nexo.api.events.NexoItemsLoadedEvent; +import com.nexomc.nexo.items.ItemBuilder; +import me.lojosho.hibiscuscommons.api.events.HibiscusHookReload; +import me.lojosho.hibiscuscommons.hooks.Hook; +import me.lojosho.hibiscuscommons.hooks.HookFlag; +import org.bukkit.Bukkit; +import org.bukkit.Material; +import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; + +/** + * A hook that integrates the plugin {@link com.nexomc.nexo.NexoPlugin NexoPlugin} to provide custom items + */ +@SuppressWarnings("SpellCheckingInspection") +public class HookNexo extends Hook { + private boolean enabled = false; + public HookNexo() { + super("nexo", HookFlag.ITEM_SUPPORT); + } + + /** + * Gets a cosmetic {@link ItemStack} that is associated with the provided id from the plugin {@link com.nexomc.nexo.NexoPlugin NexoPlugin} + */ + @Override + public ItemStack getItem(@NotNull String itemId) { + return NexoItems.optionalItemFromId(itemId).map(ItemBuilder::build).orElse(enabled ? new ItemStack(Material.AIR) : null); + } + + @Override + public String getItemString(ItemStack itemStack) { + if (itemStack == null) return null; + if (!itemStack.hasItemMeta()) return null; + return NexoItems.idFromItem(itemStack); + } + + @EventHandler + public void onLoadItems(NexoItemsLoadedEvent event) { + HibiscusHookReload.ReloadType reloadType = enabled ? HibiscusHookReload.ReloadType.RELOAD : HibiscusHookReload.ReloadType.INITIAL; + this.enabled = true; + HibiscusHookReload newEvent = new HibiscusHookReload(this, reloadType); + Bukkit.getPluginManager().callEvent(newEvent); + } +}