diff --git a/src/main/java/dev/esophose/playerparticles/gui/GuiInventoryEditData.java b/src/main/java/dev/esophose/playerparticles/gui/GuiInventoryEditData.java index ef35e9a..d0ccd15 100644 --- a/src/main/java/dev/esophose/playerparticles/gui/GuiInventoryEditData.java +++ b/src/main/java/dev/esophose/playerparticles/gui/GuiInventoryEditData.java @@ -216,7 +216,7 @@ public class GuiInventoryEditData extends GuiInventory { localeManager.getLocaleMessage("gui-color-icon-name") + localeManager.getLocaleMessage("rainbow"), new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-data-description", StringPlaceholders.single("data", localeManager.getLocaleMessage("rainbow")))}, (button, isShiftClick) -> { - editingParticle.setColor(new OrdinaryColor(999, 999, 999)); + editingParticle.setColor(OrdinaryColor.RAINBOW); callbackList.get(callbackListPosition + 1).run(); }); this.actionButtons.add(setRainbowColorButton); @@ -231,7 +231,7 @@ public class GuiInventoryEditData extends GuiInventory { localeManager.getLocaleMessage("gui-color-icon-name") + localeManager.getLocaleMessage("random"), new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-data-description", StringPlaceholders.single("data", localeManager.getLocaleMessage("random")))}, (button, isShiftClick) -> { - editingParticle.setColor(new OrdinaryColor(998, 998, 998)); + editingParticle.setColor(OrdinaryColor.RANDOM); callbackList.get(callbackListPosition + 1).run(); }); this.actionButtons.add(setRandomColorButton); @@ -289,7 +289,7 @@ public class GuiInventoryEditData extends GuiInventory { localeManager.getLocaleMessage("gui-color-icon-name") + localeManager.getLocaleMessage("rainbow"), new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-data-description", StringPlaceholders.single("data", localeManager.getLocaleMessage("rainbow")))}, (button, isShiftClick) -> { - editingParticle.setNoteColor(new NoteColor(99)); + editingParticle.setNoteColor(NoteColor.RAINBOW); callbackList.get(callbackListPosition + 1).run(); }); this.actionButtons.add(setRainbowColorButton); @@ -305,7 +305,7 @@ public class GuiInventoryEditData extends GuiInventory { localeManager.getLocaleMessage("gui-color-icon-name") + localeManager.getLocaleMessage("random"), new String[]{localeManager.getLocaleMessage("gui-color-info") + localeManager.getLocaleMessage("gui-select-data-description", StringPlaceholders.single("data", localeManager.getLocaleMessage("random")))}, (button, isShiftClick) -> { - editingParticle.setNoteColor(new NoteColor(98)); + editingParticle.setNoteColor(NoteColor.RANDOM); callbackList.get(callbackListPosition + 1).run(); }); this.actionButtons.add(setRandomColorButton); diff --git a/src/main/java/dev/esophose/playerparticles/particles/ParticleEffect.java b/src/main/java/dev/esophose/playerparticles/particles/ParticleEffect.java index 1112f8c..8e419a1 100644 --- a/src/main/java/dev/esophose/playerparticles/particles/ParticleEffect.java +++ b/src/main/java/dev/esophose/playerparticles/particles/ParticleEffect.java @@ -11,6 +11,7 @@ import java.io.File; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.stream.Stream; import org.bukkit.Color; import org.bukkit.Location; @@ -280,11 +281,11 @@ public enum ParticleEffect { int count = pparticle.isDirectional() ? 0 : 1; if (effect.hasProperty(ParticleProperty.REQUIRES_MATERIAL_DATA)) { - effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect, owner); + effect.display(particle.getSpawnMaterial(), pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), 1, pparticle.getLocation(false), isFixedEffect, owner); } else if (effect.hasProperty(ParticleProperty.COLORABLE)) { - effect.display(particle.getSpawnColor(), pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect, owner); + effect.display(particle.getSpawnColor(), pparticle.getLocation(true), isFixedEffect, owner); } else { - effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(effect.hasProperty(ParticleProperty.COLORABLE)), isFixedEffect, owner); + effect.display(pparticle.getXOff(), pparticle.getYOff(), pparticle.getZOff(), pparticle.getSpeed(), count, pparticle.getLocation(false), isFixedEffect, owner); } } @@ -481,6 +482,9 @@ public enum ParticleEffect { * @since 1.7 */ public static final class OrdinaryColor extends ParticleColor { + public static final OrdinaryColor RAINBOW = new OrdinaryColor(999, 999, 999); + public static final OrdinaryColor RANDOM = new OrdinaryColor(998, 998, 998); + private final int red; private final int green; private final int blue; @@ -558,7 +562,8 @@ public enum ParticleEffect { */ @Override public float getValueX() { - if (this.red == 999 || this.red == 998) return 0F; + if (this.equals(OrdinaryColor.RAINBOW) || this.equals(OrdinaryColor.RANDOM)) + return 0F; return (float) this.red / 255F; } @@ -569,7 +574,8 @@ public enum ParticleEffect { */ @Override public float getValueY() { - if (this.green == 999 || this.green == 998) return 0F; + if (this.equals(OrdinaryColor.RAINBOW) || this.equals(OrdinaryColor.RANDOM)) + return 0F; return (float) this.green / 255F; } @@ -580,9 +586,23 @@ public enum ParticleEffect { */ @Override public float getValueZ() { - if (this.blue == 999 || this.blue == 998) return 0F; + if (this.equals(OrdinaryColor.RAINBOW) || this.equals(OrdinaryColor.RANDOM)) + return 0F; return (float) this.blue / 255F; } + + @Override + public boolean equals(Object other) { + if (!(other instanceof OrdinaryColor)) + return false; + OrdinaryColor otherColor = (OrdinaryColor) other; + return this.red == otherColor.red && this.green == otherColor.green && this.blue == otherColor.blue; + } + + @Override + public int hashCode() { + return Objects.hash(this.red, this.green, this.blue); + } } /** @@ -595,6 +615,9 @@ public enum ParticleEffect { * @since 1.7 */ public static final class NoteColor extends ParticleColor { + public static final NoteColor RAINBOW = new NoteColor(99); + public static final NoteColor RANDOM = new NoteColor(98); + private final int note; /** @@ -657,6 +680,19 @@ public enum ParticleEffect { return 0; } + @Override + public boolean equals(Object other) { + if (!(other instanceof NoteColor)) + return false; + NoteColor otherColor = (NoteColor) other; + return this.note == otherColor.note; + } + + @Override + public int hashCode() { + return Objects.hashCode(this.note); + } + } /** diff --git a/src/main/java/dev/esophose/playerparticles/particles/ParticlePair.java b/src/main/java/dev/esophose/playerparticles/particles/ParticlePair.java index a93c9e7..db0ff2b 100644 --- a/src/main/java/dev/esophose/playerparticles/particles/ParticlePair.java +++ b/src/main/java/dev/esophose/playerparticles/particles/ParticlePair.java @@ -207,16 +207,16 @@ public class ParticlePair { if (this.effect.hasProperty(ParticleProperty.COLORABLE)) { if (this.effect == ParticleEffect.NOTE) { - if (this.noteColor.getNote() == 99) { + if (this.noteColor.equals(NoteColor.RAINBOW)) { return particleManager.getRainbowNoteParticleColor(); - } else if (this.noteColor.getNote() == 98) { + } else if (this.noteColor.equals(NoteColor.RANDOM)) { return particleManager.getRandomNoteParticleColor(); } return this.noteColor; } else { - if (this.color.getRed() == 999 && this.color.getGreen() == 999 && this.color.getBlue() == 999) { + if (this.color.equals(OrdinaryColor.RAINBOW)) { return particleManager.getRainbowParticleColor(); - } else if (this.color.getRed() == 998 && this.color.getGreen() == 998 && this.color.getBlue() == 998) { + } else if (this.color.equals(OrdinaryColor.RANDOM)) { return particleManager.getRandomParticleColor(); } else { return this.color; @@ -255,16 +255,16 @@ public class ParticlePair { return this.itemMaterial.toString().toLowerCase(); } else if (this.effect.hasProperty(ParticleProperty.COLORABLE)) { if (this.effect == ParticleEffect.NOTE) { - if (this.noteColor.getNote() == 99) { + if (this.noteColor.equals(NoteColor.RAINBOW)) { return localeManager.getLocaleMessage("rainbow"); - } else if (this.noteColor.getNote() == 98) { + } else if (this.noteColor.equals(NoteColor.RANDOM)) { return localeManager.getLocaleMessage("random"); } return localeManager.getLocaleMessage("gui-select-data-note", StringPlaceholders.single("note", this.noteColor.getNote())); } else { - if (this.color.getRed() == 999 && this.color.getGreen() == 999 && this.color.getBlue() == 999) { + if (this.color.equals(OrdinaryColor.RAINBOW)) { return localeManager.getLocaleMessage("rainbow"); - } else if (this.color.getRed() == 998 && this.color.getGreen() == 998 && this.color.getBlue() == 998) { + } else if (this.color.equals(OrdinaryColor.RANDOM)) { return localeManager.getLocaleMessage("random"); } else { return ChatColor.RED + "" + this.color.getRed() + " " + ChatColor.GREEN + this.color.getGreen() + " " + ChatColor.AQUA + this.color.getBlue(); diff --git a/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableNoteColor.java b/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableNoteColor.java index b85d6aa..8d17dd7 100644 --- a/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableNoteColor.java +++ b/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableNoteColor.java @@ -15,9 +15,9 @@ public class ParsableNoteColor extends Parsable { public NoteColor parse(PPlayer pplayer, List inputs) { String input = inputs.remove(0); if (input.equalsIgnoreCase("rainbow")) { - return new NoteColor(99); + return NoteColor.RAINBOW; } else if (input.equalsIgnoreCase("random")) { - return new NoteColor(98); + return NoteColor.RANDOM; } int note = Integer.parseInt(input); diff --git a/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableOrdinaryColor.java b/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableOrdinaryColor.java index 7da35c8..84286cd 100644 --- a/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableOrdinaryColor.java +++ b/src/main/java/dev/esophose/playerparticles/util/inputparser/parsable/ParsableOrdinaryColor.java @@ -31,8 +31,8 @@ public class ParsableOrdinaryColor extends Parsable { this.put("gray", new OrdinaryColor(128, 128, 128)); this.put("light_gray", new OrdinaryColor(192, 192, 192)); this.put("white", new OrdinaryColor(255, 255, 255)); - this.put("rainbow", new OrdinaryColor(999, 999, 999)); - this.put("random", new OrdinaryColor(998, 998, 998)); + this.put("rainbow", OrdinaryColor.RAINBOW); + this.put("random", OrdinaryColor.RANDOM); }}; }