From 7a4fd9a98bd0594709f425c57d9694578f1bd017 Mon Sep 17 00:00:00 2001 From: LoJoSho Date: Wed, 19 Jul 2023 13:39:27 -0500 Subject: [PATCH] clean: remove unused utils --- .../com/hibiscusmc/hmccosmetics/gui/Menu.java | 4 +- .../hmccosmetics/gui/special/DyeMenu.java | 3 +- .../util/builder/ItemBuilder.java | 215 ------------------ .../hmccosmetics/util/misc/Keys.java | 75 ------ .../hmccosmetics/util/misc/Placeholder.java | 33 --- 5 files changed, 3 insertions(+), 327 deletions(-) delete mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/util/builder/ItemBuilder.java delete mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Keys.java delete mode 100644 common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Placeholder.java diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java index f7bfc84e..64be5e6e 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/Menu.java @@ -5,10 +5,10 @@ import com.hibiscusmc.hmccosmetics.api.events.PlayerMenuOpenEvent; import com.hibiscusmc.hmccosmetics.config.serializer.ItemSerializer; import com.hibiscusmc.hmccosmetics.gui.type.Type; import com.hibiscusmc.hmccosmetics.gui.type.Types; +import com.hibiscusmc.hmccosmetics.hooks.Hooks; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; import com.hibiscusmc.hmccosmetics.util.MessagesUtil; import com.hibiscusmc.hmccosmetics.util.misc.Adventure; -import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; import dev.triumphteam.gui.builder.item.ItemBuilder; import dev.triumphteam.gui.guis.Gui; import dev.triumphteam.gui.guis.GuiItem; @@ -69,7 +69,7 @@ public class Menu { return; } } - final Component component = Adventure.MINI_MESSAGE.deserialize(Placeholder.applyPapiPlaceholders(player, this.title)); + final Component component = Adventure.MINI_MESSAGE.deserialize(Hooks.processPlaceholders(player, this.title)); Gui gui = Gui.gui(). title(component). rows(this.rows). diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java index 3f1ac10c..34025e45 100644 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java +++ b/common/src/main/java/com/hibiscusmc/hmccosmetics/gui/special/DyeMenu.java @@ -8,7 +8,6 @@ import com.hibiscusmc.hmccosmetics.config.Settings; import com.hibiscusmc.hmccosmetics.cosmetic.Cosmetic; import com.hibiscusmc.hmccosmetics.hooks.Hooks; import com.hibiscusmc.hmccosmetics.user.CosmeticUser; -import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; import org.bukkit.Bukkit; import org.bukkit.Color; import org.bukkit.Material; @@ -33,7 +32,7 @@ public class DyeMenu { if (originalItem == null || !cosmetic.isDyable()) return; Gui gui = HMCColorApi.INSTANCE.colorMenu(); - gui.updateTitle(Placeholder.applyPapiPlaceholders(player, Settings.getDyeMenuName())); + gui.updateTitle(Hooks.processPlaceholders(player, Settings.getDyeMenuName())); gui.setItem(Settings.getDyeMenuInputSlot(), new GuiItem(originalItem)); gui.setDefaultTopClickAction(event -> { if (event.getSlot() == Settings.getDyeMenuOutputSlot()) { diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/builder/ItemBuilder.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/builder/ItemBuilder.java deleted file mode 100644 index 11d59364..00000000 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/builder/ItemBuilder.java +++ /dev/null @@ -1,215 +0,0 @@ -package com.hibiscusmc.hmccosmetics.util.builder; - -import com.hibiscusmc.hmccosmetics.util.misc.Placeholder; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.enchantments.Enchantment; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemFlag; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.jetbrains.annotations.Contract; -import org.jetbrains.annotations.NotNull; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.Set; - -public class ItemBuilder { - - protected Material material; - protected int amount; - protected ItemMeta itemMeta; - - /** - * @param material builder material - */ - - ItemBuilder(final Material material) { - this.material = material; - this.itemMeta = Bukkit.getItemFactory().getItemMeta(material); - } - - /** - * @param itemStack builder ItemStack - */ - - ItemBuilder(final @NotNull ItemStack itemStack) { - this.material = itemStack.getType(); - this.itemMeta = itemStack.hasItemMeta() ? itemStack.getItemMeta() - : Bukkit.getItemFactory().getItemMeta(this.material); - } - - /** - * @param material builder material - * @return - */ - - @Contract("_ -> new") - @NotNull - public static ItemBuilder from(final Material material) { - return new ItemBuilder(material); - } - - /** - * @param itemStack builder ItemStack - * @return - */ - @Contract("_ -> new") - @NotNull - public static ItemBuilder from(final ItemStack itemStack) { - return new ItemBuilder(itemStack); - } - - /** - * @param amount ItemStack amount - * @return this - */ - - public ItemBuilder amount(final int amount) { - this.amount = Math.min(Math.max(1, amount), 64); - return this; - } - - /** - * @param name ItemStack name - * @return this - */ - - public ItemBuilder name(final String name) { - if (this.itemMeta == null) { - return this; - } - this.itemMeta.setDisplayName(name); - return this; - } - - /** - * @param lore ItemStack lore - * @return this - */ - - public ItemBuilder lore(final List lore) { - if (this.itemMeta == null) { - return this; - } - this.itemMeta.setLore(lore); - return this; - } - - public ItemBuilder papiPlaceholders(final Player player) { - this.lorePapiPlaceholders(player); - this.namePapiPlaceholders(player); - return this; - } - - private void lorePapiPlaceholders(final Player player) { - if (this.itemMeta == null) { - return; - } - final List newLore = new ArrayList<>(); - - final List lore = this.itemMeta.getLore(); - - if (lore == null) { - return; - } - - for (final String line : this.itemMeta.getLore()) { - newLore.add(Placeholder.applyPapiPlaceholders(player, line)); - } - - this.itemMeta.setLore(newLore); - } - - private void namePapiPlaceholders(final Player player) { - if (this.itemMeta == null) { - return; - } - - this.itemMeta.setDisplayName( - Placeholder.applyPapiPlaceholders( - player, - this.itemMeta.getDisplayName() - ) - ); - } - - /** - * @param unbreakable whether the ItemStack is unbreakable - * @return this - */ - - public ItemBuilder unbreakable(final boolean unbreakable) { - if (this.itemMeta == null) { - return this; - } - this.itemMeta.setUnbreakable(unbreakable); - return this; - } - - public ItemBuilder glow(final boolean glow) { - if (this.itemMeta == null) { - return this; - } - if (glow) { - this.itemMeta.addItemFlags(ItemFlag.HIDE_ENCHANTS); - this.itemMeta.addEnchant(Enchantment.LUCK, 1, true); - } - return this; - } - - /** - * @param enchantments enchants to be added to the ItemStack - * @param ignoreLeveLRestrictions whether to ignore enchantment level restrictions - * @return this - */ - - public ItemBuilder enchants(final Map enchantments, - boolean ignoreLeveLRestrictions) { - if (this.itemMeta == null) { - return this; - } - enchantments.forEach((enchantment, level) -> this.itemMeta.addEnchant(enchantment, level, - ignoreLeveLRestrictions)); - return this; - } - - /** - * @param itemFlags ItemStack ItemFlags - * @return this - */ - - public ItemBuilder itemFlags(final Set itemFlags) { - if (this.itemMeta == null) { - return this; - } - this.itemMeta.addItemFlags(itemFlags.toArray(new ItemFlag[0])); - return this; - } - - /** - * @param modelData ItemStack modelData - * @return this - */ - - public ItemBuilder modelData(final int modelData) { - if (this.itemMeta == null) { - return this; - } - this.itemMeta.setCustomModelData(modelData); - return this; - } - - /** - * @return built ItemStack - */ - - public ItemStack build() { - final ItemStack itemStack = new ItemStack(this.material, Math.max(this.amount, 1)); - itemStack.setItemMeta(itemMeta); - return itemStack; - } - -} \ No newline at end of file diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Keys.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Keys.java deleted file mode 100644 index d42b8653..00000000 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Keys.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.hibiscusmc.hmccosmetics.util.misc; - -import com.hibiscusmc.hmccosmetics.HMCCosmeticsPlugin; -import org.bukkit.NamespacedKey; -import org.bukkit.inventory.ItemStack; -import org.bukkit.inventory.meta.ItemMeta; -import org.bukkit.persistence.PersistentDataType; -import org.checkerframework.checker.nullness.qual.Nullable; -import org.jetbrains.annotations.NotNull; - -public class Keys { - - static HMCCosmeticsPlugin plugin = HMCCosmeticsPlugin.getInstance(); - public static final NamespacedKey ITEM_KEY = new NamespacedKey(plugin, "cosmetic"); - public static final NamespacedKey TOKEN_KEY = new NamespacedKey(plugin, "token-key"); - - public static void setKey(final @NotNull ItemStack itemStack) { - final ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta == null) { - return; - } - - itemMeta.getPersistentDataContainer().set(ITEM_KEY, PersistentDataType.BYTE, (byte) 1); - - itemStack.setItemMeta(itemMeta); - } - - public static void setKey( - final @NotNull ItemStack itemStack, - final NamespacedKey key, - final PersistentDataType type, - final Z value) { - final ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta == null) { - return; - } - - itemMeta.getPersistentDataContainer().set(key, type, value); - - itemStack.setItemMeta(itemMeta); - } - - public static boolean hasKey(final @NotNull ItemStack itemStack) { - final ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta == null) { - return false; - } - - return itemMeta.getPersistentDataContainer().has(ITEM_KEY, PersistentDataType.BYTE); - } - - public static boolean hasKey(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType type) { - final ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta == null) { - return false; - } - - return itemMeta.getPersistentDataContainer().has(key, type); - } - - @Nullable - public static Z getValue(final @NotNull ItemStack itemStack, final NamespacedKey key, final PersistentDataType type) { - final ItemMeta itemMeta = itemStack.getItemMeta(); - - if (itemMeta == null) { - return null; - } - - return itemMeta.getPersistentDataContainer().get(key, type); - } -} diff --git a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Placeholder.java b/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Placeholder.java deleted file mode 100644 index 2195fba7..00000000 --- a/common/src/main/java/com/hibiscusmc/hmccosmetics/util/misc/Placeholder.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hibiscusmc.hmccosmetics.util.misc; - -import org.bukkit.entity.Player; -import org.jetbrains.annotations.Nullable; - -public class Placeholder { - - public static final String PREFIX = "%prefix%"; - public static final String TYPE = "%type%"; - public static final String ITEM = "%item%"; - public static final String FILE = "%file%"; - - public static final String PLAYER = "%player%"; - public static final String ENABLED = "%enabled%"; - public static final String ALLOWED = "%allowed%"; - public static final String ID = "%id%"; - - /** - * @return message with placeholders applied - */ - - 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; - } - -}