mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-28 19:39:14 +00:00
Fixed ItemsAdder support (Previously done directly on GitHub using a school computer)
This commit is contained in:
@@ -9,13 +9,15 @@ import io.github.fisher2911.hmccosmetics.database.Database;
|
||||
import io.github.fisher2911.hmccosmetics.database.DatabaseFactory;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticsMenu;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.hook.item.ItemAdderHook;
|
||||
import io.github.fisher2911.hmccosmetics.hook.listener.ItemsAdderListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.*;
|
||||
import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.util.Arrays;
|
||||
@@ -50,6 +52,10 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
|
||||
this.registerCommands();
|
||||
this.registerListeners();
|
||||
|
||||
if (!HookManager.getInstance().isEnabled(ItemAdderHook.class)) {
|
||||
this.load();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,12 +67,13 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
List.of(new ItemsAdderListener(this),
|
||||
List.of(
|
||||
new JoinListener(this),
|
||||
new ClickListener(this),
|
||||
new TeleportListener(this),
|
||||
new RespawnListener(this),
|
||||
new HatRemoveFixListener(this)).
|
||||
new HatRemoveFixListener(this)
|
||||
).
|
||||
forEach(listener ->
|
||||
this.getServer().getPluginManager().registerEvents(listener, this)
|
||||
);
|
||||
@@ -84,17 +91,17 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
);
|
||||
this.commandManager.getCompletionHandler().register("#types",
|
||||
resolver ->
|
||||
Arrays.stream(ArmorItem.Type.
|
||||
values()).
|
||||
map(ArmorItem.Type::toString).
|
||||
collect(Collectors.toList())
|
||||
);
|
||||
Arrays.stream(ArmorItem.Type.
|
||||
values()).
|
||||
map(ArmorItem.Type::toString).
|
||||
collect(Collectors.toList())
|
||||
);
|
||||
this.commandManager.getCompletionHandler().register("#ids",
|
||||
resolver ->
|
||||
this.cosmeticManager.getAll().stream().map(ArmorItem::getId).collect(Collectors.toList()));
|
||||
this.cosmeticManager.getAll().stream().map(ArmorItem::getId).collect(Collectors.toList()));
|
||||
this.commandManager.register(new CosmeticsCommand(this));
|
||||
}
|
||||
|
||||
|
||||
public void load() {
|
||||
this.messageHandler.load();
|
||||
this.cosmeticsMenu.load();
|
||||
|
||||
@@ -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()));
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package io.github.fisher2911.hmccosmetics.listener;
|
||||
|
||||
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.database.Database;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.hook.item.ItemAdderHook;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public class ItemsAdderListener implements Listener {
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
private boolean enabled;
|
||||
private boolean loaded;
|
||||
|
||||
public ItemsAdderListener(final HMCCosmetics plugin) {
|
||||
this.plugin = plugin;
|
||||
enabled = HookManager.getInstance().isEnabled(ItemAdderHook.class);
|
||||
if (!this.enabled) {
|
||||
this.plugin.load();
|
||||
this.loaded = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onJoin(final ItemsAdderLoadDataEvent event) {
|
||||
this.load();
|
||||
}
|
||||
|
||||
private void load() {
|
||||
if (this.enabled) {
|
||||
this.plugin.load();
|
||||
this.loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user