Skip to content

Commit

Permalink
Allow parsing Minecraft's native item format and fix modules loading …
Browse files Browse the repository at this point in the history
…again on plugin reload
  • Loading branch information
Redned235 committed Dec 29, 2024
1 parent 08b4b40 commit be664e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
23 changes: 12 additions & 11 deletions plugin/src/main/java/org/battleplugins/arena/BattleArena.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit be664e9

Please sign in to comment.