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

Merge pull request #9 from Boy0000/nexo

feat: add Nexo support
This commit is contained in:
LoJoSho
2024-11-23 19:51:46 -06:00
committed by GitHub
3 changed files with 55 additions and 2 deletions

View File

@@ -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(

View File

@@ -19,6 +19,7 @@ import java.util.HashMap;
public class Hooks {
private static final HashMap<String, Hook> 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();

View File

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