aParticleList = new ArrayList<>();
+
+ // Process each particle in the frame
+ for (ParticleInfo particleInfo : entry.getValue()) {
+ Particle particleType = Particle.valueOf(particleInfo.getParticleType());
+ double x = particleInfo.getX();
+ double y = particleInfo.getY();
+ double z = particleInfo.getZ();
- double x = (double) pData.get("x");
- double y = (double) pData.get("y");
- double z = (double) pData.get("z");
ParticleBuilder particleBuilder = new ParticleBuilder(particleType);
- if (particleType.getDataType().equals(Particle.DustOptions.class)) {
- int rgb = HexFormat.fromHexDigits((String) pData.get("color"));
+
+ // Handle different particle data types
+ if (particleType.getDataType().equals(Particle.DustOptions.class) && particleInfo.getColor() != null) {
+ int rgb = HexFormat.fromHexDigits(particleInfo.getColor());
particleBuilder.data(new Particle.DustOptions(Color.fromRGB(rgb), 1));
}
// else if (particleType.getDataType().equals(MaterialData.class)) {
@@ -103,38 +97,50 @@ public class ParticleConfig {
//TODO implement
} else if (particleType.getDataType().equals(ItemStack.class)) {
//TODO implement
- } else {
- double data = (double) pData.get("extra");
- particleBuilder.extra(data);
+ } else if (particleInfo.getExtra() != null) {
+ particleBuilder.extra(particleInfo.getExtra());
}
+
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
}
+
loadedFrames.add(new Frame(aParticleList));
}
- return new ParticleSet(loadedFrames, displayName, List.of(lore.split("\n")), frameDelay, repeat, repeatDelay, stationary, aPartType, particleName, permission, packagePermission, displayItem);
+
+ // Create and return the ParticleSet
+ ItemStack displayItem = new ItemStack(Material.valueOf(particleData.getDisplayItem()));
+ return new ParticleSet(
+ loadedFrames,
+ particleData.getDisplayName(),
+ List.of(particleData.getLore().split("\n")),
+ particleData.getFrameDelay(),
+ particleData.getRepeat(),
+ particleData.getRepeatDelay(),
+ particleData.isStationary(),
+ particleData.getAPartType(),
+ particleData.getParticleName(),
+ particleData.getPermission(),
+ particleData.getPackagePermission(),
+ displayItem
+ );
}
public static void reload() {
ParticleStorage.clear();
ParticleConfig instance = getInstance();
+
for (File file : instance.getJsonFiles()) {
- JSONParser parser = new JSONParser();
try {
- Object obj = parser.parse(new FileReader(file));
- ParticleSet particleSet = instance.loadParticle((JSONObject) obj);
+ ParticleData particleData = objectMapper.readValue(file, ParticleData.class);
+
+ ParticleSet particleSet = instance.convertToParticleSet(particleData);
+
ParticleStorage.addParticleSet(particleSet.getAPartType(), particleSet);
- } catch (FileNotFoundException e) {
- e.printStackTrace();
} catch (IOException e) {
- e.printStackTrace();
- } catch (ParseException e) {
- e.printStackTrace();
+ Logger.error("Error reading particle file " + file.getName(), e);
} catch (Exception exception) {
- exception.printStackTrace();
+ Logger.error("Error processing particle file " + file.getName(), exception);
}
}
-
- //TODO implement
}
}
-
diff --git a/src/main/java/com/alttd/models/ParticleData.java b/src/main/java/com/alttd/models/ParticleData.java
new file mode 100644
index 0000000..4a2c336
--- /dev/null
+++ b/src/main/java/com/alttd/models/ParticleData.java
@@ -0,0 +1,77 @@
+package com.alttd.models;
+
+import com.alttd.objects.APartType;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+import java.util.Map;
+import java.util.List;
+
+/**
+ * Represents the configuration data for a particle effect, including its name, type, display properties,
+ * animations, and permissions. This class is primarily used for managing particle data in the context
+ * of custom particle effects and animations.
+ *
+ * Fields:
+ * - particleName: The unique name of the particle effect, used internally.
+ * - displayName: The name displayed to the user.
+ * - particleType: The type of the particle effect, which corresponds to an {@link APartType}.
+ * - lore: Additional descriptive text associated with the particle effect.
+ * - displayItem: An item representation for display purposes in order to visually represent the effect.
+ * - permission: The permission string required for accessing the particle effect.
+ * - packagePermission: A specific permission string linked to a grouped set of effects.
+ * - frameDelay: The delay between animation frames, in milliseconds.
+ * - repeat: The number of times the particle animation should repeat.
+ * - repeatDelay: The delay between repeat executions, in milliseconds.
+ * - randomOffset: A random position offset applied to the particle effect for variances.
+ * - stationary: Determines if the particle effect remains static or follows movement.
+ * - frames: A map defining animation frames for the particle effect. The key is an identifier, and the
+ * value is a list of {@link ParticleInfo} objects representing the frame's particle configuration.
+ *
+ * Methods:
+ * - getAPartType(): Converts the particleType string field into an equivalent {@link APartType} enum value.
+ * This allows for accessing predefined properties of the particle type.
+ */
+@Setter
+@Getter
+public class ParticleData {
+ @JsonProperty("particle_name")
+ private String particleName;
+
+ @JsonProperty("display_name")
+ private String displayName;
+
+ @JsonProperty("particle_type")
+ private String particleType;
+
+ private String lore;
+
+ @JsonProperty("display_item")
+ private String displayItem;
+
+ private String permission;
+
+ @JsonProperty("package_permission")
+ private String packagePermission;
+
+ @JsonProperty("frame_delay")
+ private int frameDelay;
+
+ private int repeat;
+
+ @JsonProperty("repeat_delay")
+ private int repeatDelay;
+
+ @JsonProperty("random_offset")
+ private double randomOffset;
+
+ private boolean stationary;
+
+ private Map> frames;
+
+ public APartType getAPartType() {
+ return APartType.valueOf(particleType);
+ }
+
+}
diff --git a/src/main/java/com/alttd/models/ParticleInfo.java b/src/main/java/com/alttd/models/ParticleInfo.java
new file mode 100644
index 0000000..8e04f07
--- /dev/null
+++ b/src/main/java/com/alttd/models/ParticleInfo.java
@@ -0,0 +1,39 @@
+package com.alttd.models;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import lombok.Getter;
+import lombok.Setter;
+
+/**
+ * Represents information about a particle, including its type, position, and additional properties.
+ * This class is used to describe the details of individual particles, including support for
+ * particle-specific attributes such as color and extra data.
+ *
+ * Fields:
+ * - particleType: The type of the particle, as defined by its name or identifier.
+ * - x, y, z: Coordinates representing the position of the particle in the 3D space.
+ * - color: A string representing the color of the particle, used primarily for "DustOptions".
+ * - extra: An additional property used for some specific particle types, allowing for further customization.
+ *
+ * The class is annotated for JSON serialization and deserialization using the Jackson library,
+ * ensuring smooth integration with JSON-based configurations.
+ *
+ * This object is used in the context of particle data configurations and animations.
+ */
+@Setter
+@Getter
+public class ParticleInfo {
+ @JsonProperty("particle_type")
+ private String particleType;
+
+ private double x;
+ private double y;
+ private double z;
+
+ // For DustOptions
+ private String color;
+
+ // For other particle types
+ private Double extra;
+
+}
diff --git a/src/main/java/com/alttd/util/Logger.java b/src/main/java/com/alttd/util/Logger.java
index 4087ea0..9666470 100644
--- a/src/main/java/com/alttd/util/Logger.java
+++ b/src/main/java/com/alttd/util/Logger.java
@@ -2,6 +2,8 @@ package com.alttd.util;
import com.alttd.AltitudeParticles;
+import java.util.logging.Level;
+
public class Logger {
static private final java.util.logging.Logger logger;
@@ -33,4 +35,8 @@ public class Logger {
}
logger.severe(severe);
}
+
+ public static void error(String error, Throwable throwable) {
+ logger.log(Level.SEVERE, error, throwable);
+ }
}