mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-29 11:59:21 +00:00
refactor some stuff
This commit is contained in:
@@ -2,7 +2,6 @@ package io.github.fisher2911.hmccosmetics;
|
||||
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.command.CosmeticsCommand;
|
||||
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
|
||||
import io.github.fisher2911.hmccosmetics.config.Settings;
|
||||
@@ -13,28 +12,32 @@ 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.ItemsAdderHook;
|
||||
import io.github.fisher2911.hmccosmetics.listener.*;
|
||||
import io.github.fisher2911.hmccosmetics.listener.ClickListener;
|
||||
import io.github.fisher2911.hmccosmetics.listener.CosmeticFixListener;
|
||||
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.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.message.Translation;
|
||||
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.Color;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import me.mattstudios.mf.base.CommandManager;
|
||||
import org.bstats.bukkit.Metrics;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class HMCCosmetics extends JavaPlugin {
|
||||
|
||||
public static final Path PLUGIN_FOLDER = Paths.get("plugins", "HMCCosmetics");
|
||||
|
||||
private ProtocolManager protocolManager;
|
||||
private Settings settings;
|
||||
private UserManager userManager;
|
||||
@@ -105,7 +108,8 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
new CosmeticFixListener(this)
|
||||
).
|
||||
forEach(
|
||||
listener -> this.getServer().getPluginManager().registerEvents(listener, this)
|
||||
listener -> this.getServer().getPluginManager()
|
||||
.registerEvents(listener, this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -117,7 +121,6 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
player,
|
||||
Messages.MUST_BE_PLAYER
|
||||
)
|
||||
|
||||
);
|
||||
this.commandManager.getCompletionHandler().register("#types",
|
||||
resolver ->
|
||||
@@ -128,7 +131,8 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -180,5 +184,6 @@ public class HMCCosmetics extends JavaPlugin {
|
||||
public Database getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package io.github.fisher2911.hmccosmetics.api;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import java.util.ArrayList;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Wrapper for ArmorItem used internally for convenience and safety
|
||||
*/
|
||||
@@ -19,7 +18,6 @@ public class CosmeticItem {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemStack the {@link org.bukkit.inventory.ItemStack} display item
|
||||
* @param id the id of the item
|
||||
* @param type the cosmetic item type
|
||||
@@ -27,12 +25,12 @@ public class CosmeticItem {
|
||||
* @param rgb from Bukkit's {@link Color#asRGB()}
|
||||
*/
|
||||
|
||||
public CosmeticItem(final ItemStack itemStack, final String id, final ArmorItem.Type type, final boolean dyeable, final int rgb) {
|
||||
public CosmeticItem(final ItemStack itemStack, final String id, final ArmorItem.Type type,
|
||||
final boolean dyeable, final int rgb) {
|
||||
this.armorItem = new ArmorItem(itemStack, id, new ArrayList<>(), "", type, dyeable, rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material the {@link org.bukkit.Material} display item
|
||||
* @param id the id of the item
|
||||
* @param type the cosmetic item type
|
||||
@@ -40,12 +38,12 @@ public class CosmeticItem {
|
||||
* @param rgb from Bukkit's {@link Color#asRGB()}
|
||||
*/
|
||||
|
||||
public CosmeticItem(final Material material, final String id, final ArmorItem.Type type, final boolean dyeable, final int rgb) {
|
||||
public CosmeticItem(final Material material, final String id, final ArmorItem.Type type,
|
||||
final boolean dyeable, final int rgb) {
|
||||
this.armorItem = new ArmorItem(material, id, new ArrayList<>(), "", type, dyeable, rgb);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemStack the {@link org.bukkit.inventory.ItemStack} display item
|
||||
* @param id the id of the item
|
||||
* @param type the cosmetic item type
|
||||
@@ -56,7 +54,6 @@ public class CosmeticItem {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material the {@link org.bukkit.Material} display item
|
||||
* @param id the id of the item
|
||||
* @param type the cosmetic item type
|
||||
@@ -93,4 +90,5 @@ public class CosmeticItem {
|
||||
public ArmorItem getArmorItem() {
|
||||
return this.armorItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class HMCCosmeticsAPI {
|
||||
|
||||
@@ -18,22 +17,23 @@ public class HMCCosmeticsAPI {
|
||||
}
|
||||
|
||||
/**
|
||||
* This will attempt to get the {@link io.github.fisher2911.hmccosmetics.api.CosmeticItem} that
|
||||
* the user is wearing. It returns an empty {@link io.github.fisher2911.hmccosmetics.api.CosmeticItem}
|
||||
* if the user is not found, or if the user is not wearing a cosmetic
|
||||
*
|
||||
* This will attempt to get the {@link io.github.fisher2911.hmccosmetics.api.CosmeticItem} that the
|
||||
* user is wearing. It returns an empty {@link io.github.fisher2911.hmccosmetics.api.CosmeticItem} if the user
|
||||
* is not found, or if the user is not wearing a cosmetic
|
||||
* @param uuid the uuid of the user
|
||||
* @param type the type of cosmetic being retrieved
|
||||
* @return the current cosmetic of the player
|
||||
*/
|
||||
public static CosmeticItem getUserCurrentItem(final UUID uuid, final ArmorItem.Type type) {
|
||||
final Optional<User> userOptional = plugin.getUserManager().get(uuid);
|
||||
if (userOptional.isEmpty()) return new CosmeticItem(ArmorItem.empty(type));
|
||||
if (userOptional.isEmpty()) {
|
||||
return new CosmeticItem(ArmorItem.empty(type));
|
||||
}
|
||||
return new CosmeticItem(userOptional.get().getPlayerArmor().getItem(type));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid the uuid of the user whose cosmetic is being set
|
||||
* @param cosmeticItem the cosmetic being set
|
||||
* @return true if the cosmetic was set, or else false
|
||||
@@ -41,14 +41,15 @@ public class HMCCosmeticsAPI {
|
||||
public static boolean setCosmeticItem(final UUID uuid, final CosmeticItem cosmeticItem) {
|
||||
final UserManager userManager = plugin.getUserManager();
|
||||
final Optional<User> userOptional = userManager.get(uuid);
|
||||
if (userOptional.isEmpty()) return false;
|
||||
if (userOptional.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
userManager.setItem(userOptional.get(), cosmeticItem.getArmorItem());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param id the id of the cosmetic item being retrieved
|
||||
* @return null if the cosmetic was not found, or a copy of the cosmetic item
|
||||
*/
|
||||
@@ -56,19 +57,23 @@ public class HMCCosmeticsAPI {
|
||||
@Nullable
|
||||
public static CosmeticItem getCosmeticFromId(final String id) {
|
||||
final ArmorItem armorItem = plugin.getCosmeticManager().getArmorItem(id);
|
||||
if (armorItem == null) return null;
|
||||
if (armorItem == null) {
|
||||
return null;
|
||||
}
|
||||
return new CosmeticItem(new ArmorItem(armorItem));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param uuid the uuid of the user whose armor stand id is being retrieved
|
||||
* @return the armor stand id, or -1 if the user is not found
|
||||
*/
|
||||
|
||||
public static int getUserArmorStandId(final UUID uuid) {
|
||||
final Optional<User> userOptional = plugin.getUserManager().get(uuid);
|
||||
if (userOptional.isEmpty()) return -1;
|
||||
if (userOptional.isEmpty()) {
|
||||
return -1;
|
||||
}
|
||||
return userOptional.get().getArmorStandId();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import io.github.fisher2911.hmccosmetics.user.User;
|
||||
*/
|
||||
public class CosmeticChangeEvent extends CosmeticItemEvent {
|
||||
|
||||
private CosmeticItem removed;
|
||||
private final User user;
|
||||
private CosmeticItem removed;
|
||||
|
||||
public CosmeticChangeEvent(final CosmeticItem cosmeticItem, final CosmeticItem removed, final User user) {
|
||||
public CosmeticChangeEvent(final CosmeticItem cosmeticItem, final CosmeticItem removed,
|
||||
final User user) {
|
||||
super(cosmeticItem);
|
||||
this.removed = removed;
|
||||
this.user = user;
|
||||
@@ -28,4 +29,5 @@ public class CosmeticChangeEvent extends CosmeticItemEvent {
|
||||
public void setRemoved(final CosmeticItem removed) {
|
||||
this.removed = removed;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,6 +17,10 @@ public abstract class CosmeticItemEvent extends Event implements Cancellable {
|
||||
this.cancelled = false;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
public CosmeticItem getCosmeticItem() {
|
||||
return this.cosmeticItem;
|
||||
}
|
||||
@@ -35,12 +39,9 @@ public abstract class CosmeticItemEvent extends Event implements Cancellable {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return HANDLERS;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import me.mattstudios.mf.annotations.Command;
|
||||
import me.mattstudios.mf.annotations.Completion;
|
||||
import me.mattstudios.mf.annotations.Default;
|
||||
@@ -21,9 +23,6 @@ import org.bukkit.Color;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
@Command("cosmetics")
|
||||
public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@@ -62,7 +61,8 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("dye")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.DYE_COMMAND)
|
||||
public void dyeArmor(final Player player, @Completion("#types") String typeString, final @me.mattstudios.mf.annotations.Optional String dyeColor) {
|
||||
public void dyeArmor(final Player player, @Completion("#types") String typeString,
|
||||
final @me.mattstudios.mf.annotations.Optional String dyeColor) {
|
||||
|
||||
final Optional<User> optionalUser = this.userManager.get(player.getUniqueId());
|
||||
|
||||
@@ -113,7 +113,8 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("add")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.SET_COSMETIC_COMMAND)
|
||||
public void setCommand(final CommandSender sender, @Completion("#players") final Player player, @Completion("#ids") final String id) {
|
||||
public void setCommand(final CommandSender sender, @Completion("#players") final Player player,
|
||||
@Completion("#ids") final String id) {
|
||||
final Optional<User> userOptional = this.userManager.get(player.getUniqueId());
|
||||
|
||||
if (userOptional.isEmpty()) {
|
||||
@@ -153,7 +154,8 @@ public class CosmeticsCommand extends CommandBase {
|
||||
|
||||
@SubCommand("remove")
|
||||
@Permission(io.github.fisher2911.hmccosmetics.message.Permission.SET_COSMETIC_COMMAND)
|
||||
public void removeCommand(final CommandSender sender, @Completion("#players") final Player player, @Completion("#types") String typeString) {
|
||||
public void removeCommand(final CommandSender sender,
|
||||
@Completion("#players") final Player player, @Completion("#types") String typeString) {
|
||||
final Optional<User> userOptional = this.userManager.get(player.getUniqueId());
|
||||
|
||||
if (userOptional.isEmpty()) {
|
||||
@@ -169,13 +171,8 @@ public class CosmeticsCommand extends CommandBase {
|
||||
try {
|
||||
final ArmorItem.Type type = ArmorItem.Type.valueOf(typeString.toUpperCase());
|
||||
|
||||
final Message setMessage = Messages.getRemovedMessage(type);
|
||||
final Message setOtherMessage = Messages.getSetOtherMessage(type);
|
||||
this.userManager.removeItem(user, type);
|
||||
this.messageHandler.sendMessage(
|
||||
player,
|
||||
setMessage
|
||||
);
|
||||
this.messageHandler.sendMessage(
|
||||
sender,
|
||||
setOtherMessage,
|
||||
|
||||
@@ -11,16 +11,16 @@ public class Threads {
|
||||
INSTANCE = new Threads();
|
||||
}
|
||||
|
||||
public static Threads getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final ExecutorService service;
|
||||
|
||||
private Threads() {
|
||||
this.service = Executors.newFixedThreadPool(1);
|
||||
}
|
||||
|
||||
public static Threads getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public void execute(final Runnable runnable) {
|
||||
this.service.execute(runnable);
|
||||
}
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
package io.github.fisher2911.hmccosmetics.config;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CosmeticSettings {
|
||||
@@ -17,22 +15,24 @@ public class CosmeticSettings {
|
||||
private boolean requireEmptyOffHand;
|
||||
|
||||
public void load(final FileConfiguration config) {
|
||||
this.requireEmptyHelmet = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_HELMET_PATH);
|
||||
this.requireEmptyOffHand = config.getBoolean(COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_OFF_HAND_PATH);
|
||||
this.requireEmptyHelmet = config.getBoolean(
|
||||
COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_HELMET_PATH);
|
||||
this.requireEmptyOffHand = config.getBoolean(
|
||||
COSMETIC_SETTINGS_PATH + "." + REQUIRE_EMPTY_OFF_HAND_PATH);
|
||||
}
|
||||
|
||||
public boolean isRequireEmptyHelmet() {
|
||||
return requireEmptyHelmet;
|
||||
}
|
||||
|
||||
public boolean isRequireEmptyOffHand() {
|
||||
return requireEmptyOffHand;
|
||||
}
|
||||
|
||||
public void setRequireEmptyHelmet(final boolean requireEmptyHelmet) {
|
||||
this.requireEmptyHelmet = requireEmptyHelmet;
|
||||
}
|
||||
|
||||
public boolean isRequireEmptyOffHand() {
|
||||
return requireEmptyOffHand;
|
||||
}
|
||||
|
||||
public void setRequireEmptyOffHand(final boolean requireEmptyOffHand) {
|
||||
this.requireEmptyOffHand = requireEmptyOffHand;
|
||||
}
|
||||
@@ -44,4 +44,5 @@ public class CosmeticSettings {
|
||||
default -> false;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,34 +8,20 @@ import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ColorItem;
|
||||
import io.github.fisher2911.hmccosmetics.gui.DyeSelectorGui;
|
||||
import io.github.fisher2911.hmccosmetics.message.Adventure;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.th0rgal.oraxen.utils.armorequipevent.ArmorType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Color;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
|
||||
private static final HMCCosmetics plugin;
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
public static final DyeGuiSerializer INSTANCE = new DyeGuiSerializer();
|
||||
|
||||
private DyeGuiSerializer() {}
|
||||
|
||||
private static final HMCCosmetics plugin;
|
||||
private static final String TITLE = "title";
|
||||
private static final String ROWS = "rows";
|
||||
private static final String ITEMS = "items";
|
||||
@@ -45,21 +31,30 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
private static final String GREEN = "green";
|
||||
private static final String BLUE = "blue";
|
||||
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path) throws SerializationException {
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
private DyeGuiSerializer() {
|
||||
}
|
||||
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path)
|
||||
throws SerializationException {
|
||||
if (!source.hasChild(path)) {
|
||||
throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node");
|
||||
throw new SerializationException(
|
||||
"Required field " + Arrays.toString(path) + " was not present in node");
|
||||
}
|
||||
return source.node(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DyeSelectorGui deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
public DyeSelectorGui deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode titleNode = this.nonVirtualNode(source, TITLE);
|
||||
final ConfigurationNode rowsNode = this.nonVirtualNode(source, ROWS);
|
||||
final ConfigurationNode itemsNode = source.node(ITEMS);
|
||||
final ConfigurationNode cosmeticSlotsNode = source.node(COSMETICS_SLOTS);
|
||||
|
||||
|
||||
final Map<Integer, GuiItem> guiItemMap = new HashMap<>();
|
||||
|
||||
final var itemMap = itemsNode.childrenMap();
|
||||
@@ -88,7 +83,8 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
final int green = colorNode.node(GREEN).getInt();
|
||||
final int blue = colorNode.node(BLUE).getInt();
|
||||
|
||||
guiItemMap.put(slot, new ColorItem(guiItem.getItemStack(), Color.fromRGB(red, green, blue)));
|
||||
guiItemMap.put(slot,
|
||||
new ColorItem(guiItem.getItemStack(), Color.fromRGB(red, green, blue)));
|
||||
}
|
||||
|
||||
final BiMap<Integer, ArmorItem.Type> cosmeticSlots = HashBiMap.create();
|
||||
@@ -114,12 +110,14 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
|
||||
String title = titleNode.getString();
|
||||
|
||||
if (title == null) title = "";
|
||||
if (title == null) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
return new DyeSelectorGui(
|
||||
plugin,
|
||||
Adventure.SERIALIZER.serialize(
|
||||
Adventure.MINI_MESSAGE.parse(title)),
|
||||
Adventure.MINI_MESSAGE.deserialize(title)),
|
||||
rowsNode.getInt(),
|
||||
guiItemMap,
|
||||
cosmeticSlots,
|
||||
@@ -127,7 +125,9 @@ public class DyeGuiSerializer implements TypeSerializer<DyeSelectorGui> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final DyeSelectorGui obj, final ConfigurationNode node) throws SerializationException {
|
||||
public void serialize(final Type type, @Nullable final DyeSelectorGui obj,
|
||||
final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,43 +4,42 @@ 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 java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GuiSerializer implements TypeSerializer<CosmeticGui> {
|
||||
|
||||
public static final GuiSerializer INSTANCE = new GuiSerializer();
|
||||
private static final HMCCosmetics plugin;
|
||||
private static final String TITLE = "title";
|
||||
private static final String ROWS = "rows";
|
||||
private static final String ITEMS = "items";
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
public static final GuiSerializer INSTANCE = new GuiSerializer();
|
||||
private GuiSerializer() {
|
||||
}
|
||||
|
||||
private GuiSerializer() {}
|
||||
|
||||
private static final String TITLE = "title";
|
||||
private static final String ROWS = "rows";
|
||||
private static final String ITEMS = "items";
|
||||
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path) throws SerializationException {
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path)
|
||||
throws SerializationException {
|
||||
if (!source.hasChild(path)) {
|
||||
throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node");
|
||||
throw new SerializationException(
|
||||
"Required field " + Arrays.toString(path) + " was not present in node");
|
||||
}
|
||||
return source.node(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CosmeticGui deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
public CosmeticGui deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode titleNode = this.nonVirtualNode(source, TITLE);
|
||||
final ConfigurationNode rowsNode = this.nonVirtualNode(source, ROWS);
|
||||
final ConfigurationNode itemsNode = source.node(ITEMS);
|
||||
@@ -64,17 +63,21 @@ public class GuiSerializer implements TypeSerializer<CosmeticGui> {
|
||||
|
||||
String title = titleNode.getString();
|
||||
|
||||
if (title == null) title = "";
|
||||
if (title == null) {
|
||||
title = "";
|
||||
}
|
||||
|
||||
return new CosmeticGui(plugin,
|
||||
Adventure.SERIALIZER.serialize(
|
||||
Adventure.MINI_MESSAGE.parse(title)),
|
||||
Adventure.MINI_MESSAGE.deserialize(title)),
|
||||
rowsNode.getInt(),
|
||||
guiItemMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final CosmeticGui obj, final ConfigurationNode node) throws SerializationException {
|
||||
public void serialize(final Type type, @Nullable final CosmeticGui obj,
|
||||
final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,7 +10,14 @@ import io.github.fisher2911.hmccosmetics.util.Utils;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.SkullBuilder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
@@ -25,25 +32,10 @@ import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.serialize.SerializationException;
|
||||
import org.spongepowered.configurate.serialize.TypeSerializer;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
|
||||
private static final HMCCosmetics plugin;
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
public static final ItemSerializer INSTANCE = new ItemSerializer();
|
||||
|
||||
private static final HMCCosmetics plugin;
|
||||
private static final String MATERIAL = "material";
|
||||
private static final String AMOUNT = "amount";
|
||||
private static final String NAME = "name";
|
||||
@@ -66,19 +58,26 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
private static final String ID = "id";
|
||||
private static final String DYEABLE = "dyeable";
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
private ItemSerializer() {
|
||||
}
|
||||
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path) throws SerializationException {
|
||||
private ConfigurationNode nonVirtualNode(final ConfigurationNode source, final Object... path)
|
||||
throws SerializationException {
|
||||
if (!source.hasChild(path)) {
|
||||
throw new SerializationException("Required field " + Arrays.toString(path) + " was not present in node");
|
||||
throw new SerializationException(
|
||||
"Required field " + Arrays.toString(path) + " was not present in node");
|
||||
}
|
||||
|
||||
return source.node(path);
|
||||
}
|
||||
|
||||
@Override
|
||||
public GuiItem deserialize(final Type type, final ConfigurationNode source) throws SerializationException {
|
||||
public GuiItem deserialize(final Type type, final ConfigurationNode source)
|
||||
throws SerializationException {
|
||||
final ConfigurationNode materialNode = this.nonVirtualNode(source, MATERIAL);
|
||||
final ConfigurationNode amountNode = source.node(AMOUNT);
|
||||
final ConfigurationNode nameNode = source.node(NAME);
|
||||
@@ -101,7 +100,6 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
final ConfigurationNode idNode = source.node(ID);
|
||||
final ConfigurationNode dyeableNode = source.node(DYEABLE);
|
||||
|
||||
|
||||
final String materialString = Utils.replaceIfNull(materialNode.getString(), "");
|
||||
final int amount = amountNode.getInt();
|
||||
|
||||
@@ -111,24 +109,28 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
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);
|
||||
if (itemStack == null) {
|
||||
itemStack = new ItemStack(Material.AIR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final String name = StringUtils.parseStringToString(nameNode.getString());
|
||||
|
||||
final boolean unbreakable = unbreakableNode.getBoolean();
|
||||
final boolean glowing = glowingNode.getBoolean();
|
||||
|
||||
final List<String> lore = Utils.replaceIfNull(loreNode.getList(String.class), new ArrayList<String>()).
|
||||
final List<String> lore = Utils.replaceIfNull(loreNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
|
||||
|
||||
final List<String> lockedLore = Utils.replaceIfNull(lockedLoreNode.getList(String.class), new ArrayList<String>()).
|
||||
final List<String> lockedLore = Utils.replaceIfNull(lockedLoreNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(StringUtils::parseStringToString).collect(Collectors.toList());
|
||||
|
||||
final int modelData = modelDataNode.getInt();
|
||||
|
||||
final Set<ItemFlag> itemFlags = Utils.replaceIfNull(itemFlagsNode.getList(String.class), new ArrayList<String>()).
|
||||
final Set<ItemFlag> itemFlags = Utils.replaceIfNull(itemFlagsNode.getList(String.class),
|
||||
new ArrayList<String>()).
|
||||
stream().map(flag -> {
|
||||
try {
|
||||
return ItemFlag.valueOf(flag.toUpperCase());
|
||||
@@ -159,9 +161,10 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
return null;
|
||||
}
|
||||
|
||||
final NamespacedKey namespacedKey = NamespacedKey.minecraft(enchantmentString.
|
||||
split(":")[0].
|
||||
toLowerCase());
|
||||
final NamespacedKey namespacedKey = NamespacedKey.minecraft(
|
||||
enchantmentString.
|
||||
split(":")[0].
|
||||
toLowerCase());
|
||||
return Registry.ENCHANTMENT.get(namespacedKey);
|
||||
|
||||
}, enchantmentString -> {
|
||||
@@ -175,7 +178,6 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
final ItemBuilder itemBuilder;
|
||||
|
||||
if (itemStack.getType() == Material.PLAYER_HEAD) {
|
||||
@@ -239,14 +241,14 @@ public class ItemSerializer implements TypeSerializer<GuiItem> {
|
||||
} catch (final IllegalArgumentException exception) {
|
||||
return dev.triumphteam.gui.builder.item.ItemBuilder.from(
|
||||
itemStack).
|
||||
asGuiItem(event -> {
|
||||
plugin.getCosmeticsMenu().openMenu(openMenu, event.getWhoClicked());
|
||||
});
|
||||
asGuiItem(event -> plugin.getCosmeticsMenu().openMenu(openMenu, event.getWhoClicked()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(final Type type, @Nullable final GuiItem obj, final ConfigurationNode node) throws SerializationException {
|
||||
public void serialize(final Type type, @Nullable final GuiItem obj,
|
||||
final ConfigurationNode node) throws SerializationException {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package io.github.fisher2911.hmccosmetics.config;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Settings {
|
||||
|
||||
@@ -22,4 +21,5 @@ public class Settings {
|
||||
public CosmeticSettings getCosmeticSettings() {
|
||||
return settings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package io.github.fisher2911.hmccosmetics.cosmetic;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CosmeticManager {
|
||||
|
||||
@@ -31,4 +29,5 @@ public class CosmeticManager {
|
||||
public Map<String, ArmorItem> getArmorItemMap() {
|
||||
return armorItemMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,6 @@ import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
import com.sun.tools.jconsole.JConsoleContext;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.concurrent.Threads;
|
||||
import io.github.fisher2911.hmccosmetics.database.dao.ArmorItemDAO;
|
||||
@@ -12,19 +11,21 @@ import io.github.fisher2911.hmccosmetics.database.dao.UserDAO;
|
||||
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 org.bukkit.entity.Player;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
public class Database {
|
||||
|
||||
protected final HMCCosmetics plugin;
|
||||
final Dao<UserDAO, UUID> userDao;
|
||||
final Dao<ArmorItemDAO, UUID> armorItemDao;
|
||||
private final ConnectionSource dataSource;
|
||||
private final DatabaseType databaseType;
|
||||
AtomicInteger ARMOR_STAND_ID = new AtomicInteger(Integer.MAX_VALUE);
|
||||
|
||||
String TABLE_NAME = "user";
|
||||
String PLAYER_UUID_COLUMN = "uuid";
|
||||
String BACKPACK_COLUMN = "backpack";
|
||||
@@ -40,14 +41,6 @@ public class Database {
|
||||
PLAYER_UUID_COLUMN +
|
||||
"))";
|
||||
|
||||
protected final HMCCosmetics plugin;
|
||||
private final ConnectionSource dataSource;
|
||||
|
||||
private final DatabaseType databaseType;
|
||||
|
||||
final Dao<UserDAO, UUID> userDao;
|
||||
final Dao<ArmorItemDAO, UUID> armorItemDao;
|
||||
|
||||
public Database(
|
||||
final HMCCosmetics plugin,
|
||||
final ConnectionSource dataSource,
|
||||
@@ -84,9 +77,11 @@ public class Database {
|
||||
user = this.userDao.createIfNotExists(new UserDAO(uuid));
|
||||
}
|
||||
|
||||
final List<ArmorItemDAO> armorItems = this.armorItemDao.queryForEq("uuid", uuid.toString());
|
||||
final List<ArmorItemDAO> armorItems = this.armorItemDao.queryForEq("uuid",
|
||||
uuid.toString());
|
||||
|
||||
final User actualUser = user.toUser(this.plugin.getCosmeticManager(), armorItems, armorStandId);
|
||||
final User actualUser = user.toUser(this.plugin.getCosmeticManager(),
|
||||
armorItems, armorStandId);
|
||||
Bukkit.getScheduler().runTask(this.plugin,
|
||||
() -> {
|
||||
this.plugin.getUserManager().add(
|
||||
@@ -153,4 +148,5 @@ public class Database {
|
||||
public Dao<ArmorItemDAO, UUID> getArmorItemDao() {
|
||||
return armorItemDao;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
package io.github.fisher2911.hmccosmetics.database;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
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 org.bukkit.Color;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
@@ -21,20 +16,20 @@ import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
public class DatabaseConverter {
|
||||
|
||||
private static final int CURRENT_VERSION = 2;
|
||||
private static final String FILE_NAME = "info.yml";
|
||||
private final HMCCosmetics plugin;
|
||||
private final Database database;
|
||||
private static final int CURRENT_VERSION = 2;
|
||||
|
||||
public DatabaseConverter(final HMCCosmetics plugin, final Database database) {
|
||||
this.database = database;
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private static final String FILE_NAME = "info.yml";
|
||||
|
||||
public void convert() {
|
||||
final File folder = new File(this.plugin.getDataFolder(), "database");
|
||||
|
||||
@@ -65,7 +60,9 @@ public class DatabaseConverter {
|
||||
|
||||
this.database.createTables();
|
||||
|
||||
for (final User user : users) database.saveUser(user);
|
||||
for (final User user : users) {
|
||||
database.saveUser(user);
|
||||
}
|
||||
}
|
||||
|
||||
private void convert(final int version, final Consumer<User> consumer) {
|
||||
@@ -77,12 +74,14 @@ public class DatabaseConverter {
|
||||
private void convertVersionOne(final Consumer<User> consumer) {
|
||||
final String query = "SELECT * from user";
|
||||
|
||||
try (final PreparedStatement statement = this.database.getDataSource().getReadOnlyConnection("user").
|
||||
try (final PreparedStatement statement = this.database.getDataSource()
|
||||
.getReadOnlyConnection("user").
|
||||
getUnderlyingConnection().prepareStatement(query)) {
|
||||
final ResultSet results = statement.executeQuery();
|
||||
try {
|
||||
|
||||
final Map<String, ArmorItem> armorItems = new ConcurrentHashMap<>(this.plugin.getCosmeticManager().getArmorItemMap());
|
||||
final Map<String, ArmorItem> armorItems = new ConcurrentHashMap<>(
|
||||
this.plugin.getCosmeticManager().getArmorItemMap());
|
||||
|
||||
while (results.next()) {
|
||||
final PlayerArmor playerArmor = PlayerArmor.empty();
|
||||
@@ -97,7 +96,9 @@ public class DatabaseConverter {
|
||||
|
||||
final ArmorItem backpack = armorItems.get(backpackId);
|
||||
final ArmorItem hat = armorItems.get(hatId);
|
||||
if (backpack != null) playerArmor.setItem(backpack);
|
||||
if (backpack != null) {
|
||||
playerArmor.setItem(backpack);
|
||||
}
|
||||
if (hat != null) {
|
||||
hat.setDye(hatDye);
|
||||
playerArmor.setItem(hat);
|
||||
@@ -112,11 +113,13 @@ public class DatabaseConverter {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
try (final PreparedStatement dropStatement = this.database.getDataSource().getReadWriteConnection("user").
|
||||
try (final PreparedStatement dropStatement = this.database.getDataSource()
|
||||
.getReadWriteConnection("user").
|
||||
getUnderlyingConnection().prepareStatement("DROP TABLE user")) {
|
||||
dropStatement.executeUpdate();
|
||||
} catch (final SQLException exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,18 +5,18 @@ import com.j256.ormlite.jdbc.JdbcPooledConnectionSource;
|
||||
import com.zaxxer.hikari.HikariConfig;
|
||||
import com.zaxxer.hikari.HikariDataSource;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.sql.SQLException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
public class DatabaseFactory {
|
||||
|
||||
private static final String FILE_NAME = "database.yml";
|
||||
private static final Path FILE_PATH = HMCCosmetics.PLUGIN_FOLDER.resolve("database.yml");
|
||||
private static final String TYPE_PATH = "type";
|
||||
private static final String NAME_PATH = "name";
|
||||
private static final String USERNAME_PATH = "username";
|
||||
@@ -25,13 +25,11 @@ public class DatabaseFactory {
|
||||
private static final String PORT_PATH = "port";
|
||||
|
||||
public static Database create(final HMCCosmetics plugin) throws SQLException {
|
||||
final File file = Path.of(plugin.getDataFolder().getPath(), FILE_NAME).toFile();
|
||||
|
||||
if (!file.exists()) {
|
||||
plugin.saveResource(FILE_NAME, false);
|
||||
if (!Files.exists(FILE_PATH)) {
|
||||
plugin.saveResource(FILE_PATH.getFileName().toString(), false);
|
||||
}
|
||||
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(file);
|
||||
final FileConfiguration config = YamlConfiguration.loadConfiguration(FILE_PATH.toFile());
|
||||
|
||||
final String type = config.getString(TYPE_PATH);
|
||||
|
||||
@@ -82,7 +80,8 @@ public class DatabaseFactory {
|
||||
};
|
||||
|
||||
if (database == null) {
|
||||
logger.severe("Error loading database, type " + type + " is invalid! Disabling plugin.");
|
||||
logger.severe(
|
||||
"Error loading database, type " + type + " is invalid! Disabling plugin.");
|
||||
Bukkit.getPluginManager().disablePlugin(plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,9 +4,8 @@ import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Objects;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@DatabaseTable(tableName = "armor_items")
|
||||
public class ArmorItemDAO {
|
||||
@@ -33,22 +32,25 @@ public class ArmorItemDAO {
|
||||
this.rgbDye = rgbDye;
|
||||
}
|
||||
|
||||
public ArmorItemDAO() {
|
||||
}
|
||||
|
||||
public static ArmorItemDAO fromArmorItem(final ArmorItem armorItem) {
|
||||
return new ArmorItemDAO(armorItem.getId(), armorItem.getType().toString(), armorItem.getDye());
|
||||
return new ArmorItemDAO(armorItem.getId(), armorItem.getType().toString(),
|
||||
armorItem.getDye());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public ArmorItem toArmorItem(final CosmeticManager cosmeticManager) {
|
||||
final ArmorItem armorItem = cosmeticManager.getArmorItem(this.id);
|
||||
if (armorItem == null) return null;
|
||||
if (armorItem == null) {
|
||||
return null;
|
||||
}
|
||||
final ArmorItem copy = new ArmorItem(armorItem);
|
||||
copy.setDye(this.rgbDye);
|
||||
return copy;
|
||||
}
|
||||
|
||||
public ArmorItemDAO() {
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
@@ -59,6 +61,7 @@ public class ArmorItemDAO {
|
||||
|
||||
/**
|
||||
* ORMLite does not allow more than one primary key (WHYYYY???????????)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getArtificialId() {
|
||||
@@ -91,10 +94,15 @@ public class ArmorItemDAO {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final ArmorItemDAO that = (ArmorItemDAO) o;
|
||||
return Objects.equals(getUuid(), that.getUuid()) && Objects.equals(getType(), that.getType());
|
||||
return Objects.equals(getUuid(), that.getUuid()) && Objects.equals(getType(),
|
||||
that.getType());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,4 +119,5 @@ public class ArmorItemDAO {
|
||||
", rgbDye=" + rgbDye +
|
||||
'}';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
package io.github.fisher2911.hmccosmetics.database.dao;
|
||||
|
||||
import com.j256.ormlite.dao.ForeignCollection;
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.field.ForeignCollectionField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
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 java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
@@ -24,20 +19,23 @@ public class UserDAO {
|
||||
public UserDAO() {
|
||||
}
|
||||
|
||||
public void setUuid(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public UserDAO(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public User toUser(final CosmeticManager cosmeticManager, final List<ArmorItemDAO> armorItems, final int armorStandId) {
|
||||
public void setUuid(final UUID uuid) {
|
||||
this.uuid = uuid;
|
||||
}
|
||||
|
||||
public User toUser(final CosmeticManager cosmeticManager, final List<ArmorItemDAO> armorItems,
|
||||
final int armorStandId) {
|
||||
final PlayerArmor playerArmor = PlayerArmor.empty();
|
||||
|
||||
for (final ArmorItemDAO armorItemDao : armorItems) {
|
||||
final ArmorItem armorItem = armorItemDao.toArmorItem(cosmeticManager);
|
||||
if (armorItem == null) continue;
|
||||
if (armorItem == null) {
|
||||
continue;
|
||||
}
|
||||
playerArmor.setItem(armorItem);
|
||||
}
|
||||
|
||||
@@ -53,8 +51,12 @@ public class UserDAO {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final UserDAO userDAO = (UserDAO) o;
|
||||
return Objects.equals(uuid, userDAO.uuid);
|
||||
}
|
||||
@@ -63,4 +65,5 @@ public class UserDAO {
|
||||
public int hashCode() {
|
||||
return Objects.hash(uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,9 @@ import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ColorBuilder;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
@@ -11,17 +14,13 @@ import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class ArmorItem extends GuiItem {
|
||||
|
||||
private final String id;
|
||||
private final List<String> lockedLore;
|
||||
private GuiAction<InventoryClickEvent> action;
|
||||
private final String permission;
|
||||
private final Type type;
|
||||
private GuiAction<InventoryClickEvent> action;
|
||||
private boolean dyeable;
|
||||
private int dye;
|
||||
|
||||
@@ -166,17 +165,6 @@ public class ArmorItem extends GuiItem {
|
||||
this.dye = dye;
|
||||
}
|
||||
|
||||
public static ArmorItem empty(final Type type) {
|
||||
return new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
"",
|
||||
new ArrayList<>(),
|
||||
"",
|
||||
type,
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
public ArmorItem(final ArmorItem armorItem) {
|
||||
super(armorItem.getItemStack(), armorItem.getAction());
|
||||
this.id = armorItem.getId();
|
||||
@@ -189,6 +177,17 @@ public class ArmorItem extends GuiItem {
|
||||
this.dye = armorItem.getDye();
|
||||
}
|
||||
|
||||
public static ArmorItem empty(final Type type) {
|
||||
return new ArmorItem(
|
||||
new ItemStack(Material.AIR),
|
||||
"",
|
||||
new ArrayList<>(),
|
||||
"",
|
||||
type,
|
||||
-1
|
||||
);
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@@ -201,6 +200,12 @@ public class ArmorItem extends GuiItem {
|
||||
return this.action;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAction(final GuiAction<InventoryClickEvent> action) {
|
||||
super.setAction(action);
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public String getPermission() {
|
||||
return permission;
|
||||
}
|
||||
@@ -253,12 +258,6 @@ public class ArmorItem extends GuiItem {
|
||||
return this.getItemStack().getType() == Material.AIR;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAction(final GuiAction<InventoryClickEvent> action) {
|
||||
super.setAction(action);
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public ArmorItem copy() {
|
||||
return new ArmorItem(this);
|
||||
}
|
||||
@@ -272,4 +271,5 @@ public class ArmorItem extends GuiItem {
|
||||
OFF_HAND
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,9 @@ public class ColorItem extends GuiItem {
|
||||
|
||||
private final Color color;
|
||||
|
||||
public ColorItem(final @NotNull ItemStack itemStack, final GuiAction<InventoryClickEvent> action, final Color color) {
|
||||
public ColorItem(final @NotNull ItemStack itemStack,
|
||||
final GuiAction<InventoryClickEvent> action,
|
||||
final Color color) {
|
||||
super(itemStack, action);
|
||||
this.color = color;
|
||||
}
|
||||
@@ -28,7 +30,8 @@ public class ColorItem extends GuiItem {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public ColorItem(final @NotNull Material material, final @Nullable GuiAction<InventoryClickEvent> action, final Color color) {
|
||||
public ColorItem(final @NotNull Material material,
|
||||
final @Nullable GuiAction<InventoryClickEvent> action, final Color color) {
|
||||
super(material, action);
|
||||
this.color = color;
|
||||
}
|
||||
@@ -36,4 +39,5 @@ public class ColorItem extends GuiItem {
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.fisher2911.hmccosmetics.gui;
|
||||
|
||||
import com.comphenix.net.bytebuddy.jar.asm.Type;
|
||||
import dev.triumphteam.gui.components.GuiAction;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
@@ -11,21 +10,20 @@ import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Messages;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class CosmeticGui {
|
||||
|
||||
private static final float COOL_DOWN = 0.5f;
|
||||
protected final HMCCosmetics plugin;
|
||||
protected final MessageHandler messageHandler;
|
||||
protected final String title;
|
||||
@@ -33,11 +31,8 @@ public class CosmeticGui {
|
||||
protected final Map<Integer, ItemStack> itemStackMap;
|
||||
protected final Map<Integer, GuiItem> guiItemMap;
|
||||
protected Gui gui;
|
||||
|
||||
private long lastClicked;
|
||||
|
||||
private static final float COOL_DOWN = 0.5f;
|
||||
|
||||
public CosmeticGui(
|
||||
final HMCCosmetics plugin,
|
||||
final String title,
|
||||
@@ -53,7 +48,6 @@ public class CosmeticGui {
|
||||
}
|
||||
|
||||
private void setItems(final User user) {
|
||||
|
||||
final Player player = user.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
@@ -64,7 +58,9 @@ public class CosmeticGui {
|
||||
final int slot = entry.getKey();
|
||||
|
||||
final GuiItem guiItem = this.getGuiItem(user, player, slot);
|
||||
if (guiItem == null) continue;
|
||||
if (guiItem == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.gui.setItem(slot, guiItem);
|
||||
}
|
||||
@@ -78,7 +74,9 @@ public class CosmeticGui {
|
||||
final GuiAction<InventoryClickEvent> actionIfSet) {
|
||||
|
||||
final long current = System.currentTimeMillis();
|
||||
if ((current - this.lastClicked) / 1000. < COOL_DOWN) return;
|
||||
if ((current - this.lastClicked) / 1000. < COOL_DOWN) {
|
||||
return;
|
||||
}
|
||||
this.lastClicked = current;
|
||||
|
||||
if (!(human instanceof final Player player)) {
|
||||
@@ -102,13 +100,16 @@ public class CosmeticGui {
|
||||
|
||||
final GuiItem guiItem = this.getGuiItem(user, player, slot);
|
||||
|
||||
if (guiItem == null) return;
|
||||
if (guiItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gui.updateItem(slot, guiItem);
|
||||
}
|
||||
|
||||
public void open(final HumanEntity humanEntity) {
|
||||
final Optional<User> optionalUser = this.plugin.getUserManager().get(humanEntity.getUniqueId());
|
||||
final Optional<User> optionalUser = this.plugin.getUserManager()
|
||||
.get(humanEntity.getUniqueId());
|
||||
|
||||
if (optionalUser.isEmpty()) {
|
||||
return;
|
||||
@@ -117,7 +118,8 @@ public class CosmeticGui {
|
||||
final User user = optionalUser.get();
|
||||
|
||||
this.gui = Gui.gui().
|
||||
title(Adventure.MINI_MESSAGE.parse(Placeholder.applyPapiPlaceholders(user.getPlayer(), this.title))).
|
||||
title(Adventure.MINI_MESSAGE.deserialize(
|
||||
Placeholder.applyPapiPlaceholders(user.getPlayer(), this.title))).
|
||||
rows(this.rows).
|
||||
create();
|
||||
|
||||
@@ -132,15 +134,19 @@ public class CosmeticGui {
|
||||
private GuiItem getGuiItem(final User user, final Player player, final int slot) {
|
||||
final GuiItem guiItem = this.guiItemMap.get(slot);
|
||||
|
||||
if (guiItem == null) return null;
|
||||
if (guiItem == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final ItemStack itemStack = this.itemStackMap.get(slot);
|
||||
|
||||
if (itemStack == null) return null;
|
||||
if (itemStack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (guiItem instanceof final ArmorItem armorItem) {
|
||||
|
||||
final String permission = armorItem.getPermission() == null ? "" : armorItem.getPermission();
|
||||
final String permission =
|
||||
armorItem.getPermission() == null ? "" : armorItem.getPermission();
|
||||
|
||||
final boolean hasPermission = permission.isBlank() || player.hasPermission(permission);
|
||||
|
||||
@@ -155,9 +161,12 @@ public class CosmeticGui {
|
||||
return;
|
||||
}
|
||||
|
||||
final ArmorItem cosmeticItem = this.plugin.getCosmeticManager().getArmorItem(armorItem.getId());
|
||||
final ArmorItem cosmeticItem = this.plugin.getCosmeticManager()
|
||||
.getArmorItem(armorItem.getId());
|
||||
|
||||
if (cosmeticItem == null) return;
|
||||
if (cosmeticItem == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.setUserArmor(player, user, cosmeticItem, event, armorItem.getAction());
|
||||
}
|
||||
@@ -171,7 +180,8 @@ public class CosmeticGui {
|
||||
return guiItem;
|
||||
}
|
||||
|
||||
protected ItemStack applyPlaceholders(final User user, final Player player, final ArmorItem armorItem, final boolean hasPermission) {
|
||||
protected ItemStack applyPlaceholders(final User user, final Player player,
|
||||
final ArmorItem armorItem, final boolean hasPermission) {
|
||||
final Map<String, String> placeholders = new HashMap<>();
|
||||
|
||||
final PlayerArmor playerArmor = user.getPlayerArmor();
|
||||
@@ -214,4 +224,5 @@ public class CosmeticGui {
|
||||
new HashMap<>(this.guiItemMap)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,6 +7,10 @@ import io.github.fisher2911.hmccosmetics.config.GuiSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.config.ItemSerializer;
|
||||
import io.github.fisher2911.hmccosmetics.cosmetic.CosmeticManager;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -16,12 +20,6 @@ import org.spongepowered.configurate.ConfigurateException;
|
||||
import org.spongepowered.configurate.ConfigurationNode;
|
||||
import org.spongepowered.configurate.yaml.YamlConfigurationLoader;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Path;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public class CosmeticsMenu {
|
||||
|
||||
public static final String MAIN_MENU = "main";
|
||||
@@ -76,7 +74,9 @@ public class CosmeticsMenu {
|
||||
@Nullable
|
||||
private CosmeticGui getGui(final String id) {
|
||||
final CosmeticGui gui = this.guiMap.get(id);
|
||||
if (gui == null) return null;
|
||||
if (gui == null) {
|
||||
return null;
|
||||
}
|
||||
return gui.copy();
|
||||
}
|
||||
|
||||
@@ -95,8 +95,8 @@ public class CosmeticsMenu {
|
||||
}
|
||||
|
||||
if (!Path.of(this.plugin.getDataFolder().getPath(),
|
||||
"menus",
|
||||
DYE_MENU + ".yml").toFile().exists()) {
|
||||
"menus",
|
||||
DYE_MENU + ".yml").toFile().exists()) {
|
||||
this.plugin.saveResource(
|
||||
new File("menus", DYE_MENU + ".yml").getPath(),
|
||||
false
|
||||
@@ -134,22 +134,28 @@ public class CosmeticsMenu {
|
||||
final ConfigurationNode source = loader.load();
|
||||
|
||||
if (id.equals(DYE_MENU)) {
|
||||
this.guiMap.put(id, DyeGuiSerializer.INSTANCE.deserialize(DyeSelectorGui.class, source));
|
||||
this.guiMap.put(id,
|
||||
DyeGuiSerializer.INSTANCE.deserialize(DyeSelectorGui.class, source));
|
||||
this.plugin.getLogger().info("Loaded dye gui: " + id);
|
||||
continue;
|
||||
}
|
||||
|
||||
final CosmeticGui gui = source.get(CosmeticGui.class);
|
||||
|
||||
if (gui == null) continue;
|
||||
if (gui == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (final GuiItem guiItem : gui.guiItemMap.values()) {
|
||||
if (guiItem instanceof final ArmorItem item) {
|
||||
final ArmorItem copy = new ArmorItem(item);
|
||||
copy.setAction(null);
|
||||
this.cosmeticManager.addArmorItem(copy);
|
||||
if (copy.getPermission().isBlank()) continue;
|
||||
Bukkit.getPluginManager().addPermission(new Permission(copy.getPermission()));
|
||||
if (copy.getPermission().isBlank()) {
|
||||
continue;
|
||||
}
|
||||
Bukkit.getPluginManager()
|
||||
.addPermission(new Permission(copy.getPermission()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,4 +167,5 @@ public class CosmeticsMenu {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,12 +5,13 @@ import com.google.common.collect.HashBiMap;
|
||||
import dev.triumphteam.gui.guis.Gui;
|
||||
import dev.triumphteam.gui.guis.GuiItem;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.database.dao.ArmorItemDAO;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
@@ -18,10 +19,6 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class DyeSelectorGui extends CosmeticGui {
|
||||
|
||||
private final BiMap<Integer, ArmorItem.Type> cosmeticsSlots;
|
||||
@@ -46,7 +43,8 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
|
||||
public Gui getGui(final User user, @Nullable final ArmorItem.Type type) {
|
||||
this.gui = Gui.gui().
|
||||
title(Component.text(Placeholder.applyPapiPlaceholders(user.getPlayer(), this.title))).
|
||||
title(Component.text(
|
||||
Placeholder.applyPapiPlaceholders(user.getPlayer(), this.title))).
|
||||
rows(rows).
|
||||
create();
|
||||
|
||||
@@ -77,7 +75,9 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
|
||||
final ItemStack itemStack = this.itemStackMap.get(entry.getKey());
|
||||
|
||||
if (itemStack == null) continue;
|
||||
if (itemStack == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
guiItem.setItemStack(
|
||||
ItemBuilder.from(itemStack.clone()).papiPlaceholders(player).build()
|
||||
@@ -162,7 +162,9 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
private void updateSelected(final User user, final Player player) {
|
||||
final ArmorItem.Type type = this.cosmeticsSlots.get(this.selectedCosmetic);
|
||||
|
||||
if (type == null) return;
|
||||
if (type == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.gui.updateItem(this.selectedCosmetic,
|
||||
|
||||
@@ -176,7 +178,8 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
@Override
|
||||
public void open(final HumanEntity player) {
|
||||
final Optional<User> optionalUser = this.plugin.getUserManager().get(player.getUniqueId());
|
||||
optionalUser.ifPresent(user -> this.getGui(user, user.getLastSetItem().getType()).open(player));
|
||||
optionalUser.ifPresent(
|
||||
user -> this.getGui(user, user.getLastSetItem().getType()).open(player));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -194,4 +197,5 @@ public class DyeSelectorGui extends CosmeticGui {
|
||||
this.selectedCosmetic
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,15 +5,14 @@ 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;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class HookManager {
|
||||
|
||||
@@ -23,12 +22,7 @@ public class 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;
|
||||
@@ -49,7 +43,9 @@ 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);
|
||||
if (pluginManager.getPlugin("Oraxen") != null) {
|
||||
itemHookMap.put(oraxenHook.getIdentifier(), oraxenHook);
|
||||
}
|
||||
if (pluginManager.getPlugin("ItemsAdder") != null) {
|
||||
itemHookMap.put(itemsAdderHook.getIdentifier(), itemsAdderHook);
|
||||
this.listeners.add(itemsAdderHook);
|
||||
@@ -59,6 +55,10 @@ public class HookManager {
|
||||
itemHookMap.values().forEach(hook -> this.registerHook(hook.getClass()));
|
||||
}
|
||||
|
||||
public static HookManager getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
protected void registerHook(final Class<? extends Hook> hook) {
|
||||
this.registeredHooks.add(hook);
|
||||
}
|
||||
@@ -81,4 +81,5 @@ public class HookManager {
|
||||
public ItemHooks getItemHooks() {
|
||||
return itemHooks;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
package io.github.fisher2911.hmccosmetics.hook.item;
|
||||
|
||||
import java.util.Map;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class ItemHooks {
|
||||
|
||||
private final Map<String, ItemHook> itemHookMap;
|
||||
@@ -17,20 +16,27 @@ 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 StringBuilder itemId = new StringBuilder();
|
||||
|
||||
for (int i = 1; i < parts.length; i++) {
|
||||
itemId.append(parts[i]);
|
||||
if (i < parts.length - 1) itemId.append(":");
|
||||
if (i < parts.length - 1) {
|
||||
itemId.append(":");
|
||||
}
|
||||
}
|
||||
|
||||
final ItemHook hook = this.itemHookMap.get(identifier);
|
||||
|
||||
if (hook == null) return null;
|
||||
if (hook == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return hook.getItem(itemId.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -32,7 +32,10 @@ public class ItemsAdderHook implements ItemHook, Listener {
|
||||
@Override
|
||||
public ItemStack getItem(final String id) {
|
||||
final CustomStack stack = CustomStack.getInstance(id);
|
||||
if (stack == null) return null;
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
return stack.getItemStack().clone();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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;
|
||||
@@ -23,7 +22,10 @@ public class OraxenHook implements ItemHook {
|
||||
@Override
|
||||
public ItemStack getItem(final String id) {
|
||||
final ItemBuilder itemBuilder = OraxenItems.getItemById(id);
|
||||
if (itemBuilder == null) return null;
|
||||
if (itemBuilder == null) {
|
||||
return null;
|
||||
}
|
||||
return itemBuilder.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.github.fisher2911.hmccosmetics.inventory;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@@ -19,6 +17,10 @@ public class PlayerArmor {
|
||||
this.armorItems.put(offHand.getType(), offHand);
|
||||
}
|
||||
|
||||
public PlayerArmor(final Map<ArmorItem.Type, ArmorItem> armorItems) {
|
||||
this.armorItems = armorItems;
|
||||
}
|
||||
|
||||
public static PlayerArmor empty() {
|
||||
return new PlayerArmor(
|
||||
ArmorItem.empty(ArmorItem.Type.HAT),
|
||||
@@ -27,10 +29,6 @@ public class PlayerArmor {
|
||||
);
|
||||
}
|
||||
|
||||
public PlayerArmor(final Map<ArmorItem.Type, ArmorItem> armorItems) {
|
||||
this.armorItems = armorItems;
|
||||
}
|
||||
|
||||
public ArmorItem getHat() {
|
||||
return this.getItem(ArmorItem.Type.HAT);
|
||||
}
|
||||
@@ -63,4 +61,5 @@ public class PlayerArmor {
|
||||
public PlayerArmor copy() {
|
||||
return new PlayerArmor(new HashMap<>(this.armorItems));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,8 @@ package io.github.fisher2911.hmccosmetics.listener;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -12,9 +14,6 @@ import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryCloseEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public class ClickListener implements Listener {
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
@@ -30,14 +29,18 @@ public class ClickListener implements Listener {
|
||||
@EventHandler
|
||||
public void onCosmeticClick(final InventoryClickEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!(player instanceof Player)) return;
|
||||
if (!(player instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
this.fixInventory((Player) player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onCosmeticClick(final InventoryDragEvent event) {
|
||||
final HumanEntity player = event.getWhoClicked();
|
||||
if (!(player instanceof Player)) return;
|
||||
if (!(player instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
this.fixInventory((Player) player);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.github.fisher2911.hmccosmetics.listener;
|
||||
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -10,13 +9,10 @@ import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.bukkit.event.inventory.InventoryDragEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerSwapHandItemsEvent;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.PlayerInventory;
|
||||
import org.spigotmc.event.entity.EntityMountEvent;
|
||||
|
||||
public class CosmeticFixListener implements Listener {
|
||||
@@ -31,34 +27,47 @@ public class CosmeticFixListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onEntityMount(final EntityMountEvent event) {
|
||||
if (!(event.getEntity() instanceof final Player player)) return;
|
||||
if (!(event.getEntity() instanceof final Player player)) {
|
||||
return;
|
||||
}
|
||||
this.fixCosmetics(player);
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onOffhandSwap(final PlayerSwapHandItemsEvent event) {
|
||||
final ItemStack offHand = event.getOffHandItem();
|
||||
if (offHand != null && offHand.getType() != Material.AIR) return;
|
||||
if (offHand != null && offHand.getType() != Material.AIR) {
|
||||
return;
|
||||
}
|
||||
this.fixCosmetics(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onRightClick(final PlayerInteractEvent event) {
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK && event.getHand() != EquipmentSlot.OFF_HAND) return;
|
||||
if (event.getAction() != Action.RIGHT_CLICK_BLOCK
|
||||
&& event.getHand() != EquipmentSlot.OFF_HAND) {
|
||||
return;
|
||||
}
|
||||
final Player player = event.getPlayer();
|
||||
|
||||
final ItemStack mainHand = event.getPlayer().getInventory().getItemInMainHand();
|
||||
|
||||
if (mainHand.getType().isBlock() && mainHand.getAmount() > 0) return;
|
||||
if (mainHand.getType().isBlock() && mainHand.getAmount() > 0) {
|
||||
return;
|
||||
}
|
||||
this.userManager.updateCosmetics(player.getUniqueId(), true);
|
||||
}
|
||||
|
||||
@EventHandler(ignoreCancelled = true)
|
||||
public void onBlockPlace(final BlockPlaceEvent event) {
|
||||
if (event.getHand() != EquipmentSlot.OFF_HAND) return;
|
||||
if (event.getHand() != EquipmentSlot.OFF_HAND) {
|
||||
return;
|
||||
}
|
||||
final ItemStack itemStack = event.getItemInHand();
|
||||
|
||||
if (itemStack.getAmount() > 1) return;
|
||||
if (itemStack.getAmount() > 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.fixCosmetics(event.getPlayer());
|
||||
}
|
||||
@@ -67,4 +76,5 @@ public class CosmeticFixListener implements Listener {
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(this.plugin,
|
||||
() -> this.userManager.updateCosmetics(player.getUniqueId(), true), 2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class JoinListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
this.database.loadUser(player.getUniqueId(),
|
||||
user -> Bukkit.getScheduler().runTaskAsynchronously(this.plugin,
|
||||
() -> this.userManager.resendCosmetics(player)));
|
||||
() -> this.userManager.resendCosmetics(player)));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@@ -35,4 +35,5 @@ public class JoinListener implements Listener {
|
||||
final Player player = event.getPlayer();
|
||||
this.userManager.remove(player.getUniqueId());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@ package io.github.fisher2911.hmccosmetics.listener;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.user.User;
|
||||
import io.github.fisher2911.hmccosmetics.user.UserManager;
|
||||
import java.util.Optional;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerRespawnEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class RespawnListener implements Listener {
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
@@ -33,4 +32,5 @@ public class RespawnListener implements Listener {
|
||||
});
|
||||
}, 1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,8 +34,12 @@ public class Message {
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
final Message message = (Message) o;
|
||||
return Objects.equals(key, message.key);
|
||||
}
|
||||
@@ -54,4 +58,5 @@ public class Message {
|
||||
TITLE
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +1,21 @@
|
||||
package io.github.fisher2911.hmccosmetics.message;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.util.StringUtils;
|
||||
import io.github.fisher2911.hmccosmetics.util.Utils;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.kyori.adventure.title.Title;
|
||||
import net.md_5.bungee.api.ChatMessageType;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class MessageHandler {
|
||||
|
||||
@@ -40,23 +40,24 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendMessage(final CommandSender sender, final Message key, final Map<String, String> placeholders) {
|
||||
public void sendMessage(final CommandSender sender, final Message key,
|
||||
final Map<String, String> placeholders) {
|
||||
final String message = this.getPapiPlaceholders(
|
||||
sender,
|
||||
Placeholder.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
final Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.sender(sender).sendMessage(component);
|
||||
final Component component = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
sender.spigot().sendMessage(BungeeComponentSerializer.get().serialize(component));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param sender receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendMessage(final CommandSender sender, final Message key) {
|
||||
@@ -64,23 +65,24 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendActionBar(final Player player, final Message key, final Map<String, String> placeholders) {
|
||||
public void sendActionBar(final Player player, final Message key,
|
||||
final Map<String, String> placeholders) {
|
||||
final String message = this.getPapiPlaceholders(
|
||||
player,
|
||||
Placeholder.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
this.adventure.player(player).sendActionBar(component);
|
||||
Component component = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, BungeeComponentSerializer.get().serialize(component));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendActionBar(final Player player, final Message key) {
|
||||
@@ -88,23 +90,24 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param placeholders placeholders
|
||||
*/
|
||||
|
||||
public void sendTitle(final Player player, final Message key, final Map<String, String> placeholders) {
|
||||
public void sendTitle(final Player player, final Message key,
|
||||
final Map<String, String> placeholders) {
|
||||
final String message = this.getPapiPlaceholders(
|
||||
player,
|
||||
Placeholder.applyPlaceholders(this.getMessage(key), placeholders)
|
||||
);
|
||||
Component component = Adventure.MINI_MESSAGE.parse(message);
|
||||
Component component = Adventure.MINI_MESSAGE.deserialize(message);
|
||||
this.adventure.player(player).showTitle(Title.title(component, Component.empty()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param player receiver of message
|
||||
* @param key message key
|
||||
* @param key message key
|
||||
*/
|
||||
|
||||
public void sendTitle(final Player player, final Message key) {
|
||||
@@ -144,12 +147,14 @@ public class MessageHandler {
|
||||
for (final String key : config.getKeys(false)) {
|
||||
final String message = Utils.replaceIfNull(config.getString(key), "", value -> {
|
||||
if (value == null) {
|
||||
this.logger.warning(String.format(ErrorMessages.ITEM_NOT_FOUND, "message", fileName));
|
||||
this.logger.warning(
|
||||
String.format(ErrorMessages.ITEM_NOT_FOUND, "message", fileName));
|
||||
}
|
||||
}).replace(Placeholder.PREFIX, prefix);
|
||||
|
||||
final Message.Type messageType = Utils.stringToEnum(
|
||||
Utils.replaceIfNull(config.getString("type"), ""), Message.Type.class, Message.Type.MESSAGE
|
||||
Utils.replaceIfNull(config.getString("type"), ""), Message.Type.class,
|
||||
Message.Type.MESSAGE
|
||||
);
|
||||
|
||||
this.messageMap.put(key, new Message(key, message, messageType));
|
||||
@@ -157,10 +162,10 @@ public class MessageHandler {
|
||||
}
|
||||
|
||||
private String getPapiPlaceholders(final CommandSender sender, final String message) {
|
||||
if (sender instanceof final Player player) {
|
||||
return Placeholder.applyPapiPlaceholders(player, message);
|
||||
}
|
||||
return Placeholder.applyPapiPlaceholders(null, message);
|
||||
if (sender instanceof final Player player) {
|
||||
return Placeholder.applyPapiPlaceholders(player, message);
|
||||
}
|
||||
return Placeholder.applyPapiPlaceholders(null, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,17 +34,19 @@ public class Messages {
|
||||
public static final Message ITEM_NOT_FOUND =
|
||||
new Message("item-not-found", ChatColor.RED + "That item could not be found!");
|
||||
public static final Message HELP_COMMAND =
|
||||
new Message("help-command", "<#6D9DC5><st> </st> <gradient:#40B7D6:#6D9DC5>HMCCosmetics - Help</gradient><#6D9DC5> <st> </st>\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"<#5AE4B5>• <#40B7D6>/cosmetics - <#6D9DC5>Opens cosmetics GUI.\n" +
|
||||
"\n" +
|
||||
"<#5AE4B5>• <#40B7D6>/cosmetics dye <gray><BACKPACK/HAT></gray> - <#6D9DC5>Opens dye menu for specified cosmetic.\n" +
|
||||
"\n" +
|
||||
"<#5AE4B5>• <#40B7D6>/cosmetics help - <#6D9DC5>Opens this menu.\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"<st> </st>");
|
||||
new Message("help-command",
|
||||
"""
|
||||
<#6D9DC5><st> </st> <gradient:#40B7D6:#6D9DC5>HMCCosmetics - Help</gradient><#6D9DC5> <st> </st>
|
||||
|
||||
|
||||
<#5AE4B5>• <#40B7D6>/cosmetics - <#6D9DC5>Opens cosmetics GUI.
|
||||
|
||||
<#5AE4B5>• <#40B7D6>/cosmetics dye <gray><BACKPACK/HAT></gray> - <#6D9DC5>Opens dye menu for specified cosmetic.
|
||||
|
||||
<#5AE4B5>• <#40B7D6>/cosmetics help - <#6D9DC5>Opens this menu.
|
||||
|
||||
|
||||
<st> </st>""");
|
||||
|
||||
public static final Message SET_OTHER_BACKPACK = new Message(
|
||||
"set-other-backpack", ChatColor.GREEN + "You have set the backpack of " +
|
||||
|
||||
@@ -2,11 +2,10 @@ package io.github.fisher2911.hmccosmetics.message;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.hook.HookManager;
|
||||
import io.github.fisher2911.hmccosmetics.hook.PAPIHook;
|
||||
import java.util.Map;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class Placeholder {
|
||||
|
||||
public static final String PREFIX = "%prefix%";
|
||||
@@ -19,7 +18,7 @@ public class Placeholder {
|
||||
public static final String ALLOWED = "%allowed%";
|
||||
|
||||
/**
|
||||
* @param message message being translated
|
||||
* @param message message being translated
|
||||
* @param placeholders placeholders applied
|
||||
* @return message with placeholders applied
|
||||
*/
|
||||
@@ -31,11 +30,13 @@ public class Placeholder {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static String applyPapiPlaceholders(@Nullable final Player player, final String message) {
|
||||
public static String applyPapiPlaceholders(@Nullable final Player player,
|
||||
final String message) {
|
||||
if (HookManager.getInstance().isEnabled(PAPIHook.class)) {
|
||||
return HookManager.getInstance().getPapiHook().parse(player, message);
|
||||
}
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,23 @@
|
||||
package io.github.fisher2911.hmccosmetics.message;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class Translation {
|
||||
|
||||
private static final Translation INSTANCE;
|
||||
private static final String FILE_NAME = "translations.yml";
|
||||
private static final String TRANSLATION_PATH = "translations";
|
||||
|
||||
static {
|
||||
INSTANCE = new Translation(HMCCosmetics.getPlugin(HMCCosmetics.class));
|
||||
}
|
||||
|
||||
public static Translation getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final HMCCosmetics plugin;
|
||||
private final Map<String, String> translations;
|
||||
|
||||
@@ -29,8 +26,13 @@ public class Translation {
|
||||
this.plugin = plugin;
|
||||
}
|
||||
|
||||
private static final String FILE_NAME = "translations.yml";
|
||||
private static final String TRANSLATION_PATH = "translations";
|
||||
public static Translation getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public static String translate(final String key) {
|
||||
return INSTANCE.translations.getOrDefault(key, key);
|
||||
}
|
||||
|
||||
public void load() {
|
||||
final File file = new File(this.plugin.getDataFolder(), FILE_NAME);
|
||||
@@ -42,15 +44,13 @@ public class Translation {
|
||||
|
||||
final ConfigurationSection section = config.getConfigurationSection(TRANSLATION_PATH);
|
||||
|
||||
if (section == null) return;
|
||||
if (section == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final String key : section.getKeys(false)) {
|
||||
this.translations.put(key, section.getString(key));
|
||||
}
|
||||
}
|
||||
|
||||
public static String translate(final String key) {
|
||||
return INSTANCE.translations.getOrDefault(key, key);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.ints.IntArrayList;
|
||||
@@ -14,13 +16,10 @@ import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PacketManager {
|
||||
|
||||
public static PacketContainer getEntitySpawnPacket(final Location location, final int entityId, final EntityType entityType) {
|
||||
public static PacketContainer getEntitySpawnPacket(final Location location, final int entityId,
|
||||
final EntityType entityType) {
|
||||
final PacketContainer packet = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY);
|
||||
|
||||
// Entity ID
|
||||
@@ -45,9 +44,10 @@ public class PacketManager {
|
||||
public static PacketContainer getEquipmentPacket(
|
||||
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList,
|
||||
final int entityId
|
||||
) {
|
||||
) {
|
||||
|
||||
final PacketContainer armorPacket = new PacketContainer(PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
final PacketContainer armorPacket = new PacketContainer(
|
||||
PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
armorPacket.getIntegers().write(0, entityId);
|
||||
armorPacket.getSlotStackPairLists().write(0, equipmentList);
|
||||
|
||||
@@ -55,7 +55,8 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
public static PacketContainer getRotationPacket(final int entityId, final Location location) {
|
||||
final PacketContainer rotationPacket = new PacketContainer(PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
final PacketContainer rotationPacket = new PacketContainer(
|
||||
PacketType.Play.Server.ENTITY_HEAD_ROTATION);
|
||||
|
||||
rotationPacket.getIntegers().write(0, entityId);
|
||||
rotationPacket.getBytes().write(0, (byte) (location.getYaw() * 256 / 360));
|
||||
@@ -74,7 +75,8 @@ public class PacketManager {
|
||||
}
|
||||
|
||||
public static PacketContainer getEntityDestroyPacket(final int entityId) {
|
||||
final PacketContainer destroyPacket = new PacketContainer(PacketType.Play.Server.ENTITY_DESTROY);
|
||||
final PacketContainer destroyPacket = new PacketContainer(
|
||||
PacketType.Play.Server.ENTITY_DESTROY);
|
||||
destroyPacket.getModifier().write(0, new IntArrayList(new int[]{entityId}));
|
||||
|
||||
return destroyPacket;
|
||||
@@ -96,4 +98,5 @@ public class PacketManager {
|
||||
sendPacket(player, packets);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,10 +6,12 @@ import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.Pair;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import io.github.fisher2911.hmccosmetics.HMCCosmetics;
|
||||
import io.github.fisher2911.hmccosmetics.gui.ArmorItem;
|
||||
import io.github.fisher2911.hmccosmetics.inventory.PlayerArmor;
|
||||
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.EntityType;
|
||||
@@ -17,19 +19,13 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class User {
|
||||
|
||||
private final UUID uuid;
|
||||
private final PlayerArmor playerArmor;
|
||||
|
||||
private ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT);
|
||||
|
||||
private boolean hasArmorStand;
|
||||
private final int armorStandId;
|
||||
private ArmorItem lastSetItem = ArmorItem.empty(ArmorItem.Type.HAT);
|
||||
private boolean hasArmorStand;
|
||||
|
||||
public User(final UUID uuid, final PlayerArmor playerArmor, final int armorStandId) {
|
||||
this.uuid = uuid;
|
||||
@@ -77,11 +73,15 @@ public class User {
|
||||
public void spawnArmorStand(final Player other) {
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) return;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Location location = player.getLocation();
|
||||
|
||||
final PacketContainer packet = PacketManager.getEntitySpawnPacket(location, this.armorStandId, EntityType.ARMOR_STAND);
|
||||
final PacketContainer packet = PacketManager.getEntitySpawnPacket(location,
|
||||
this.armorStandId,
|
||||
EntityType.ARMOR_STAND);
|
||||
|
||||
PacketManager.sendPacket(other, packet);
|
||||
}
|
||||
@@ -107,7 +107,9 @@ public class User {
|
||||
|
||||
final Player player = this.getPlayer();
|
||||
|
||||
if (player == null) return;
|
||||
if (player == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList = new ArrayList<>();
|
||||
equipmentList.add(new Pair<>(EnumWrappers.ItemSlot.HEAD,
|
||||
@@ -116,18 +118,24 @@ public class User {
|
||||
|
||||
final Location location = player.getLocation();
|
||||
|
||||
final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList, this.armorStandId);
|
||||
final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId, location);
|
||||
final PacketContainer ridingPacket = PacketManager.getRidingPacket(player.getEntityId(), this.armorStandId);
|
||||
final PacketContainer armorPacket = PacketManager.getEquipmentPacket(equipmentList,
|
||||
this.armorStandId);
|
||||
final PacketContainer rotationPacket = PacketManager.getRotationPacket(this.armorStandId,
|
||||
location);
|
||||
final PacketContainer ridingPacket = PacketManager.getRidingPacket(player.getEntityId(),
|
||||
this.armorStandId);
|
||||
|
||||
final PacketContainer metaContainer = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
final PacketContainer metaContainer = new PacketContainer(
|
||||
PacketType.Play.Server.ENTITY_METADATA);
|
||||
|
||||
WrappedDataWatcher metaData = new WrappedDataWatcher();
|
||||
|
||||
final Serializer byteSerializer = WrappedDataWatcher.Registry.get(Byte.class);
|
||||
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, byteSerializer), (byte) (0x20));
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, byteSerializer), (byte) (0x10));
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(0, byteSerializer),
|
||||
(byte) (0x20));
|
||||
metaData.setObject(new WrappedDataWatcher.WrappedDataWatcherObject(15, byteSerializer),
|
||||
(byte) (0x10));
|
||||
|
||||
metaContainer.getIntegers().write(0, this.armorStandId);
|
||||
metaContainer.getWatchableCollectionModifier().write(0, metaData.getWatchableObjects());
|
||||
@@ -147,4 +155,5 @@ public class User {
|
||||
public ArmorItem getLastSetItem() {
|
||||
return lastSetItem;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,14 +16,6 @@ import io.github.fisher2911.hmccosmetics.message.MessageHandler;
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import io.github.fisher2911.hmccosmetics.packet.PacketManager;
|
||||
import io.github.fisher2911.hmccosmetics.util.builder.ItemBuilder;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
@@ -31,6 +23,13 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
|
||||
public class UserManager {
|
||||
|
||||
@@ -66,7 +65,9 @@ public class UserManager {
|
||||
public void remove(final UUID uuid) {
|
||||
final User user = this.userMap.remove(uuid);
|
||||
|
||||
if (user == null) return;
|
||||
if (user == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.armorStandIdMap.remove(user.getArmorStandId());
|
||||
|
||||
@@ -105,7 +106,6 @@ public class UserManager {
|
||||
|
||||
public void updateCosmetics(final UUID uuid, final boolean ignoreRestrictions) {
|
||||
this.get(uuid).ifPresent(user -> this.updateCosmetics(user, ignoreRestrictions));
|
||||
|
||||
}
|
||||
|
||||
public void updateCosmetics(final UUID uuid) {
|
||||
@@ -122,7 +122,8 @@ public class UserManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateCosmetics(final User user, final boolean ignoreRestrictions, final Player other) {
|
||||
public void updateCosmetics(final User user, final boolean ignoreRestrictions,
|
||||
final Player other) {
|
||||
final Player player = user.getPlayer();
|
||||
|
||||
if (player == null) {
|
||||
@@ -134,10 +135,15 @@ public class UserManager {
|
||||
final List<Pair<EnumWrappers.ItemSlot, ItemStack>> equipmentList = new ArrayList<>();
|
||||
|
||||
equipmentList.add(
|
||||
new Pair<>(EnumWrappers.ItemSlot.HEAD, this.getCosmeticItem(player, playerArmor.getHat(), EquipmentSlot.HEAD, ignoreRestrictions))
|
||||
new Pair<>(EnumWrappers.ItemSlot.HEAD,
|
||||
this.getCosmeticItem(player, playerArmor.getHat(), EquipmentSlot.HEAD,
|
||||
ignoreRestrictions))
|
||||
);
|
||||
equipmentList.add(
|
||||
new Pair<>(EnumWrappers.ItemSlot.OFFHAND, this.getCosmeticItem(player, playerArmor.getOffHand(), EquipmentSlot.OFF_HAND, ignoreRestrictions))
|
||||
new Pair<>(EnumWrappers.ItemSlot.OFFHAND,
|
||||
this.getCosmeticItem(player, playerArmor.getOffHand(),
|
||||
EquipmentSlot.OFF_HAND,
|
||||
ignoreRestrictions))
|
||||
);
|
||||
|
||||
PacketManager.sendPacket(
|
||||
@@ -168,14 +174,19 @@ public class UserManager {
|
||||
final boolean isAir = itemStack.getType().isAir();
|
||||
final boolean requireEmpty = cosmeticSettings.requireEmpty(slot);
|
||||
|
||||
if (!isAir && (!requireEmpty || ignoreRestrictions)) return itemStack;
|
||||
if (!isAir && (!requireEmpty || ignoreRestrictions)) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
|
||||
if (equipment == null) return itemStack;
|
||||
if (equipment == null) {
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
final ItemStack equipped = equipment.getItem(slot);
|
||||
|
||||
if (equipped != null && equipped.getType() != Material.AIR) return equipped;
|
||||
if (equipped != null && equipped.getType() != Material.AIR) {
|
||||
return equipped;
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
@@ -184,9 +195,12 @@ public class UserManager {
|
||||
ArmorItem previous = user.getPlayerArmor().getItem(armorItem.getType());
|
||||
|
||||
final CosmeticChangeEvent event =
|
||||
new CosmeticChangeEvent(new CosmeticItem(armorItem.copy()), new CosmeticItem(previous.copy()), user);
|
||||
new CosmeticChangeEvent(new CosmeticItem(armorItem.copy()),
|
||||
new CosmeticItem(previous.copy()), user);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) return;
|
||||
if (event.isCancelled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
user.setItem(event.getCosmeticItem().getArmorItem());
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.plugin, () -> {
|
||||
@@ -254,4 +268,5 @@ public class UserManager {
|
||||
public void cancelTeleportTask() {
|
||||
this.teleportTask.cancel();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,12 +8,7 @@ import org.bukkit.persistence.PersistentDataType;
|
||||
|
||||
public class Keys {
|
||||
|
||||
static HMCCosmetics plugin;
|
||||
|
||||
static {
|
||||
plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
}
|
||||
|
||||
static HMCCosmetics plugin = HMCCosmetics.getPlugin(HMCCosmetics.class);
|
||||
public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic");
|
||||
public static final NamespacedKey ARMOR_STAND_KEY = new NamespacedKey(plugin, "armor-stand");
|
||||
|
||||
|
||||
@@ -1,15 +1,8 @@
|
||||
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.hook.PAPIHook;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public class StringUtils {
|
||||
|
||||
@@ -25,11 +18,11 @@ public class StringUtils {
|
||||
*/
|
||||
|
||||
public static Component parse(final String parsed) {
|
||||
return Adventure.MINI_MESSAGE.parse(parsed);
|
||||
return Adventure.MINI_MESSAGE.deserialize(parsed);
|
||||
}
|
||||
|
||||
public static String parseStringToString(final String parsed) {
|
||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.parse(parsed));
|
||||
return Adventure.SERIALIZER.serialize(Adventure.MINI_MESSAGE.deserialize(parsed));
|
||||
}
|
||||
|
||||
public static String formatArmorItemType(String type) {
|
||||
@@ -44,4 +37,5 @@ public class StringUtils {
|
||||
|
||||
return firstPart + parts[1].substring(0, 1).toUpperCase() + parts[1].substring(1);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
package io.github.fisher2911.hmccosmetics.util;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class Utils {
|
||||
|
||||
/**
|
||||
* @param original Object to be checked if null
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final @NotNull T replacement) {
|
||||
return replaceIfNull(original, replacement, t -> {});
|
||||
return replaceIfNull(original, replacement, t -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param original Object to be checked if null
|
||||
* @param original Object to be checked if null
|
||||
* @param replacement Object returned if original is null
|
||||
* @param consumer accepts the original object, can be used for logging
|
||||
* @return original if not null, otherwise replacement
|
||||
*/
|
||||
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final T replacement, final @NotNull Consumer<T> consumer) {
|
||||
public static <T> T replaceIfNull(final @Nullable T original, final T replacement,
|
||||
final @NotNull Consumer<T> consumer) {
|
||||
if (original == null) {
|
||||
consumer.accept(replacement);
|
||||
return replacement;
|
||||
@@ -37,7 +37,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param t object being checked
|
||||
* @param consumer accepted if t is not null
|
||||
* @param <T> type
|
||||
@@ -51,14 +50,14 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param t object being checked
|
||||
* @param function applied if t is not null
|
||||
* @param <T> type
|
||||
* @return
|
||||
*/
|
||||
|
||||
public static <T> Optional<T> returnIfNotNull(final @Nullable T t, final @NotNull Function<T, T> function) {
|
||||
public static <T> Optional<T> returnIfNotNull(final @Nullable T t,
|
||||
final @NotNull Function<T, T> function) {
|
||||
if (t == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
@@ -66,7 +65,6 @@ public class Utils {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
@@ -74,13 +72,13 @@ public class Utils {
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
final @NotNull Class<E> enumClass,
|
||||
E defaultEnum) {
|
||||
return stringToEnum(enumAsString, enumClass, defaultEnum, e -> {});
|
||||
final @NotNull Class<E> enumClass,
|
||||
E defaultEnum) {
|
||||
return stringToEnum(enumAsString, enumClass, defaultEnum, e -> {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param enumAsString Enum value as a string to be parsed
|
||||
* @param enumClass enum type enumAsString is to be converted to
|
||||
* @param defaultEnum default value to be returned
|
||||
@@ -89,9 +87,9 @@ public class Utils {
|
||||
*/
|
||||
|
||||
public static <E extends Enum<E>> E stringToEnum(final @NotNull String enumAsString,
|
||||
@NotNull final Class<E> enumClass,
|
||||
final E defaultEnum,
|
||||
final @NotNull Consumer<E> consumer) {
|
||||
@NotNull final Class<E> enumClass,
|
||||
final E defaultEnum,
|
||||
final @NotNull Consumer<E> consumer) {
|
||||
try {
|
||||
final E value = Enum.valueOf(enumClass, enumAsString);
|
||||
consumer.accept(value);
|
||||
|
||||
@@ -7,13 +7,9 @@ import org.bukkit.inventory.meta.ItemMeta;
|
||||
import org.bukkit.inventory.meta.LeatherArmorMeta;
|
||||
import org.bukkit.inventory.meta.PotionMeta;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ColorBuilder extends ItemBuilder{
|
||||
public class ColorBuilder extends ItemBuilder {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material ItemStack material
|
||||
*/
|
||||
|
||||
@@ -22,7 +18,6 @@ public class ColorBuilder extends ItemBuilder{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemStack ItemStack
|
||||
*/
|
||||
|
||||
@@ -31,7 +26,6 @@ public class ColorBuilder extends ItemBuilder{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material ItemStack material
|
||||
* @return this
|
||||
* @throws IllegalArgumentException thrown if itemStack's type can not change color
|
||||
@@ -45,7 +39,6 @@ public class ColorBuilder extends ItemBuilder{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param itemStack ItemStack
|
||||
* @return this
|
||||
* @throws IllegalArgumentException thrown if itemStack's type can not change color
|
||||
@@ -59,8 +52,18 @@ public class ColorBuilder extends ItemBuilder{
|
||||
return new ColorBuilder(itemStack);
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final Material material) {
|
||||
return canBeColored(new ItemStack(material));
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
return (itemMeta instanceof LeatherArmorMeta ||
|
||||
itemMeta instanceof PotionMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param color armor color
|
||||
* @return this
|
||||
*/
|
||||
@@ -75,14 +78,4 @@ public class ColorBuilder extends ItemBuilder{
|
||||
return this;
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final Material material) {
|
||||
return canBeColored(new ItemStack(material));
|
||||
}
|
||||
|
||||
public static boolean canBeColored(final ItemStack itemStack) {
|
||||
final ItemMeta itemMeta = itemStack.getItemMeta();
|
||||
|
||||
return (itemMeta instanceof LeatherArmorMeta ||
|
||||
itemMeta instanceof PotionMeta);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
package io.github.fisher2911.hmccosmetics.util.builder;
|
||||
|
||||
import io.github.fisher2911.hmccosmetics.message.Placeholder;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
@@ -10,11 +13,6 @@ import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.ItemMeta;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class ItemBuilder {
|
||||
|
||||
protected Material material;
|
||||
@@ -36,7 +34,8 @@ public class ItemBuilder {
|
||||
|
||||
ItemBuilder(final ItemStack itemStack) {
|
||||
this.material = itemStack.getType();
|
||||
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta() : Bukkit.getItemFactory().getItemMeta(this.material);
|
||||
this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta()
|
||||
: Bukkit.getItemFactory().getItemMeta(this.material);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -146,12 +145,16 @@ public class ItemBuilder {
|
||||
}
|
||||
|
||||
private void lorePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) return;
|
||||
if (this.itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
final List<String> newLore = new ArrayList<>();
|
||||
|
||||
final List<String> lore = this.itemMeta.getLore();
|
||||
|
||||
if (lore == null) return;
|
||||
if (lore == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final String line : this.itemMeta.getLore()) {
|
||||
newLore.add(Placeholder.applyPapiPlaceholders(player, line));
|
||||
@@ -161,7 +164,9 @@ public class ItemBuilder {
|
||||
}
|
||||
|
||||
private void namePapiPlaceholders(final Player player) {
|
||||
if (this.itemMeta == null) return;
|
||||
if (this.itemMeta == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.itemMeta.setDisplayName(
|
||||
Placeholder.applyPapiPlaceholders(
|
||||
@@ -196,16 +201,18 @@ public class ItemBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enchantments enchants to be added to the ItemStack
|
||||
* @param enchantments enchants to be added to the ItemStack
|
||||
* @param ignoreLeveLRestrictions whether to ignore enchantment level restrictions
|
||||
* @return this
|
||||
*/
|
||||
|
||||
public ItemBuilder enchants(final Map<Enchantment, Integer> enchantments, boolean ignoreLeveLRestrictions) {
|
||||
public ItemBuilder enchants(final Map<Enchantment, Integer> enchantments,
|
||||
boolean ignoreLeveLRestrictions) {
|
||||
if (this.itemMeta == null) {
|
||||
return this;
|
||||
}
|
||||
enchantments.forEach((enchantment, level) -> this.itemMeta.addEnchant(enchantment, level, ignoreLeveLRestrictions));
|
||||
enchantments.forEach((enchantment, level) -> this.itemMeta.addEnchant(enchantment, level,
|
||||
ignoreLeveLRestrictions));
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,15 +2,14 @@ package io.github.fisher2911.hmccosmetics.util.builder;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.properties.Property;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.meta.SkullMeta;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* Some parts taken from https://github.com/TriumphTeam/triumph-gui/blob/master/core/src/main/java/dev/triumphteam/gui/builder/item/SkullBuilder.java
|
||||
*/
|
||||
@@ -23,7 +22,8 @@ public class SkullBuilder extends ItemBuilder {
|
||||
Field field;
|
||||
|
||||
try {
|
||||
final SkullMeta skullMeta = (SkullMeta) new ItemStack(Material.PLAYER_HEAD).getItemMeta();
|
||||
final SkullMeta skullMeta = (SkullMeta) new ItemStack(
|
||||
Material.PLAYER_HEAD).getItemMeta();
|
||||
field = skullMeta.getClass().getDeclaredField("profile");
|
||||
field.setAccessible(true);
|
||||
} catch (NoSuchFieldException e) {
|
||||
@@ -36,7 +36,6 @@ public class SkullBuilder extends ItemBuilder {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param material The material
|
||||
*/
|
||||
|
||||
@@ -46,6 +45,7 @@ public class SkullBuilder extends ItemBuilder {
|
||||
|
||||
/**
|
||||
* Creates a new SkullBuilder instance
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
|
||||
@@ -55,7 +55,6 @@ public class SkullBuilder extends ItemBuilder {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param player skull owner
|
||||
* @return this
|
||||
*/
|
||||
@@ -68,7 +67,6 @@ public class SkullBuilder extends ItemBuilder {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param texture skull texture
|
||||
* @return this
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user