9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-30 12:29:16 +00:00

Fixed ItemsAdder support (Previously done directly on GitHub using a school computer)

This commit is contained in:
HeroBrineGoat
2022-01-18 19:25:11 -05:00
parent f19b4d359e
commit 39b6a8de67
5 changed files with 56 additions and 64 deletions

View File

@@ -1,9 +1,11 @@
package io.github.fisher2911.hmccosmetics.hook;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import io.github.fisher2911.hmccosmetics.hook.item.ItemHook;
import io.github.fisher2911.hmccosmetics.hook.item.ItemHooks;
import io.github.fisher2911.hmccosmetics.hook.item.OraxenHook;
import io.github.fisher2911.hmccosmetics.hook.item.ItemAdderHook;
import io.github.fisher2911.hmccosmetics.hook.listener.ItemsAdderListener;
import org.bukkit.Bukkit;
import org.bukkit.plugin.PluginManager;
import org.jetbrains.annotations.Nullable;
@@ -15,21 +17,24 @@ import java.util.Set;
public class HookManager {
private static HookManager INSTANCE;
private static final HookManager INSTANCE;
static {
INSTANCE = new HookManager();
INSTANCE = new HookManager(HMCCosmetics.getPlugin(HMCCosmetics.class));
}
public static HookManager getInstance() {
return INSTANCE;
}
private final HMCCosmetics plugin;
private final ItemHooks itemHooks;
private final PAPIHook papiHook;
private final Set<Class<? extends Hook>> registeredHooks;
private HookManager() {
private HookManager(final HMCCosmetics plugin) {
this.plugin = plugin;
this.registeredHooks = new HashSet<>();
final PluginManager pluginManager = Bukkit.getPluginManager();
if (pluginManager.getPlugin("PlaceholderApi") != null) {
@@ -43,9 +48,12 @@ public class HookManager {
final OraxenHook oraxenHook = new OraxenHook();
final ItemAdderHook itemAdderHook = new ItemAdderHook();
if (pluginManager.getPlugin("Oraxen") != null) itemHookMap.put(oraxenHook.getIdentifier(), oraxenHook);
if (pluginManager.getPlugin("ItemAdder") != null) itemHookMap.put(itemAdderHook.getIdentifier(), itemAdderHook);
this.itemHooks = new ItemHooks(itemHookMap);
if (pluginManager.getPlugin("ItemAdder") != null) {
itemHookMap.put(itemAdderHook.getIdentifier(), itemAdderHook);
this.plugin.getServer().getPluginManager().registerEvents(new ItemsAdderListener(this.plugin), this.plugin);
}
this.itemHooks = new ItemHooks(itemHookMap);
itemHookMap.values().forEach(hook -> this.registerHook(hook.getClass()));
}

View File

@@ -1,10 +1,9 @@
package io.github.fisher2911.hmccosmetics.hook.item;
import dev.lone.itemsadder.api.CustomStack;
import io.github.fisher2911.hmccosmetics.hook.Hook;
import org.bukkit.inventory.ItemStack;
import dev.lone.itemsadder.api.CustomStack;
import org.bukkit.inventory.ItemStack;
public class ItemAdderHook implements ItemHook {
public class ItemAdderHook implements ItemHook {
public static final String ID = "ITEM_ADDER";
private static final String IDENTIFIER = "itemadder";

View File

@@ -0,0 +1,23 @@
package io.github.fisher2911.hmccosmetics.hook.listener;
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class ItemsAdderListener implements Listener {
private final HMCCosmetics plugin;
private boolean loaded;
public ItemsAdderListener(final HMCCosmetics plugin) {
this.plugin = plugin;
}
@EventHandler
public void onItemAdderLoad(final ItemsAdderLoadDataEvent event) {
if (this.loaded) return;
this.plugin.load();
this.loaded = true;
}
}