mirror of
https://github.com/TotalFreedomMC/PlayerParticles.git
synced 2025-01-05 22:28:22 +00:00
Group presets now use the InputParser system
This commit is contained in:
parent
b07f844d59
commit
2303696a09
2 changed files with 29 additions and 64 deletions
|
@ -25,16 +25,17 @@ public class ParticlePlaceholderExpansion extends PlaceholderExpansion {
|
||||||
if (pplayer == null)
|
if (pplayer == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (placeholder.equals("active_amount")) {
|
switch (placeholder) {
|
||||||
return String.valueOf(pplayer.getActiveParticles().size());
|
case "active_amount":
|
||||||
} else if (placeholder.equals("group_amount")) {
|
return String.valueOf(pplayer.getActiveParticles().size());
|
||||||
return String.valueOf(pplayer.getParticleGroups().size());
|
case "group_amount":
|
||||||
} else if (placeholder.equals("fixed_amount")) {
|
return String.valueOf(pplayer.getParticleGroups().size() - 1);
|
||||||
return String.valueOf(pplayer.getFixedParticles().size());
|
case "fixed_amount":
|
||||||
} else if (placeholder.equals("is_moving")) {
|
return String.valueOf(pplayer.getFixedParticles().size());
|
||||||
return String.valueOf(pplayer.isMoving());
|
case "is_moving":
|
||||||
} else if (placeholder.equals("can_see_particles")) {
|
return String.valueOf(pplayer.isMoving());
|
||||||
return String.valueOf(pplayer.canSeeParticles());
|
case "can_see_particles":
|
||||||
|
return String.valueOf(pplayer.canSeeParticles());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (placeholder.startsWith("particle_")) {
|
if (placeholder.startsWith("particle_")) {
|
||||||
|
|
|
@ -9,7 +9,7 @@ import dev.esophose.playerparticles.particles.ParticleGroup;
|
||||||
import dev.esophose.playerparticles.particles.ParticleGroupPreset;
|
import dev.esophose.playerparticles.particles.ParticleGroupPreset;
|
||||||
import dev.esophose.playerparticles.particles.ParticlePair;
|
import dev.esophose.playerparticles.particles.ParticlePair;
|
||||||
import dev.esophose.playerparticles.styles.ParticleStyle;
|
import dev.esophose.playerparticles.styles.ParticleStyle;
|
||||||
import dev.esophose.playerparticles.util.ParticleUtils;
|
import dev.esophose.playerparticles.util.inputparser.InputParser;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -96,8 +96,8 @@ public class ParticleGroupPresetManager extends Manager {
|
||||||
ConfigurationSection particleSection = groupSection.getConfigurationSection(stringId);
|
ConfigurationSection particleSection = groupSection.getConfigurationSection(stringId);
|
||||||
|
|
||||||
int id = Integer.parseInt(stringId);
|
int id = Integer.parseInt(stringId);
|
||||||
ParticleEffect effect = ParticleEffect.fromName(particleSection.getString("effect"));
|
ParticleEffect effect = new InputParser(null, new String[] { particleSection.getString("effect") }).next(ParticleEffect.class);
|
||||||
ParticleStyle style = ParticleStyle.fromName(particleSection.getString("style"));
|
ParticleStyle style = new InputParser(null, new String[] { particleSection.getString("style") }).next(ParticleStyle.class);
|
||||||
|
|
||||||
if (effect == null) {
|
if (effect == null) {
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid effect name: '" + particleSection.getString("effect") + "'!");
|
PlayerParticles.getInstance().getLogger().severe("Invalid effect name: '" + particleSection.getString("effect") + "'!");
|
||||||
|
@ -117,69 +117,33 @@ public class ParticleGroupPresetManager extends Manager {
|
||||||
String dataString = particleSection.getString("data");
|
String dataString = particleSection.getString("data");
|
||||||
if (dataString != null && !dataString.isEmpty()) {
|
if (dataString != null && !dataString.isEmpty()) {
|
||||||
String[] args = dataString.split(" ");
|
String[] args = dataString.split(" ");
|
||||||
|
InputParser inputParser = new InputParser(null, args);
|
||||||
|
|
||||||
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
if (effect.hasProperty(ParticleProperty.COLORABLE)) {
|
||||||
if (effect == ParticleEffect.NOTE) {
|
if (effect == ParticleEffect.NOTE) {
|
||||||
if (args[0].equalsIgnoreCase("rainbow")) {
|
noteColorData = inputParser.next(NoteColor.class);
|
||||||
noteColorData = new NoteColor(99);
|
if (noteColorData == null) {
|
||||||
} else if (args[0].equalsIgnoreCase("random")) {
|
PlayerParticles.getInstance().getLogger().severe("Invalid note: '" + dataString + "'!");
|
||||||
noteColorData = new NoteColor(98);
|
throw new Exception();
|
||||||
} else {
|
|
||||||
int note;
|
|
||||||
try {
|
|
||||||
note = Integer.parseInt(args[0]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid note: '" + args[0] + "'!");
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (note < 0 || note > 23) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid note: '" + args[0] + "'!");
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
noteColorData = new NoteColor(note);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (args[0].equalsIgnoreCase("rainbow")) {
|
colorData = inputParser.next(OrdinaryColor.class);
|
||||||
colorData = new OrdinaryColor(999, 999, 999);
|
if (colorData == null) {
|
||||||
} else if (args[0].equalsIgnoreCase("random")) {
|
PlayerParticles.getInstance().getLogger().severe("Invalid color: '" + dataString + "'!");
|
||||||
colorData = new OrdinaryColor(998, 998, 998);
|
throw new Exception();
|
||||||
} else {
|
|
||||||
int r, g, b;
|
|
||||||
|
|
||||||
try {
|
|
||||||
r = Integer.parseInt(args[0]);
|
|
||||||
g = Integer.parseInt(args[1]);
|
|
||||||
b = Integer.parseInt(args[2]);
|
|
||||||
} catch (Exception e) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid color: '" + args[0] + " " + args[1] + " " + args[2] + "'!");
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid color: '" + args[0] + " " + args[1] + " " + args[2] + "'!");
|
|
||||||
throw new Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
colorData = new OrdinaryColor(r, g, b);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
} else if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) {
|
||||||
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
|
if (effect == ParticleEffect.BLOCK || effect == ParticleEffect.FALLING_DUST) {
|
||||||
try {
|
blockData = inputParser.next(Material.class);
|
||||||
blockData = ParticleUtils.closestMatch(args[0]);
|
if (blockData == null || !blockData.isBlock()) {
|
||||||
if (blockData == null || !blockData.isBlock()) throw new Exception();
|
PlayerParticles.getInstance().getLogger().severe("Invalid block: '" + dataString + "'!");
|
||||||
} catch (Exception e) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid block: '" + args[0] + "'!");
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
} else if (effect == ParticleEffect.ITEM) {
|
} else if (effect == ParticleEffect.ITEM) {
|
||||||
try {
|
itemData = inputParser.next(Material.class);
|
||||||
itemData = ParticleUtils.closestMatch(args[0]);
|
if (itemData == null || itemData.isBlock()) {
|
||||||
if (itemData == null || itemData.isBlock()) throw new Exception();
|
PlayerParticles.getInstance().getLogger().severe("Invalid item: '" + dataString + "'!");
|
||||||
} catch (Exception e) {
|
|
||||||
PlayerParticles.getInstance().getLogger().severe("Invalid item: '" + args[0] + "'!");
|
|
||||||
throw new Exception();
|
throw new Exception();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue