how to make a firework spawn instantly spigot code example

Example: spigot spawn firework

public static void spawnFireworks(Location location, int amount) {
   Location loc = location;
   Firework fw = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
   FireworkMeta fwm = fw.getFireworkMeta();

  fwm.setPower(2);
  fwm.addEffect(FireworkEffect.builder().withColor(Color.LIME).flicker(true).build());

  fw.setFireworkMeta(fwm);
  fw.detonate();

  for(int i = 0;i<amount; i++){
    Firework fw2 = (Firework) loc.getWorld().spawnEntity(loc, EntityType.FIREWORK);
    fw2.setFireworkMeta(fwm);
  }
}

Tags:

Java Example