mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 03:49:19 +00:00
@@ -9,11 +9,9 @@ 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.listener.ClickListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.HatRemoveFixListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.JoinListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.RespawnListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.TeleportListener;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.hook.item.ItemsAdderHook;
|
||||
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;
|
||||
@@ -22,6 +20,7 @@ import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@@ -47,16 +46,19 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
this.userManager = new UserManager(this);
|
||||
this.cosmeticManager = new CosmeticManager(new HashMap<>());
|
||||
this.cosmeticsMenu = new CosmeticsMenu(this);
|
||||
this.messageHandler.load();
|
||||
this.cosmeticsMenu.load();
|
||||
|
||||
this.userManager.startTeleportTask();
|
||||
|
||||
this.database = DatabaseFactory.create(this);
|
||||
this.database.load();
|
||||
|
||||
this.registerCommands();
|
||||
this.registerListeners();
|
||||
|
||||
if (!HookManager.getInstance().isEnabled(ItemsAdderHook.class)) {
|
||||
this.load();
|
||||
}
|
||||
|
||||
HookManager.getInstance().registerListeners(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -68,13 +70,15 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
List.of(new JoinListener(this),
|
||||
List.of(
|
||||
new JoinListener(this),
|
||||
new ClickListener(this),
|
||||
new TeleportListener(this),
|
||||
new RespawnListener(this),
|
||||
new HatRemoveFixListener(this)).
|
||||
forEach(listener ->
|
||||
this.getServer().getPluginManager().registerEvents(listener, this)
|
||||
new HatRemoveFixListener(this)
|
||||
).
|
||||
forEach(
|
||||
listener -> this.getServer().getPluginManager().registerEvents(listener, this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -90,17 +94,23 @@ 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();
|
||||
this.database.load();
|
||||
}
|
||||
|
||||
public MessageHandler getMessageHandler() {
|
||||
return messageHandler;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.CosmeticGui;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.bukkit.NamespacedKey;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.Registry;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -192,13 +193,16 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
itemBuilder = ItemBuilder.from(itemStack);
|
||||
}
|
||||
|
||||
if (itemStack.getItemMeta() != null && !itemStack.getItemMeta().hasCustomModelData()) {
|
||||
itemBuilder.modelData(modelData);
|
||||
}
|
||||
|
||||
itemStack = itemBuilder.
|
||||
amount(amount).
|
||||
name(name).
|
||||
unbreakable(unbreakable).
|
||||
glow(glowing).
|
||||
lore(lore).
|
||||
modelData(modelData).
|
||||
enchants(enchantments, true).
|
||||
itemFlags(itemFlags).
|
||||
build();
|
||||
|
||||
@@ -33,6 +33,7 @@ public class DatabaseFactory {
|
||||
final Logger logger = plugin.getLogger();
|
||||
|
||||
if (type == null) {
|
||||
logger.severe("Database type was null, disabling plugin.");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
throw new NullPointerException();
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
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.ItemsAdderHook;
|
||||
import io.github.fisher2911.hmccosmetics.hook.item.OraxenHook;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -14,22 +17,27 @@ 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 final Set<Listener> listeners;
|
||||
|
||||
private HookManager() {
|
||||
private HookManager(final HMCCosmetics plugin) {
|
||||
this.plugin = plugin;
|
||||
this.registeredHooks = new HashSet<>();
|
||||
this.listeners = new HashSet<>();
|
||||
final PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
if (pluginManager.getPlugin("PlaceholderApi") != null) {
|
||||
this.registeredHooks.add(PAPIHook.class);
|
||||
@@ -40,9 +48,14 @@ public class HookManager {
|
||||
|
||||
final Map<String, ItemHook> itemHookMap = new HashMap<>();
|
||||
final OraxenHook oraxenHook = new OraxenHook();
|
||||
final ItemsAdderHook itemsAdderHook = new ItemsAdderHook();
|
||||
if (pluginManager.getPlugin("Oraxen") != null) itemHookMap.put(oraxenHook.getIdentifier(), oraxenHook);
|
||||
this.itemHooks = new ItemHooks(itemHookMap);
|
||||
if (pluginManager.getPlugin("ItemsAdder") != null) {
|
||||
itemHookMap.put(itemsAdderHook.getIdentifier(), itemsAdderHook);
|
||||
this.listeners.add(itemsAdderHook);
|
||||
}
|
||||
|
||||
this.itemHooks = new ItemHooks(itemHookMap);
|
||||
itemHookMap.values().forEach(hook -> this.registerHook(hook.getClass()));
|
||||
}
|
||||
|
||||
@@ -54,6 +67,12 @@ public class HookManager {
|
||||
return this.registeredHooks.contains(hook);
|
||||
}
|
||||
|
||||
public void registerListeners(final HMCCosmetics plugin) {
|
||||
for (final Listener listener : this.listeners) {
|
||||
plugin.getServer().getPluginManager().registerEvents(listener, plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PAPIHook getPapiHook() {
|
||||
return papiHook;
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook.item;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemHooks {
|
||||
@@ -20,18 +17,20 @@ public class ItemHooks {
|
||||
public ItemStack getItemStack(final String item) {
|
||||
final String[] parts = item.split(":");
|
||||
|
||||
if (parts.length != 2) return null;
|
||||
if (parts.length < 2) return null;
|
||||
|
||||
final String identifier = parts[0];
|
||||
final String itemId = parts[1];
|
||||
final StringBuilder itemId = new StringBuilder();
|
||||
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
itemId.append(parts[i]);
|
||||
if (i < parts.length - 1) itemId.append(":");
|
||||
}
|
||||
|
||||
final ItemHook hook = this.itemHookMap.get(identifier);
|
||||
|
||||
|
||||
if (hook == null) return null;
|
||||
|
||||
return hook.getItem(itemId);
|
||||
return hook.getItem(itemId.toString());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook.item;
|
||||
|
||||
import dev.lone.itemsadder.api.CustomStack;
|
||||
import dev.lone.itemsadder.api.Events.ItemsAdderLoadDataEvent;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class ItemsAdderHook implements ItemHook, Listener {
|
||||
|
||||
public static final String ID = "ITEM_ADDER";
|
||||
private static final String IDENTIFIER = "itemsadder";
|
||||
|
||||
@EventHandler
|
||||
public void onItemsAdderLoad(final ItemsAdderLoadDataEvent event) {
|
||||
final HMCCosmetics plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
Bukkit.getScheduler().runTaskAsynchronously(plugin, plugin::load);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(final String id) {
|
||||
final CustomStack stack = CustomStack.getInstance(id);
|
||||
if (stack == null) return null;
|
||||
return stack.getItemStack().clone();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user