Remove magic values for rainbow/random colors

This commit is contained in:
Esophose 2020-02-01 17:22:32 -07:00
parent 882c55b28b
commit c0f6e75e79
5 changed files with 58 additions and 22 deletions

View file

@ -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);

View file

@ -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);
}
}
/**

View file

@ -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();

View file

@ -15,9 +15,9 @@ public class ParsableNoteColor extends Parsable<NoteColor> {
public NoteColor parse(PPlayer pplayer, List<String> 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);

View file

@ -31,8 +31,8 @@ public class ParsableOrdinaryColor extends Parsable<OrdinaryColor> {
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);
}};
}