-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] Firework: Add the ability to specify HEX #102
Comments
I see that in 4.60.1 only the RGB parameter was added. Since I couldn't wait long, I had to write these parameters myself. BUT I'm not sure if they are correct, because I don't know Java. public static void firework(Player player, String actionLine, ConditionalEvents plugin) {
// firework: colors:<color1>,<color2> type:<type> fade:<color1>,<color2> power:<power> location(optional):<x>;<y>;<z>;<world> trail:<true/false> flicker:<true/false>
ArrayList < Color > colors = new ArrayList < Color > ();
FireworkEffect.Type type = null;
ArrayList < Color > fadeColors = new ArrayList < Color > ();
Location location = null;
int power = 0;
boolean trail = false;
boolean flicker = false;
String[] sep = actionLine.split(" ");
for (String s: sep) {
if (s.startsWith("colors:")) {
s = s.replace("colors:", "");
String[] colorsSep = s.split(",");
for (String colorSep: colorsSep) {
colors.add(parseColor(colorSep));
}
} else if (s.startsWith("type:")) {
s = s.replace("type:", "");
type = FireworkEffect.Type.valueOf(s);
} else if (s.startsWith("fade:")) {
s = s.replace("fade:", "");
String[] colorsSep = s.split(",");
for (String colorSep: colorsSep) {
fadeColors.add(parseColor(colorSep));
}
} else if (s.startsWith("power:")) {
s = s.replace("power:", "");
power = Integer.valueOf(s);
} else if (s.startsWith("location:")) {
String[] sep2 = s.replace("location:", "").split(";");
location = new Location(
Bukkit.getWorld(sep2[3]), Double.parseDouble(sep2[0]), Double.parseDouble(sep2[1]), Double.parseDouble(sep2[2])
);
} else if (s.startsWith("trail:")) {
s = s.replace("trail:", "");
trail = Boolean.parseBoolean(s);
} else if (s.startsWith("flicker:")) {
s = s.replace("flicker:", "");
flicker = Boolean.parseBoolean(s);
}
}
if (location == null) {
location = player.getLocation();
}
ServerVersion serverVersion = ConditionalEvents.serverVersion;
EntityType entityType = null;
if (serverVersion.serverVersionGreaterEqualThan(serverVersion, ServerVersion.v1_20_R4)) {
entityType = EntityType.FIREWORK_ROCKET;
} else {
entityType = EntityType.valueOf("FIREWORK");
}
Firework firework = (Firework) location.getWorld().spawnEntity(location, entityType);
FireworkMeta fireworkMeta = firework.getFireworkMeta();
FireworkEffect effect = FireworkEffect.builder()
.flicker(flicker)
.trail(trail)
.withColor(colors)
.with(type)
.withFade(fadeColors)
.build();
fireworkMeta.addEffect(effect);
fireworkMeta.setPower(power);
firework.setFireworkMeta(fireworkMeta);
firework.setMetadata("conditionalevents", new FixedMetadataValue(plugin, "no_damage"));
}
private static Color parseColor(String input) {
if (input.startsWith("#")) {
// HEX color
try {
int rgb = Integer.parseInt(input.substring(1), 16);
return Color.fromRGB((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("Invalid HEX color format: " + input);
}
} else {
// Normal color name
return OtherUtils.getFireworkColorFromName(input);
}
} But in fact, the result with the color change turned out to be cool. And with an added parameter, without which it would not have been possible to do it. |
Which one is the shot at angle parameter? |
Hello. I would like to specify not only the values from spigot but also my own HEX colors.
Because specifying like this
colors:WHITE,FUCHSIA,AQUA
, is not very convenient and the variability is not very presentable.Thank you!
The text was updated successfully, but these errors were encountered: