9
0
mirror of https://github.com/HibiscusMC/HibiscusCommons.git synced 2025-12-19 15:09:26 +00:00

feat: add Nexo Reload event

This commit is contained in:
LoJoSho
2024-11-23 19:49:51 -06:00
parent a7a59110ab
commit eeb8d4a655
2 changed files with 10 additions and 4 deletions

View File

@@ -11,7 +11,7 @@ plugins {
} }
group = "me.lojosho" group = "me.lojosho"
version = "0.5.0" version = "0.5.1"
allprojects { allprojects {
apply(plugin = "java") apply(plugin = "java")
@@ -26,6 +26,7 @@ allprojects {
// UpdateChecker // UpdateChecker
maven("https://repo.jeff-media.com/public") maven("https://repo.jeff-media.com/public")
// Nexo
maven("https://repo.nexomc.com/snapshots/") maven("https://repo.nexomc.com/snapshots/")
// Geary & Backup ProtocolLib repo // Geary & Backup ProtocolLib repo

View File

@@ -3,8 +3,10 @@ package me.lojosho.hibiscuscommons.hooks.items;
import com.nexomc.nexo.api.NexoItems; import com.nexomc.nexo.api.NexoItems;
import com.nexomc.nexo.api.events.NexoItemsLoadedEvent; import com.nexomc.nexo.api.events.NexoItemsLoadedEvent;
import com.nexomc.nexo.items.ItemBuilder; import com.nexomc.nexo.items.ItemBuilder;
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 org.bukkit.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@@ -15,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
*/ */
@SuppressWarnings("SpellCheckingInspection") @SuppressWarnings("SpellCheckingInspection")
public class HookNexo extends Hook { public class HookNexo extends Hook {
private boolean loaded = false; private boolean enabled = false;
public HookNexo() { public HookNexo() {
super("nexo", HookFlag.ITEM_SUPPORT); super("nexo", HookFlag.ITEM_SUPPORT);
} }
@@ -25,7 +27,7 @@ public class HookNexo extends Hook {
*/ */
@Override @Override
public ItemStack getItem(@NotNull String itemId) { public ItemStack getItem(@NotNull String itemId) {
return NexoItems.optionalItemFromId(itemId).map(ItemBuilder::build).orElse(loaded ? new ItemStack(Material.AIR) : null); return NexoItems.optionalItemFromId(itemId).map(ItemBuilder::build).orElse(enabled ? new ItemStack(Material.AIR) : null);
} }
@Override @Override
@@ -37,6 +39,9 @@ public class HookNexo extends Hook {
@EventHandler @EventHandler
public void onLoadItems(NexoItemsLoadedEvent event) { public void onLoadItems(NexoItemsLoadedEvent event) {
loaded = true; HibiscusHookReload.ReloadType reloadType = enabled ? HibiscusHookReload.ReloadType.RELOAD : HibiscusHookReload.ReloadType.INITIAL;
this.enabled = true;
HibiscusHookReload newEvent = new HibiscusHookReload(this, reloadType);
Bukkit.getPluginManager().callEvent(newEvent);
} }
} }