From 2829a1af2b4500adf5ed23ea01e20173cfc391d8 Mon Sep 17 00:00:00 2001 From: EpicKnarvik97 Date: Tue, 4 Jul 2023 19:19:51 +0200 Subject: [PATCH] Allows specifying different particle effects depending on the material --- README.md | 39 ++--- .../config/LaunchpadConfiguration.java | 71 ++++---- .../config/LaunchpadParticleConfig.java | 151 ++++++++++++++++++ .../launchpad/task/ParticleSpawner.java | 99 ++++++------ .../launchpad/util/MaterialHelper.java | 34 ++-- src/main/resources/config.yml | 5 +- 6 files changed, 284 insertions(+), 115 deletions(-) create mode 100644 src/main/java/net/knarcraft/launchpad/config/LaunchpadParticleConfig.java diff --git a/README.md b/README.md index 0f04d37..65a468e 100644 --- a/README.md +++ b/README.md @@ -32,22 +32,23 @@ If you alter several launchpad values in succession, they'll all be applied to t ## Configuration -| Node | Type | Description | -|-------------------------------------------------------------|-------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| -| launchpad.materials | List | A list of materials, or material tags (+TAG_NAME), which are always treated as launchpads, without the need for manual registration. | -| launchpad.materialWhitelist | List | A list of materials, or material tags (+TAG_NAME), which can be manually turned into launchpads. Use this to prevent unwanted blocks from being turned into launchpads. | -| launchpad.verticalVelocity | Decimal number | The vertical (upwards) velocity applied to launchpads if not specified otherwise. | -| launchpad.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads if not specified otherwise. | -| launchpad.materialVelocities.\.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads of type \ if not overridden for the block. | -| launchpad.materialVelocities.\.verticalVelocity | Decimal number | The vertical (sideways) velocity applied to launchpads of type \ if not overridden for the block. | -| launchpad.particles.enabled | True / False | Whether to display some kind of particle effect above manually added launchpads. | -| launchpad.particles.mode | SINGLE / SQUARE / PYRAMID / SPHERE / CIRCLE | The mode used for drawing particles. SINGLE directly spawns the particle(s) in one spot above the launchpad. The other ones spawn particles a bunch of times in a pattern. | -| launchpad.particles.type | [Particle](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html) | The type of particle to spawn above launchpads. | -| launchpad.particles.amount | Positive integer | The amount of particles to spawn. Use 1 if mode is anything except SINGLE, unless you know what you are doing! | -| launchpad.particles.offsetX | Decimal number | The offset, or spread of the particles in the X direction, relative to the launchpad | -| launchpad.particles.offsetY | Decimal number | The offset, or spread of the particles in the Y direction, relative to the launchpad | -| launchpad.particles.offsetZ | Decimal number | The offset, or spread of the particles in the Z direction, relative to the launchpad | -| launchpad.particles.heightOffset | Decimal number | The amount of blocks above the launchpad the particle should spawn. 0.5 = half a block. 1 = one block. | -| launchpad.particles.particleDensity | Decimal number | A definition for the number of particles used to draw shapes. The number of particles is basically `distance / particleDensity`, so lower numbers create a more dense shape. | -| launchpad.particles.extra | Decimal number | Extra data for the specific particle. Check the Spigot documentation for details. | -| launchpad.particles.spawnDelay | Positive integer | The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on the particle, higher values will make the particle(s) completely disappear and reappear. | \ No newline at end of file +| Node | Type | Description | +|-------------------------------------------------------------|-------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| launchpad.materials | List | A list of materials, or material tags (+TAG_NAME), which are always treated as launchpads, without the need for manual registration. | +| launchpad.materialWhitelist | List | A list of materials, or material tags (+TAG_NAME), which can be manually turned into launchpads. Use this to prevent unwanted blocks from being turned into launchpads. | +| launchpad.verticalVelocity | Decimal number | The vertical (upwards) velocity applied to launchpads if not specified otherwise. | +| launchpad.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads if not specified otherwise. | +| launchpad.materialVelocities.\.horizontalVelocity | Decimal number | The horizontal (sideways) velocity applied to launchpads of type \ if not overridden for the block. | +| launchpad.materialVelocities.\.verticalVelocity | Decimal number | The vertical (sideways) velocity applied to launchpads of type \ if not overridden for the block. | +| launchpad.particles.enabled | True / False | Whether to display some kind of particle effect above manually added launchpads. | +| launchpad.particles.mode | SINGLE / SQUARE / PYRAMID / SPHERE / CIRCLE | The mode used for drawing particles. SINGLE directly spawns the particle(s) in one spot above the launchpad. The other ones spawn particles a bunch of times in a pattern. | +| launchpad.particles.type | [Particle](https://hub.spigotmc.org/javadocs/spigot/org/bukkit/Particle.html) | The type of particle to spawn above launchpads. | +| launchpad.particles.amount | Positive integer | The amount of particles to spawn. Use 1 if mode is anything except SINGLE, unless you know what you are doing! | +| launchpad.particles.offsetX | Decimal number | The offset, or spread of the particles in the X direction, relative to the launchpad | +| launchpad.particles.offsetY | Decimal number | The offset, or spread of the particles in the Y direction, relative to the launchpad | +| launchpad.particles.offsetZ | Decimal number | The offset, or spread of the particles in the Z direction, relative to the launchpad | +| launchpad.particles.heightOffset | Decimal number | The amount of blocks above the launchpad the particle should spawn. 0.5 = half a block. 1 = one block. | +| launchpad.particles.particleDensity | Decimal number | A definition for the number of particles used to draw shapes. The number of particles is basically `distance / particleDensity`, so lower numbers create a more dense shape. | +| launchpad.particles.extra | Decimal number | Extra data for the specific particle. Check the Spigot documentation for details. | +| launchpad.particles.spawnDelay | Positive integer | The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on the particle, higher values will make the particle(s) completely disappear and reappear. | +| launchpad.particles.materialParticles | Configuration section | This section allows specifying different particle configurations for a material or a material tag. So you'd set materialParticles.LIGHT_WEIGHTED_PRESSURE_PLATE.type to set the particle type for LIGHT_WEIGHTED_PRESSURE_PLATE. | \ No newline at end of file diff --git a/src/main/java/net/knarcraft/launchpad/config/LaunchpadConfiguration.java b/src/main/java/net/knarcraft/launchpad/config/LaunchpadConfiguration.java index 9a58490..feacf40 100644 --- a/src/main/java/net/knarcraft/launchpad/config/LaunchpadConfiguration.java +++ b/src/main/java/net/knarcraft/launchpad/config/LaunchpadConfiguration.java @@ -6,13 +6,14 @@ import net.knarcraft.launchpad.task.ParticleSpawner; import net.knarcraft.launchpad.util.MaterialHelper; import org.bukkit.Bukkit; import org.bukkit.Material; -import org.bukkit.Particle; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.file.FileConfiguration; import org.jetbrains.annotations.NotNull; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.logging.Level; @@ -148,45 +149,51 @@ public class LaunchpadConfiguration { } boolean previousEnabled = this.particlesEnabled; this.particlesEnabled = particlesSection.getBoolean("enabled", false); - @NotNull Particle particleType; - try { - particleType = Particle.valueOf(particlesSection.getString("type")); - } catch (IllegalArgumentException exception) { - particleType = Particle.ASH; - } - int particleAmount = particlesSection.getInt("amount", 30); - double offsetX = particlesSection.getDouble("offsetX", 0.5); - double offsetY = particlesSection.getDouble("offsetY", 1); - double offsetZ = particlesSection.getDouble("offsetZ", 0.5); - double heightOffset = particlesSection.getDouble("heightOffset", 0.5); - double particleDensity = particlesSection.getDouble("particleDensity", 0.1); - double extra = particlesSection.getDouble("extra", 0); - int spawnDelay = particlesSection.getInt("spawnDelay", 20); - ParticleMode particleMode; - try { - particleMode = ParticleMode.valueOf(particlesSection.getString("mode")); - } catch (IllegalArgumentException exception) { - particleMode = ParticleMode.SINGLE; - } - - // Make sure particle density is between 1 (inclusive) and 0 (exclusive) - if (particleDensity <= 0) { - particleDensity = 0.1; - } else if (particleDensity > 360) { - particleDensity = 360; - } + // Cancel previous particle spawning task if previously enabled if (previousEnabled) { - // Cancel previous particle spawning task Bukkit.getScheduler().cancelTask(particleTaskId); } + // Start particle spawning if enabled if (this.particlesEnabled) { - // Start particle spawning + LaunchpadParticleConfig particleConfig = new LaunchpadParticleConfig(particlesSection); + + // Load any per-material configuration options + Map materialConfigs; + ConfigurationSection perMaterialSection = particlesSection.getConfigurationSection("materialParticles"); + if (perMaterialSection != null) { + materialConfigs = loadMaterialParticleConfigs(perMaterialSection); + } else { + materialConfigs = new HashMap<>(); + } + particleTaskId = Bukkit.getScheduler().scheduleSyncRepeatingTask(Launchpad.getInstance(), - new ParticleSpawner(particleMode, particleType, particleAmount, particleDensity, heightOffset, - offsetX, offsetY, offsetZ, extra), 20, spawnDelay); + new ParticleSpawner(particleConfig, materialConfigs), 20, particleConfig.getSpawnDelay()); } } + /** + * Loads all per-material particle configuration options + * + * @param perMaterialSection

