Solved Firework spawning (Quick, please!)

Discussion in 'Plugin Development' started by Limeth, Dec 31, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Limeth

    Hello, I'm trying to spawn a firework in the onCommand function using:

    Code:java
    1.  
    2. Location fireworkLoc = event.getClickedBlock().getRelative(event.getBlockFace()).getLocation();
    3. Firework firework = spawnFirework(fireworkLoc);
    4. FireworkMeta fMeta = firework.getFireworkMeta();
    5. Random rnd = new Random();
    6.  
    7. final List<Color> colour = new ArrayList<Color>();
    8. Collections.addAll(colour, Color.AQUA, Color.BLACK, Color.BLUE, Color.FUCHSIA, Color.GRAY, Color.GREEN, Color.LIME, Color.MAROON, Color.NAVY, Color.OLIVE, Color.ORANGE, Color.PURPLE, Color.RED, Color.SILVER, Color.TEAL, Color.WHITE, Color.YELLOW);
    9.  
    10. List<FireworkEffect> effectList = new ArrayList<FireworkEffect>();
    11. int amount = 1 + rnd.nextInt(3);
    12.  
    13. for(int i = amount; i < 3; i++) {
    14.  
    15. FireworkEffect.Type type = FireworkEffect.Type.values()[rnd.nextInt(5)];
    16.  
    17. List<Color> colorList = new ArrayList<Color>();
    18. int colorAmount = 1 + rnd.nextInt(3);
    19.  
    20. for(int j = colorAmount; j < 3; j++)
    21. colorList.add(colour.get(rnd.nextInt(17)));
    22.  
    23. List<Color> fadeList = new ArrayList<Color>();
    24. int fadeAmount = 1 + rnd.nextInt(3);
    25.  
    26. for(int k = fadeAmount; k < 3; k++)
    27. fadeList.add(colour.get(rnd.nextInt(17)));
    28. //This below is line #73.
    29. FireworkEffect curEffect = FireworkEffect.builder().flicker(rnd.nextBoolean()).trail(rnd.nextBoolean()).with(type).withColor(colorList).withFade(fadeList).build();
    30.  
    31. effectList.add(curEffect);
    32.  
    33. }
    34.  
    35. fMeta.addEffects(effectList);
    36. fMeta.setPower(1 + rnd.nextInt(3));
    37.  
    38. firework.setFireworkMeta(fMeta);
    39.  


    It is throwing me this error:

    Code:text
    1.  
    2. Caused by: java.lang.IllegalStateException: Cannot make FireworkEffect without any color
    3. at org.bukkit.FireworkEffect.<init>(FireworkEffect.java:300)
    4. at org.bukkit.FireworkEffect$Builder.build(FireworkEffect.java:275)
    5. at me.limeth.Rachejtle.onPlayerInteract(Rachejtle.java:73)
    6. at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
    7. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    8. at java.lang.reflect.Method.invoke(Method.java:601)
    9. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    10. ... 16 more
    11.  


    I know I shouln't bump so often, but it's year 2013 in 3.5 hours. I'd like to have it done in 30 minutes, so I can use it on my server. Would you mind helping me, please?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  2. Offline

    SchulziHD

    Add the colors with a loop. What you're adding is a List and not a single color. I thinks thats the error.
     
    Limeth likes this.
  3. Offline

    Limeth

    I looked at the loop and I noticed that I set it to : 0, 1, 2 colors.
    I changed "<" to "<=", it works perfectly! Thanks!
     
  4. Offline

    pasow

    wow, that was close...
     
    Limeth likes this.
Thread Status:
Not open for further replies.

Share This Page