Skip to content

Commit be664e9

Browse files
committed
Allow parsing Minecraft's native item format and fix modules loading again on plugin reload
1 parent 08b4b40 commit be664e9

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

plugin/src/main/java/org/battleplugins/arena/BattleArena.java

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,20 @@ public void onEnable() {
115115
// Register default arenas
116116
this.registerArena(this, "Arena", Arena.class);
117117

118+
// Enable the plugin
118119
this.enable();
119120

121+
// Enable modules
122+
this.moduleLoader.enableModules();
123+
124+
// Register base command
125+
PluginCommand command = this.getCommand("battlearena");
126+
if (command == null) {
127+
throw new IllegalArgumentException("Failed to register command 'battlearena'. Was it not registered?");
128+
}
129+
130+
command.setExecutor(new BACommandExecutor("battlearena"));
131+
120132
// Loads all arena loaders
121133
this.loadArenaLoaders(this.arenasPath);
122134

@@ -162,17 +174,6 @@ private void enable() {
162174

163175
// Clear any remaining dynamic maps
164176
this.clearDynamicMaps();
165-
166-
// Enable modules
167-
this.moduleLoader.enableModules();
168-
169-
// Register base command
170-
PluginCommand command = this.getCommand("battlearena");
171-
if (command == null) {
172-
throw new IllegalArgumentException("Failed to register command 'battlearena'. Was it not registered?");
173-
}
174-
175-
command.setExecutor(new BACommandExecutor("battlearena"));
176177
}
177178

178179
@Override

plugin/src/main/java/org/battleplugins/arena/config/ItemStackParser.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.kyori.adventure.text.Component;
44
import net.kyori.adventure.text.format.TextDecoration;
55
import net.kyori.adventure.text.minimessage.MiniMessage;
6+
import org.bukkit.Bukkit;
67
import org.bukkit.Material;
78
import org.bukkit.NamespacedKey;
89
import org.bukkit.configuration.ConfigurationSection;
@@ -44,7 +45,19 @@ public ItemStack parse(Object object) throws ParseException {
4445
public static ItemStack deserializeSingular(String contents) throws ParseException {
4546
ItemStack itemStack;
4647

47-
SingularValueParser.ArgumentBuffer buffer = SingularValueParser.parseNamed(contents, SingularValueParser.BraceStyle.CURLY, ';');
48+
SingularValueParser.ArgumentBuffer buffer;
49+
try {
50+
buffer = SingularValueParser.parseNamed(contents, SingularValueParser.BraceStyle.CURLY, ';');
51+
} catch (ParseException e) {
52+
// If we get an error, let's try parsing using Minecraft's native format
53+
try {
54+
return Bukkit.getItemFactory().createItemStack(contents);
55+
} catch (IllegalArgumentException ex) {
56+
ex.initCause(e);
57+
throw e;
58+
}
59+
}
60+
4861
if (!buffer.hasNext()) {
4962
throw new ParseException("No data found for ItemStack")
5063
.cause(ParseException.Cause.INVALID_TYPE)

plugin/src/main/java/org/battleplugins/arena/module/ArenaModuleLoader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public void loadModules() throws IOException {
112112
public void enableModules() {
113113
this.modules.values().forEach(module -> {
114114
if (this.plugin.getMainConfig().getDisabledModules().contains(module.module().id())) {
115-
this.plugin.info("Module {} is disabled in the configuration. Skipping...", module.module().name());
115+
this.plugin.debug("Module {} is disabled in the configuration. Skipping...", module.module().name());
116116
return;
117117
}
118118

0 commit comments

Comments
 (0)