Skip to content
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

Open
JuraRusan opened this issue Dec 20, 2024 · 5 comments
Open

[Feature Request] Firework: Add the ability to specify HEX #102

JuraRusan opened this issue Dec 20, 2024 · 5 comments

Comments

@JuraRusan
Copy link

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!

@JuraRusan
Copy link
Author

I'm currently working on New Year's fireworks and I noticed that some components are missing.
has_trail:
has_twinkle:
ShotAtAngle: & Motion:

It would be great to have some more parameters.
image

Thanks!

@JuraRusan
Copy link
Author

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.
https://youtu.be/S_V862eFVz4

@Ajneb97
Copy link
Owner

Ajneb97 commented Jan 19, 2025

Which one is the shot at angle parameter?

@JuraRusan
Copy link
Author

If we are talking about these shots, then they were made using this command
Image

To be more precise, the parameters ShotAtAngle: & Motion:. I couldn't figure out how to add them because I don’t have much knowledge, so I just used a console command.

- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,1.125d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;5636095]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,1.125d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;5636095]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,2.25d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;9364394]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,2.25d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;9364394]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,3.375d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;13026901]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,3.375d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;13026901]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,4.5d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;16755200]}]}}}}'
- 'console_command: minecraft:summon firework_rocket -765.5 66.2 312.5 {shotAtAngle:1b,Motion:[0d,4.5d,0d],FireworksItem:{id:firework_rocket,components:{fireworks:{explosions:[{has_twinkle:1b,has_trail:1b,shape:burst,colors:[I;16755200]}]}}}}'

@JuraRusan
Copy link
Author

The whole show fit into so many lines that I was very surprised, but the plugin did not create any delays. Everything was perfect.

Image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants