mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-28 19:39:14 +00:00
Added oraxen item support
This commit is contained in:
@@ -35,7 +35,6 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
private MessageHandler messageHandler;
|
||||
private CosmeticsMenu cosmeticsMenu;
|
||||
private CommandManager commandManager;
|
||||
private boolean papiEnabled;
|
||||
private Database database;
|
||||
|
||||
@Override
|
||||
@@ -56,8 +55,6 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
this.database = DatabaseFactory.create(this);
|
||||
this.database.load();
|
||||
|
||||
this.papiEnabled = Bukkit.getPluginManager().getPlugin("PlaceholderAPI") != null;
|
||||
|
||||
this.registerCommands();
|
||||
this.registerListeners();
|
||||
}
|
||||
@@ -126,9 +123,5 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
public Database getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public boolean isPapiEnabled() {
|
||||
return papiEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,8 +4,6 @@ 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 io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
|
||||
@@ -3,6 +3,7 @@ package io.github.fisher2911.hmccosmetics.config;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.util.Keys;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
@@ -96,9 +97,19 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
final ConfigurationNode dyeableNode = source.node(DYEABLE);
|
||||
|
||||
|
||||
final Material material = Utils.stringToEnum(Utils.replaceIfNull(materialNode.getString(), ""),
|
||||
Material.class, Material.AIR);
|
||||
final String materialString = Utils.replaceIfNull(materialNode.getString(), "");
|
||||
final int amount = amountNode.getInt();
|
||||
|
||||
ItemStack itemStack;
|
||||
|
||||
try {
|
||||
itemStack = new ItemStack(Material.valueOf(materialString), amount);
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
itemStack = HookManager.getInstance().getItemHooks().getItemStack(materialString);
|
||||
if (itemStack == null) itemStack = new ItemStack(Material.AIR);
|
||||
}
|
||||
|
||||
|
||||
final Component name = StringUtils.parse(nameNode.getString());
|
||||
|
||||
final boolean unbreakable = unbreakableNode.getBoolean();
|
||||
@@ -162,7 +173,7 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
|
||||
final ItemBuilder itemBuilder;
|
||||
|
||||
if (material == Material.PLAYER_HEAD) {
|
||||
if (itemStack.getType() == Material.PLAYER_HEAD) {
|
||||
itemBuilder = SkullBuilder.
|
||||
create();
|
||||
|
||||
@@ -172,16 +183,16 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
|
||||
((SkullBuilder) itemBuilder).owner(player);
|
||||
}
|
||||
} else if (ColorBuilder.canBeColored(material)) {
|
||||
itemBuilder = ColorBuilder.from(material);
|
||||
} else if (ColorBuilder.canBeColored(itemStack)) {
|
||||
itemBuilder = ColorBuilder.from(itemStack);
|
||||
if (color != null) {
|
||||
((ColorBuilder) itemBuilder).color(color);
|
||||
}
|
||||
} else {
|
||||
itemBuilder = ItemBuilder.from(material);
|
||||
itemBuilder = ItemBuilder.from(itemStack);
|
||||
}
|
||||
|
||||
final ItemStack itemStack = itemBuilder.
|
||||
itemStack = itemBuilder.
|
||||
amount(amount).
|
||||
name(name).
|
||||
unbreakable(unbreakable).
|
||||
|
||||
@@ -5,6 +5,7 @@ import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
@@ -49,6 +50,7 @@ public abstract class Database {
|
||||
}
|
||||
|
||||
public void saveUser(final User user) {
|
||||
|
||||
try (final PreparedStatement statement = this.getConnection().prepareStatement(this.getSaveStatement())) {
|
||||
final PlayerArmor playerArmor = user.getPlayerArmor();
|
||||
final String hat = playerArmor.getHat().getId();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook;
|
||||
|
||||
public interface Hook {
|
||||
|
||||
String getId();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook;
|
||||
|
||||
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 org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class HookManager {
|
||||
|
||||
private static HookManager INSTANCE;
|
||||
|
||||
static {
|
||||
INSTANCE = new HookManager();
|
||||
}
|
||||
|
||||
public static HookManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final ItemHooks itemHooks;
|
||||
private final PAPIHook papiHook;
|
||||
private final Set<Class<? extends Hook>> registeredHooks;
|
||||
|
||||
private HookManager() {
|
||||
this.registeredHooks = new HashSet<>();
|
||||
final PluginManager pluginManager = Bukkit.getPluginManager();
|
||||
if (pluginManager.getPlugin("PlaceholderApi") != null) {
|
||||
this.registeredHooks.add(PAPIHook.class);
|
||||
this.papiHook = new PAPIHook();
|
||||
} else {
|
||||
this.papiHook = null;
|
||||
}
|
||||
|
||||
final Map<String, ItemHook> itemHookMap = new HashMap<>();
|
||||
final OraxenHook oraxenHook = new OraxenHook();
|
||||
if (pluginManager.getPlugin("Oraxen") != null) itemHookMap.put(oraxenHook.getIdentifier(), oraxenHook);
|
||||
this.itemHooks = new ItemHooks(itemHookMap);
|
||||
|
||||
itemHookMap.values().forEach(hook -> this.registerHook(hook.getClass()));
|
||||
}
|
||||
|
||||
protected void registerHook(final Class<? extends Hook> hook) {
|
||||
this.registeredHooks.add(hook);
|
||||
}
|
||||
|
||||
public boolean isEnabled(final Class<? extends Hook> hook) {
|
||||
return this.registeredHooks.contains(hook);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PAPIHook getPapiHook() {
|
||||
return papiHook;
|
||||
}
|
||||
|
||||
public ItemHooks getItemHooks() {
|
||||
return itemHooks;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PAPIHook implements Hook {
|
||||
|
||||
private static final String ID = "PAPI";
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
public String parse(final Player player, final String string) {
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook.item;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.hook.Hook;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface ItemHook extends Hook {
|
||||
|
||||
String getIdentifier();
|
||||
|
||||
ItemStack getItem(final String id);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
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 {
|
||||
|
||||
private final Map<String, ItemHook> itemHookMap;
|
||||
|
||||
public ItemHooks(final Map<String, ItemHook> itemHookMap) {
|
||||
this.itemHookMap = itemHookMap;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ItemStack getItemStack(final String item) {
|
||||
final String[] parts = item.split(":");
|
||||
|
||||
if (parts.length != 2) return null;
|
||||
|
||||
final String identifier = parts[0];
|
||||
final String itemId = parts[1];
|
||||
|
||||
final ItemHook hook = this.itemHookMap.get(identifier);
|
||||
|
||||
|
||||
if (hook == null) return null;
|
||||
|
||||
return hook.getItem(itemId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook.item;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.hook.Hook;
|
||||
import io.th0rgal.oraxen.items.ItemBuilder;
|
||||
import io.th0rgal.oraxen.items.OraxenItems;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public class OraxenHook implements ItemHook {
|
||||
|
||||
public static final String ID = "ORAXEN";
|
||||
private static final String IDENTIFIER = "oraxen";
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return IDENTIFIER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem(final String id) {
|
||||
final ItemBuilder itemBuilder = OraxenItems.getItemById(id);
|
||||
if (itemBuilder == null) return null;
|
||||
return itemBuilder.build();
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.github.fisher2911.hmccosmetics.message;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.github.fisher2911.hmccosmetics.util.Utils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
package io.github.fisher2911.hmccosmetics.papi;
|
||||
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class PAPIHook {
|
||||
|
||||
public static String parse(final Player player, final String string) {
|
||||
return PlaceholderAPI.setPlaceholders(player, string);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
package io.github.fisher2911.hmccosmetics.util;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.papi.PAPIHook;
|
||||
import io.github.fisher2911.hmccosmetics.hook.PAPIHook;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -32,8 +32,8 @@ public class StringUtils {
|
||||
}
|
||||
|
||||
public static String applyPapiPlaceholders(@Nullable final Player player, final String message) {
|
||||
if (plugin.isPapiEnabled()) {
|
||||
return PAPIHook.parse(player, message);
|
||||
if (HookManager.getInstance().isEnabled(PAPIHook.class)) {
|
||||
return HookManager.getInstance().getPapiHook().parse(player, message);
|
||||
}
|
||||
|
||||
return message;
|
||||
|
||||
Reference in New Issue
Block a user