diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java index 034833cd..6645d280 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/api/player/profess/PlayerClass.java @@ -68,7 +68,7 @@ public class PlayerClass implements ExperienceObject, PreloadedObject { private final List skillSlots = new ArrayList<>(); private final List skillTrees = new ArrayList<>(); - private final List classScripts = new LinkedList(); + private final List classScripts = new ArrayList<>(); private final Map stats = new HashMap<>(); private final Map skills = new LinkedHashMap<>(); private final List subclasses = new ArrayList<>(); @@ -206,7 +206,14 @@ public class PlayerClass implements ExperienceObject, PreloadedObject { } // Casting particle - castParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle")) : null; + CastingParticle castingParticle; + try { + castingParticle = config.contains("cast-particle") ? new CastingParticle(config.getConfigurationSection("cast-particle")) : null; + } catch (RuntimeException exception) { + MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load casting mode particle of class '" + getId() + "': " + exception.getMessage()); + castingParticle = null; + } + this.castParticle = castingParticle; // Other class options if (config.contains("options")) @@ -216,7 +223,7 @@ public class PlayerClass implements ExperienceObject, PreloadedObject { config.getBoolean("options." + key)); } catch (IllegalArgumentException exception) { MMOCore.plugin.getLogger().log(Level.WARNING, - "Could not load option '" + key + "' from class '" + key + "': " + exception.getMessage()); + "Could not load option '" + key + "' from class '" + getId() + "': " + exception.getMessage()); } // Experience sources @@ -366,9 +373,9 @@ public class PlayerClass implements ExperienceObject, PreloadedObject { /** * @return A list of passive skills which correspond to class - * scripts wrapped in a format recognized by MythicLib. - * Class scripts are handled just like - * passive skills + * scripts wrapped in a format recognized by MythicLib. + * Class scripts are handled just like + * passive skills */ @NotNull public List getScripts() { diff --git a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/particle/CastingParticle.java b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/particle/CastingParticle.java index 3ccf2eb7..84b76c29 100644 --- a/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/particle/CastingParticle.java +++ b/MMOCore-API/src/main/java/net/Indyuce/mmocore/loot/chest/particle/CastingParticle.java @@ -1,40 +1,41 @@ package net.Indyuce.mmocore.loot.chest.particle; +import io.lumine.mythic.lib.UtilityMethods; import org.apache.commons.lang.Validate; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; +import org.bukkit.block.data.BlockData; import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.function.Consumer; public class CastingParticle { private final Consumer display; - public CastingParticle(ConfigurationSection config) { + public CastingParticle(@NotNull ConfigurationSection config) { Validate.notNull(config, "Casting particle config cannot be null"); - String format = config.getString("particle"); - Validate.notNull(format, "Could not read particle name"); - Particle particle = Particle.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_")); + final Particle particle = Particle.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("particle"), "Could not find particle name"))); - if (config.contains("color")) { - final float size = (float) config.getDouble("size") == 0 ? 1 : (float) Math.max(config.getDouble("size"), 0); - Color color = Color.fromRGB(config.getInt("color.red"), config.getInt("color.green"), config.getInt("color.blue")); + // Color + if (particle.getDataType() == Particle.DustOptions.class) { + final float size = Math.max((float) config.getDouble("size", 1), 0); + final Color color = Color.fromRGB(config.getInt("color.red"), config.getInt("color.green"), config.getInt("color.blue")); display = loc -> loc.getWorld().spawnParticle(particle, loc, 1, new Particle.DustOptions(color, size)); - return; } - if (config.contains("material")) { - format = config.getString("material"); - Validate.notNull(format, "Could not read material name"); - Material material = Material.valueOf(format.toUpperCase().replace("-", "_").replace(" ", "_")); + // Material + else if (particle.getDataType() == BlockData.class) { + final Material material = Material.valueOf(UtilityMethods.enumName(Objects.requireNonNull(config.getString("material"), "Particle requires a block"))); display = loc -> loc.getWorld().spawnParticle(particle, loc, 1, material.createBlockData()); - return; } - display = loc -> loc.getWorld().spawnParticle(particle, loc, 0); + // Anything else (does not work for all particles) + else display = loc -> loc.getWorld().spawnParticle(particle, loc, 0); } public CastingParticle(Particle particle) {