From d64b4223756d4e7386af7222ca8b43e3d4913056 Mon Sep 17 00:00:00 2001 From: Esoteric Enderman Date: Tue, 29 Oct 2024 12:06:31 +0000 Subject: [PATCH] Update dependency --- build.gradle.kts | 2 +- .../plugins/template/PaperTemplatePlugin.java | 17 +++-- .../commands/GiveCustomItemCommand.java | 48 -------------- .../custom/items/AbstractCustomItem.java | 62 ------------------- .../template/custom/items/CustomItem.java | 9 --- .../custom/items/CustomItemManager.java | 34 ---------- .../plugins/template/language/Message.java | 3 +- 7 files changed, 9 insertions(+), 166 deletions(-) delete mode 100644 src/main/java/org/esoteric/minecraft/plugins/template/commands/GiveCustomItemCommand.java delete mode 100644 src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java delete mode 100644 src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItem.java delete mode 100644 src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java diff --git a/build.gradle.kts b/build.gradle.kts index e8b56d75..80d47767 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -103,7 +103,7 @@ dependencies { implementation("dev.jorel", "commandapi-bukkit-shade-mojang-mapped", "9.5.3") implementation("net.lingala.zip4j", "zip4j", "2.11.5") implementation("com.github.EsotericFoundation:utility.kt:0.1.0") - implementation("com.github.EsotericFoundation:plugin-library:0.1.0") + implementation("com.github.EsotericFoundation:plugin-library:0.2.0") } tasks { diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/PaperTemplatePlugin.java b/src/main/java/org/esoteric/minecraft/plugins/template/PaperTemplatePlugin.java index 1d1eabbe..0c7265dd 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/PaperTemplatePlugin.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/PaperTemplatePlugin.java @@ -2,16 +2,16 @@ import dev.jorel.commandapi.CommandAPI; import dev.jorel.commandapi.CommandAPIBukkitConfig; +import foundation.esoteric.minecraft.plugins.library.commands.GiveCustomItemCommand; import foundation.esoteric.minecraft.plugins.library.file.FileManagedPlugin; import foundation.esoteric.minecraft.plugins.library.file.FileManager; +import foundation.esoteric.minecraft.plugins.library.item.CustomItemManager; +import foundation.esoteric.minecraft.plugins.library.item.CustomItemPlugin; import org.bukkit.NamespacedKey; import org.bukkit.plugin.java.JavaPlugin; -import org.esoteric.minecraft.plugins.template.commands.GiveCustomItemCommand; import org.esoteric.minecraft.plugins.template.commands.PlaceCustomMultiblockCommand; import org.esoteric.minecraft.plugins.template.commands.SetLanguageCommand; import org.esoteric.minecraft.plugins.template.commands.SpawnCustomMultientityCommand; -import org.esoteric.minecraft.plugins.template.custom.items.CustomItem; -import org.esoteric.minecraft.plugins.template.custom.items.CustomItemManager; import org.esoteric.minecraft.plugins.template.custom.multiblocks.CustomMultiblock; import org.esoteric.minecraft.plugins.template.custom.multiblocks.CustomMultiblockManager; import org.esoteric.minecraft.plugins.template.custom.multientities.CustomMultientity; @@ -22,7 +22,7 @@ import org.esoteric.minecraft.plugins.template.language.Message; import org.esoteric.minecraft.plugins.template.resourcepack.ResourcePackManager; -public final class PaperTemplatePlugin extends JavaPlugin implements FileManagedPlugin { +public final class PaperTemplatePlugin extends JavaPlugin implements FileManagedPlugin, CustomItemPlugin { private FileManager fileManager; private PlayerDataManager playerDataManager; @@ -91,11 +91,10 @@ public void onEnable() { if (Message.isEnabled()) { languageManager = new LanguageManager(this); } + resourcePackManager = new ResourcePackManager(this); httpServerManager = new HttpServerManager(this); - if (CustomItem.isEnabled()) { - customItemManager = new CustomItemManager(this); - } + customItemManager = new CustomItemManager(this); if (CustomMultientity.isEnabled()) { customMultientityManager = new CustomMultientityManager(this); } @@ -106,9 +105,7 @@ public void onEnable() { if (Message.isEnabled()) { new SetLanguageCommand(this); } - if (CustomItem.isEnabled()) { - new GiveCustomItemCommand(this); - } + new GiveCustomItemCommand(this); if (CustomMultientity.isEnabled()) { new SpawnCustomMultientityCommand(this); } diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/commands/GiveCustomItemCommand.java b/src/main/java/org/esoteric/minecraft/plugins/template/commands/GiveCustomItemCommand.java deleted file mode 100644 index f6c98d9b..00000000 --- a/src/main/java/org/esoteric/minecraft/plugins/template/commands/GiveCustomItemCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.esoteric.minecraft.plugins.template.commands; - -import dev.jorel.commandapi.CommandAPICommand; -import dev.jorel.commandapi.CommandPermission; -import dev.jorel.commandapi.arguments.Argument; -import dev.jorel.commandapi.arguments.ArgumentSuggestions; -import dev.jorel.commandapi.arguments.CustomArgument; -import dev.jorel.commandapi.arguments.CustomArgument.CustomArgumentException; -import dev.jorel.commandapi.arguments.StringArgument; -import org.esoteric.minecraft.plugins.template.PaperTemplatePlugin; -import org.esoteric.minecraft.plugins.template.custom.items.CustomItem; -import org.esoteric.minecraft.plugins.template.language.Message; - -import java.util.stream.Stream; - -public class GiveCustomItemCommand extends CommandAPICommand { - - public GiveCustomItemCommand(PaperTemplatePlugin plugin) { - super("give-custom-item"); - - String customItemArgumentNodeName = "custom-item-id"; - - String[] customItemIds = Stream.of(CustomItem.values()).map(Enum::name).toArray(String[]::new); - - Argument customItemArgument = new CustomArgument<>(new StringArgument(customItemArgumentNodeName), (info) -> { - String input = info.currentInput(); - - try { - return CustomItem.valueOf(input); - } catch (IllegalArgumentException exception) { - assert plugin.getLanguageManager() != null; - throw CustomArgumentException.fromAdventureComponent(plugin.getLanguageManager().getMessage(Message.UNKNOWN_CUSTOM_ITEM, info.sender(), input)); - } - }).includeSuggestions(ArgumentSuggestions.strings(customItemIds)); - - executesPlayer((info) -> { - CustomItem item = (CustomItem) info.args().get(customItemArgumentNodeName); - - assert plugin.getCustomItemManager() != null; - plugin.getCustomItemManager().giveCustomItem(item, info.sender()); - }); - - withPermission(CommandPermission.OP); - withArguments(customItemArgument); - - register(plugin); - } -} diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java deleted file mode 100644 index 16aae8fe..00000000 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/AbstractCustomItem.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.esoteric.minecraft.plugins.template.custom.items; - -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.event.Listener; -import org.bukkit.inventory.ItemStack; -import org.bukkit.persistence.PersistentDataType; -import org.esoteric.minecraft.plugins.template.PaperTemplatePlugin; -import org.jetbrains.annotations.NotNull; - -public abstract class AbstractCustomItem implements Listener { - - private final PaperTemplatePlugin plugin; - - private final CustomItem itemId; - private final Material material; - - public AbstractCustomItem(@NotNull CustomItemManager customItemManager, CustomItem itemId, Material material) { - this.plugin = customItemManager.getPlugin(); - - this.itemId = itemId; - this.material = material; - - Bukkit.getPluginManager().registerEvents(this, plugin); - - customItemManager.addCustomItem(itemId, this); - } - - protected abstract ItemStack generateCustomItem(ItemStack baseCustomItem, Player player); - - public ItemStack getCustomItem(Player player) { - ItemStack item = new ItemStack(material); - item.editMeta((meta) -> meta.getPersistentDataContainer().set(plugin.getCustomItemIdKey(), PersistentDataType.STRING, itemId.name())); - return generateCustomItem(item, player); - } - - public boolean isItem(ItemStack itemStack) { - if (itemStack == null) { - return false; - } - - if (!itemStack.hasItemMeta()) { - return false; - } - - String dataContainerItemIdValue = itemStack.getItemMeta().getPersistentDataContainer().get(plugin.getCustomItemIdKey(), PersistentDataType.STRING); - if (dataContainerItemIdValue == null) { - return false; - } - - try { - return itemId == CustomItem.valueOf(dataContainerItemIdValue); - } catch (IllegalArgumentException exception) { - return false; - } - } - - public void give(@NotNull Player player) { - player.getInventory().addItem(getCustomItem(player)); - } -} diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItem.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItem.java deleted file mode 100644 index fd341c59..00000000 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItem.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.esoteric.minecraft.plugins.template.custom.items; - -public enum CustomItem { - ; - - public static boolean isEnabled() { - return values().length != 0; - } -} diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java b/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java deleted file mode 100644 index 818ba7f1..00000000 --- a/src/main/java/org/esoteric/minecraft/plugins/template/custom/items/CustomItemManager.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.esoteric.minecraft.plugins.template.custom.items; - -import org.bukkit.entity.Player; -import org.esoteric.minecraft.plugins.template.PaperTemplatePlugin; - -import java.util.HashMap; -import java.util.Map; - -public class CustomItemManager { - - private final PaperTemplatePlugin plugin; - - private final Map customItemMap = new HashMap<>(); - - public PaperTemplatePlugin getPlugin() { - return plugin; - } - - public CustomItemManager(PaperTemplatePlugin plugin) { - this.plugin = plugin; - } - - public void addCustomItem(CustomItem itemId, AbstractCustomItem customItem) { - customItemMap.put(itemId, customItem); - } - - public AbstractCustomItem getAbstractCustomItem(CustomItem itemId) { - return customItemMap.get(itemId); - } - - public void giveCustomItem(CustomItem itemId, Player player) { - customItemMap.get(itemId).give(player); - } -} diff --git a/src/main/java/org/esoteric/minecraft/plugins/template/language/Message.java b/src/main/java/org/esoteric/minecraft/plugins/template/language/Message.java index 41871fa7..5fba21bb 100644 --- a/src/main/java/org/esoteric/minecraft/plugins/template/language/Message.java +++ b/src/main/java/org/esoteric/minecraft/plugins/template/language/Message.java @@ -1,6 +1,5 @@ package org.esoteric.minecraft.plugins.template.language; -import org.esoteric.minecraft.plugins.template.custom.items.CustomItem; import org.esoteric.minecraft.plugins.template.custom.multiblocks.CustomMultiblock; import org.esoteric.minecraft.plugins.template.custom.multientities.CustomMultientity; @@ -10,7 +9,7 @@ public enum Message { SET_LANGUAGE_SUCCESSFULLY(() -> false), UNKNOWN_LANGUAGE(() -> false), - UNKNOWN_CUSTOM_ITEM(CustomItem::isEnabled), + UNKNOWN_CUSTOM_ITEM(), UNKNOWN_CUSTOM_MULTIENTITY(CustomMultientity::isEnabled), UNKNOWN_CUSTOM_MULTIBLOCK(CustomMultiblock::isEnabled);