The configuration section containing per-material particle options

+ * @return

The loaded per-material particle configuration options

+ */ + private @NotNull Map loadMaterialParticleConfigs( + @NotNull ConfigurationSection perMaterialSection) { + Map materialConfigs = new HashMap<>(); + for (String key : perMaterialSection.getKeys(false)) { + Set materials = MaterialHelper.loadMaterialString(key); + ConfigurationSection materialSection = perMaterialSection.getConfigurationSection(key); + if (materialSection == null) { + continue; + } + LaunchpadParticleConfig materialParticleConfig = new LaunchpadParticleConfig(materialSection); + for (Material material : materials) { + materialConfigs.put(material, materialParticleConfig); + } + } + return materialConfigs; + } + } diff --git a/src/main/java/net/knarcraft/launchpad/config/LaunchpadParticleConfig.java b/src/main/java/net/knarcraft/launchpad/config/LaunchpadParticleConfig.java new file mode 100644 index 0000000..da97e07 --- /dev/null +++ b/src/main/java/net/knarcraft/launchpad/config/LaunchpadParticleConfig.java @@ -0,0 +1,151 @@ +package net.knarcraft.launchpad.config; + +import org.bukkit.Particle; +import org.bukkit.configuration.ConfigurationSection; +import org.jetbrains.annotations.NotNull; + +/** + * A configuration describing a launchpad + */ +public class LaunchpadParticleConfig { + + private final ParticleMode particleMode; + private final Particle particleType; + private final int particleAmount; + private final double particleDensity; + private final double heightOffset; + private final int spawnDelay; + private final double offsetX; + private final double offsetY; + private final double offsetZ; + private final double extra; + + /** + * Instantiates a new particle config + * + * @param particlesSection

The configuration section containing the particle's settings

+ */ + public LaunchpadParticleConfig(ConfigurationSection particlesSection) { + @NotNull Particle particleType; + try { + particleType = Particle.valueOf(particlesSection.getString("type")); + } catch (IllegalArgumentException | NullPointerException exception) { + particleType = Particle.ASH; + } + this.particleType = particleType; + this.particleAmount = particlesSection.getInt("amount", 30); + this.offsetX = particlesSection.getDouble("offsetX", 0.5); + this.offsetY = particlesSection.getDouble("offsetY", 1); + this.offsetZ = particlesSection.getDouble("offsetZ", 0.5); + this.heightOffset = particlesSection.getDouble("heightOffset", 0.5); + this.extra = particlesSection.getDouble("extra", 0); + this.spawnDelay = particlesSection.getInt("spawnDelay", 20); + ParticleMode particleMode; + try { + particleMode = ParticleMode.valueOf(particlesSection.getString("mode")); + } catch (IllegalArgumentException | NullPointerException exception) { + particleMode = ParticleMode.SINGLE; + } + this.particleMode = particleMode; + + // Make sure particle density is between 1 (inclusive) and 0 (exclusive) + double particleDensity = particlesSection.getDouble("particleDensity", 0.1); + if (particleDensity <= 0) { + particleDensity = 0.1; + } else if (particleDensity > 360) { + particleDensity = 360; + } + this.particleDensity = particleDensity; + } + + /** + * The mode to use when drawing/spawning the particle(s) + * + * @return

The particle mode

+ */ + public ParticleMode getParticleMode() { + return particleMode; + } + + /** + * The type of particle to spawn + * + * @return

The particle type

+ */ + public Particle getParticleType() { + return particleType; + } + + /** + * The amount of particles to spawn + * + * @return

The amount of particles

+ */ + public int getParticleAmount() { + return particleAmount; + } + + /** + * The density of particles to use in shapes closer to 0 causes larger density + * + * @return

The particle density

+ */ + public double getParticleDensity() { + return particleDensity; + } + + /** + * The number of blocks above the launchpad the particle(s) should spawn + * + * @return

The y-offset

+ */ + public double getHeightOffset() { + return heightOffset; + } + + /** + * Gets the delay in ticks to wait before spawning the particle(s) again + * + * @return

The spawn delay

+ */ + public int getSpawnDelay() { + return spawnDelay; + } + + /** + * The offset/spread of particles in the x-direction + * + * @return

The x-offset

+ */ + public double getOffsetX() { + return offsetX; + } + + /** + * The offset/spread of particles in the y-direction + * + * @return

The y-offset

+ */ + public double getOffsetY() { + return offsetY; + } + + /** + * The offset/spread of particles in the z-direction + * + * @return

The z-offset

+ */ + public double getOffsetZ() { + return offsetZ; + } + + /** + * The extra value to set for the particle. Exactly what it does depends on the particle. + * + * @return

The particle's extra value

+ */ + public double getExtra() { + return extra; + } + +} diff --git a/src/main/java/net/knarcraft/launchpad/task/ParticleSpawner.java b/src/main/java/net/knarcraft/launchpad/task/ParticleSpawner.java index 6de4d76..faa9165 100644 --- a/src/main/java/net/knarcraft/launchpad/task/ParticleSpawner.java +++ b/src/main/java/net/knarcraft/launchpad/task/ParticleSpawner.java @@ -1,64 +1,43 @@ package net.knarcraft.launchpad.task; -import net.knarcraft.launchpad.config.ParticleMode; +import net.knarcraft.launchpad.config.LaunchpadParticleConfig; import net.knarcraft.launchpad.launchpad.LaunchpadBlock; import net.knarcraft.launchpad.launchpad.LaunchpadBlockHandler; import org.bukkit.Location; -import org.bukkit.Particle; +import org.bukkit.Material; import org.bukkit.World; import org.bukkit.util.BoundingBox; import org.bukkit.util.Vector; import org.jetbrains.annotations.NotNull; +import java.util.Map; + /** * A runnable tasks that spawns particles at every launchpad */ public class ParticleSpawner implements Runnable { - private final ParticleMode particleMode; - private final Particle particleType; - private final int particleAmount; - private final double particleDensity; - private final double heightOffset; - private final double offsetX; - private final double offsetY; - private final double offsetZ; - private final double extra; - private Vector[] pyramidVectors; private double[][] circleCoordinates; private double[][] sphereCoordinates; + private final LaunchpadParticleConfig particleConfig; + private final Map materialConfigs; private LaunchpadBlock processingLaunchpad = null; /** * Instantiates a new particle spawner * - * @param particleMode

The mode used when spawning particles

- * @param particleType

The type of particle to spawn

- * @param particleAmount

The amount of particles to spawn at once

- * @param particleDensity

The density of particles for particle shapes. Lower = more particles.

- * @param heightOffset

The height above the launchpad the particle should spawn

- * @param offsetX

The offset of the particle in the X direction

- * @param offsetY

The offset of the particle in the Y direction

- * @param offsetZ

The offset of the particle in the Z direction

- * @param extra

Extra data for the particle

+ * @param particleConfig

The configuration for the particle to spawn

*/ - public ParticleSpawner(@NotNull ParticleMode particleMode, @NotNull Particle particleType, int particleAmount, - double particleDensity, double heightOffset, double offsetX, double offsetY, double offsetZ, - double extra) { - this.particleMode = particleMode; - this.particleType = particleType; - this.particleAmount = particleAmount; - this.particleDensity = particleDensity; - this.heightOffset = heightOffset; - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - this.extra = extra; + public ParticleSpawner(LaunchpadParticleConfig particleConfig, Map materialConfigs) { + this.particleConfig = particleConfig; + this.materialConfigs = materialConfigs; this.pyramidVectors = null; this.circleCoordinates = null; + this.sphereCoordinates = null; } @Override @@ -78,8 +57,9 @@ public class ParticleSpawner implements Runnable { // Store the currently processed launchpad for height calculation processingLaunchpad = launchpad; - switch (particleMode) { - case SINGLE -> spawnParticle(world, location.clone().add(0.5, heightOffset, 0.5)); + switch (getParticleConfig().getParticleMode()) { + case SINGLE -> spawnParticle(world, location.clone().add( + 0.5, getParticleConfig().getHeightOffset(), 0.5)); case SQUARE -> drawSquare(world, location); case CIRCLE -> drawCircle(world, location); case PYRAMID -> drawPyramid(world, location); @@ -88,6 +68,19 @@ public class ParticleSpawner implements Runnable { } } + /** + * Gets the particle config to use for the current launchpad's material + * + * @return

The particle config to use

+ */ + private LaunchpadParticleConfig getParticleConfig() { + LaunchpadParticleConfig materialConfig = this.materialConfigs.get(processingLaunchpad.getBlock().getType()); + if (materialConfig != null) { + return materialConfig; + } + return this.particleConfig; + } + /** * Spawns a sphere of particles at the given location * @@ -97,7 +90,7 @@ public class ParticleSpawner implements Runnable { private void drawSphere(@NotNull World world, @NotNull Location location) { // For spheres, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point // errors when calculating the length of circleCoordinates - double density = Math.max(1, particleDensity); + double density = Math.max(1, getParticleConfig().getParticleDensity()); // Store calculations for improved efficiency if (sphereCoordinates == null) { int length = (int) Math.ceil((180 / density)); @@ -108,11 +101,11 @@ public class ParticleSpawner implements Runnable { continue; } sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5, - heightOffset + 0.5, (0.5 * Math.cos(x)) + 0.5}; + getParticleConfig().getHeightOffset() + 0.5, (0.5 * Math.cos(x)) + 0.5}; sphereCoordinates[i++] = new double[]{(0.5 * Math.sin(x)) + 0.5, - heightOffset + 0.5 + (0.5 * Math.cos(x)), 0.5}; + getParticleConfig().getHeightOffset() + 0.5 + (0.5 * Math.cos(x)), 0.5}; sphereCoordinates[i++] = new double[]{0.5, - heightOffset + 0.5 + (0.5 * Math.sin(x)), (0.5 * Math.cos(x)) + 0.5}; + getParticleConfig().getHeightOffset() + 0.5 + (0.5 * Math.sin(x)), (0.5 * Math.cos(x)) + 0.5}; } } @@ -135,12 +128,12 @@ public class ParticleSpawner implements Runnable { // Store calculations for improved efficiency if (pyramidVectors == null) { // The 0.5 offsets are required for the angle of the pyramid's 4 lines to be correct - double coordinateMin = -0.5 * heightOffset; - double coordinateMax = 1 + (0.5 * heightOffset); + double coordinateMin = -0.5 * getParticleConfig().getHeightOffset(); + double coordinateMax = 1 + (0.5 * getParticleConfig().getHeightOffset()); pyramidVectors = new Vector[5]; // The vector from the origin to the top of the pyramid - pyramidVectors[0] = new Vector(0.5, 1 + heightOffset, 0.5); + pyramidVectors[0] = new Vector(0.5, 1 + getParticleConfig().getHeightOffset(), 0.5); // The vectors from the top of the pyramid towards each corner pyramidVectors[1] = new Vector(coordinateMin, 0, coordinateMin).subtract(pyramidVectors[0]).normalize(); pyramidVectors[2] = new Vector(coordinateMax, 0, coordinateMin).subtract(pyramidVectors[0]).normalize(); @@ -149,7 +142,7 @@ public class ParticleSpawner implements Runnable { } Location topLocation = location.clone().add(pyramidVectors[0]); - for (double x = 0; x <= 1.2; x += particleDensity) { + for (double x = 0; x <= 1.2; x += getParticleConfig().getParticleDensity()) { spawnParticle(world, topLocation.clone().add(pyramidVectors[1].clone().multiply(x))); spawnParticle(world, topLocation.clone().add(pyramidVectors[2].clone().multiply(x))); spawnParticle(world, topLocation.clone().add(pyramidVectors[3].clone().multiply(x))); @@ -166,7 +159,7 @@ public class ParticleSpawner implements Runnable { private void drawCircle(@NotNull World world, @NotNull Location location) { // For circles, densities below 0.1 has weird bugs such as blinking in and out of existence, and floating point // errors when calculating the length of circleCoordinates - double density = Math.max(1, particleDensity); + double density = Math.max(1, getParticleConfig().getParticleDensity()); // Store calculations for improved efficiency if (circleCoordinates == null) { circleCoordinates = new double[(int) Math.ceil((180 / density))][]; @@ -181,7 +174,7 @@ public class ParticleSpawner implements Runnable { // Spawn particles on the stored locations, relative to the launchpad for (double[] circleCoordinate : circleCoordinates) { - spawnParticle(world, location.clone().add(circleCoordinate[0], heightOffset, circleCoordinate[1])); + spawnParticle(world, location.clone().add(circleCoordinate[0], getParticleConfig().getHeightOffset(), circleCoordinate[1])); } } @@ -192,11 +185,11 @@ public class ParticleSpawner implements Runnable { * @param location

The location of the block to spawn the particles at

*/ private void drawSquare(@NotNull World world, @NotNull Location location) { - for (float x = 0; x <= 1; x += particleDensity) { - spawnParticle(world, location.clone().add(x, heightOffset, 0)); - spawnParticle(world, location.clone().add(x, heightOffset, 1)); - spawnParticle(world, location.clone().add(0, heightOffset, x)); - spawnParticle(world, location.clone().add(1, heightOffset, x)); + for (float x = 0; x <= 1; x += getParticleConfig().getParticleDensity()) { + spawnParticle(world, location.clone().add(x, getParticleConfig().getHeightOffset(), 0)); + spawnParticle(world, location.clone().add(x, getParticleConfig().getHeightOffset(), 1)); + spawnParticle(world, location.clone().add(0, getParticleConfig().getHeightOffset(), x)); + spawnParticle(world, location.clone().add(1, getParticleConfig().getHeightOffset(), x)); } } @@ -207,8 +200,10 @@ public class ParticleSpawner implements Runnable { * @param location

The location to spawn the particle at

*/ private void spawnParticle(@NotNull World world, @NotNull Location location) { - world.spawnParticle(particleType, location.add(0, getBlockHeight(processingLaunchpad), 0), particleAmount, - offsetX, offsetY, offsetZ, extra); + world.spawnParticle(getParticleConfig().getParticleType(), + location.add(0, getBlockHeight(processingLaunchpad), 0), getParticleConfig().getParticleAmount(), + getParticleConfig().getOffsetX(), getParticleConfig().getOffsetY(), getParticleConfig().getOffsetZ(), + getParticleConfig().getExtra()); } /** diff --git a/src/main/java/net/knarcraft/launchpad/util/MaterialHelper.java b/src/main/java/net/knarcraft/launchpad/util/MaterialHelper.java index d9fc791..cfae3e3 100644 --- a/src/main/java/net/knarcraft/launchpad/util/MaterialHelper.java +++ b/src/main/java/net/knarcraft/launchpad/util/MaterialHelper.java @@ -33,18 +33,30 @@ public final class MaterialHelper { continue; } - // Try to parse a material tag first - if (parseMaterialTag(parsedMaterials, string)) { - continue; - } + parsedMaterials.addAll(loadMaterialString(string)); + } + return parsedMaterials; + } - // Try to parse a material name - Material matched = Material.matchMaterial(string); - if (matched != null) { - parsedMaterials.add(matched); - } else { - Launchpad.log(Level.WARNING, "&cUnable to parse material: " + string); - } + /** + * Parses a string representing a material or a material tag + * + * @param materialString

The material string to parse

+ * @return

The materials defined by the material string, or an empty list if none were found

+ */ + public static @NotNull Set loadMaterialString(@NotNull String materialString) { + Set parsedMaterials = new HashSet<>(); + // Try to parse a material tag first + if (parseMaterialTag(parsedMaterials, materialString)) { + return parsedMaterials; + } + + // Try to parse a material name + Material matched = Material.matchMaterial(materialString); + if (matched != null) { + parsedMaterials.add(matched); + } else { + Launchpad.log(Level.WARNING, "&cUnable to parse material: " + materialString); } return parsedMaterials; } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index e3de377..ab1dd71 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -47,4 +47,7 @@ launchpad: extra: 0 # The amount of ticks (1 second = 20 ticks) between each time the particle(s) should be spawned again. Depending on # the particle, higher values will make the particle(s) completely disappear and reappear. - spawnDelay: 20 \ No newline at end of file + spawnDelay: 20 + # Particle configurations per material. So you'd set materialParticles.LIGHT_WEIGHTED_PRESSURE_PLATE.type to set the + # particle type for LIGHT_WEIGHTED_PRESSURE_PLATE. + materialParticles: [ ] \ No newline at end of file