From be664e925f40e329193682bb839656f5d122e015 Mon Sep 17 00:00:00 2001 From: RednedEpic Date: Sat, 28 Dec 2024 18:59:59 -0600 Subject: [PATCH] Allow parsing Minecraft's native item format and fix modules loading again on plugin reload --- .../org/battleplugins/arena/BattleArena.java | 23 ++++++++++--------- .../arena/config/ItemStackParser.java | 15 +++++++++++- .../arena/module/ArenaModuleLoader.java | 2 +- 3 files changed, 27 insertions(+), 13 deletions(-) diff --git a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java index 4126e647..0b60ba3b 100644 --- a/plugin/src/main/java/org/battleplugins/arena/BattleArena.java +++ b/plugin/src/main/java/org/battleplugins/arena/BattleArena.java @@ -115,8 +115,20 @@ public void onEnable() { // Register default arenas this.registerArena(this, "Arena", Arena.class); + // Enable the plugin this.enable(); + // Enable modules + this.moduleLoader.enableModules(); + + // Register base command + PluginCommand command = this.getCommand("battlearena"); + if (command == null) { + throw new IllegalArgumentException("Failed to register command 'battlearena'. Was it not registered?"); + } + + command.setExecutor(new BACommandExecutor("battlearena")); + // Loads all arena loaders this.loadArenaLoaders(this.arenasPath); @@ -162,17 +174,6 @@ private void enable() { // Clear any remaining dynamic maps this.clearDynamicMaps(); - - // Enable modules - this.moduleLoader.enableModules(); - - // Register base command - PluginCommand command = this.getCommand("battlearena"); - if (command == null) { - throw new IllegalArgumentException("Failed to register command 'battlearena'. Was it not registered?"); - } - - command.setExecutor(new BACommandExecutor("battlearena")); } @Override diff --git a/plugin/src/main/java/org/battleplugins/arena/config/ItemStackParser.java b/plugin/src/main/java/org/battleplugins/arena/config/ItemStackParser.java index a50ce3b5..107d8365 100644 --- a/plugin/src/main/java/org/battleplugins/arena/config/ItemStackParser.java +++ b/plugin/src/main/java/org/battleplugins/arena/config/ItemStackParser.java @@ -3,6 +3,7 @@ import net.kyori.adventure.text.Component; import net.kyori.adventure.text.format.TextDecoration; import net.kyori.adventure.text.minimessage.MiniMessage; +import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.NamespacedKey; import org.bukkit.configuration.ConfigurationSection; @@ -44,7 +45,19 @@ public ItemStack parse(Object object) throws ParseException { public static ItemStack deserializeSingular(String contents) throws ParseException { ItemStack itemStack; - SingularValueParser.ArgumentBuffer buffer = SingularValueParser.parseNamed(contents, SingularValueParser.BraceStyle.CURLY, ';'); + SingularValueParser.ArgumentBuffer buffer; + try { + buffer = SingularValueParser.parseNamed(contents, SingularValueParser.BraceStyle.CURLY, ';'); + } catch (ParseException e) { + // If we get an error, let's try parsing using Minecraft's native format + try { + return Bukkit.getItemFactory().createItemStack(contents); + } catch (IllegalArgumentException ex) { + ex.initCause(e); + throw e; + } + } + if (!buffer.hasNext()) { throw new ParseException("No data found for ItemStack") .cause(ParseException.Cause.INVALID_TYPE) diff --git a/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java b/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java index fe171ab9..e41e222a 100644 --- a/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java +++ b/plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java @@ -112,7 +112,7 @@ public void loadModules() throws IOException { public void enableModules() { this.modules.values().forEach(module -> { if (this.plugin.getMainConfig().getDisabledModules().contains(module.module().id())) { - this.plugin.info("Module {} is disabled in the configuration. Skipping...", module.module().name()); + this.plugin.debug("Module {} is disabled in the configuration. Skipping...", module.module().name()); return; }