[Util] FireworkEffectPlayer v1.0

Discussion in 'Resources' started by codename_B, Dec 30, 2012.

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


  2. Offline


    by turning off your speakers....
  3. Offline


    Sure it is. Wanna fight?

    You block the packet sent to the client telling it to play that sound. ;)
    silthus likes this.
  4. Offline


    Eh.. didn't realise that. So.. how would you go about doing that? I took a look at the packets, but couldn't find out what packet I'd be using and how you'd even block a packet.

    e: It's not possible, I was right. :p
  5. I like this purely because of the way you avoided directly referencing NMS or OBC. I'll try move some of my plugins that use reflection over to this method. Thanks!
  6. Thanks :)
    Rprrr http://dev.bukkit.org/server-mods/protocollib/

    // EDIT: I looked into the protocols sent by the server when a fireworks is triggered, but it does not seem to fire a named sound effect.
    Instead it sends the player a vehicle spawn packet with the entity ID of the firework and some meta data and velocity how it looks.
    As far as I can tell, the sound is played purely on the client side and the server never sends sound.
  7. Offline


    Bro, do you even catch?
  8. Offline


    I don't wanna bump an old thread, but doing this, I can't run the firework effect :l

    Edit: Nevermind, was being stupid.
  9. Offline


    Hey no need to worry, this thread is still relevant as there is no API for this yet.
    Qwahchees likes this.
  10. Offline


    Im new to java and bukkit apis and all that so this might have a stupid error in it.
    But when i tried using this i got an "Unhandled exception Type Exception" underlining the whole piece of code that is supposed to create the firework.

    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if (sender instanceof Player){
    Player player = (Player)sender;
    fplayer.playFirework(player.getWorld(), player.getLocation(), FireworkEffect.builder().with(Type.BURST).withColor(Color.BLACK).build()); \\This is the part thats erroring
    } else {
    getLogger().info("You must be a player to do this command!");
  11. Offline


    Bro, do you even catch?
  12. Offline


    You have to use a try { statement, and then catch any exceptions.

    Lemme pop my code info ya.

    FireworkHandler fplayer = new FireworkHandler();
                    try {
    fplayer.playFirework(ent.getWorld(), entlocfx);
                    } catch (
    Exception exc) {
    Also, create an object.

    I enjoy your "bro do you even catch" hint. Heh, helped me actually :p

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: May 30, 2016
    codename_B likes this.
  13. why not make a pull request to include this into craftbukkit?
    Hanii Puppy and teunie75 like this.
  14. Offline


    Wrote some extra things, like totally random fireworks:
    package nl.teun.willems.firework;
    import java.util.Random;
    import org.bukkit.Color;
    import org.bukkit.FireworkEffect;
    import org.bukkit.Location;
    import org.bukkit.FireworkEffect.Type;
    public class FireworkSettings {
    //A random for colors, types and booleans coming
    static Random newrandom = new Random();
    //Getting the playerclass
    FireworkEffectPlayer fplayer = new FireworkEffectPlayer();
    //Making a random fireworkType
    public static Type randomType(){
    //Getting the double and use NextDouble() so you get a new number
    double random1 = newrandom.nextDouble()*10;
    //The number goes from 0 to 10, if the number is 2 give Ball with 2/4 give Burst etc.
    if(random1 < 2){
    return Type.BALL;
    }else if(random1 >= 2 && random1 < 4){
    return Type.BURST;
    }else if(random1 >= 4 && random1 < 6){
    return Type.CREEPER;
    }else if(random1 >= 6 && random1 < 8){
    return Type.STAR;
    return Type.BALL_LARGE;
    //Random Colors, I only used the ones from Minecraft
    public static Color randomColor(){
    //The same as with the types but then with colors
    double random2 = newrandom.nextDouble()*8;
    if(random2 < 1){
    return Color.WHITE;
    }else if(random2 >= 1 && random2 < 2){
    return Color.ORANGE;
    }else if(random2 >=2 && random2 < 3){
    return Color.BLUE;
    }else if(random2 >= 3 && random2 < 4){
    return Color.YELLOW;
    }else if(random2 >= 4 && random2 < 5){
    return Color.GREEN;
    }else if(random2 >= 5 && random2 < 6){
    return Color.GRAY;
    }else if(random2 >= 6 && random2 < 7){
    return Color.PURPLE;
    return Color.RED;
    //Simple random boolean
    public static boolean randomBoolean(){
    double random3 = newrandom.nextDouble()*8;
    if(random3 <= 4){
    return false;
    return true;
    //FireworkEffectPlayer but then shorter, this more clearer view
    public void playFw(Location location, FireworkEffect fwEffect){
    try { fplayer.playFirework(location.getWorld(), location, fwEffect);
    }catch (Exception e){
    //A random fireworkeffect with everything in it
    public FireworkEffect randomFireworkEffect(){
    return FireworkEffect.builder().with(randomType()).withColor(randomColor()).withFade(randomColor()).trail(randomBoolean()).flicker(randomBoolean()).build();
  15. Offline


    You could do that in far fewer lines :)
  16. Offline


    This looked cool, so I tried it out with some of the code on the forums, but no luck. What is wrong with this?:
    1. package me.ultimate;
    3. import org.bukkit.entity.Player;
    4. import org.bukkit.event.EventHandler;
    5. import org.bukkit.event.player.PlayerLoginEvent;
    6. import org.bukkit.plugin.java.JavaPlugin;
    8. public final class Circle extends JavaPlugin {
    10. @EventHandler
    11. public void onPlayerLogin(PlayerLoginEvent event) {
    12. Player player = event.getPlayer();
    13. try {
    14. ((FireworkEffectPlayer) player).playFirework(event.getPlayer().getWorld(), event.getPlayer().getLocation(), FireworkEffectPlayer.getRandomEffect());
    15. } catch (Exception e) {
    16. getLogger().info("ERROR! ERROR!");
    17. e.printStackTrace();
    18. }
    19. }
    20. }
  17. Offline


    Ultimate_n00b you are casting player to FireworkEffectPlayer. FireworkEffectPlayer has no affiliation with the Player object, it just is supposed to "play" firework effects. Check the "example use" code on the OP.
  18. Offline


    xD I thought it was supposed to spawn a firework at a player. Okay, I got this now, thanks.
  19. Offline


    Just wanted to say CodenameB rocks for putting this in :p
    Ultimate_n00b likes this.
  20. Offline


    You're a babe Kainzo @D
  21. This class is perfect <3 but there's a small problem; it seems that occasionally when I call it, no firework goes off, and it seems to consistently happen with the first call to the method when I start my test server.

    I feel like I'm doing something wrong, but I've literally only copy+pasted it into my project, and call it from a static method. I've wrapped the method call in try-catch which prints exceptions to the console, but I'm not getting anything when I have the method called and nothing happens.

  22. Offline


    It's entirely possible that it's a client issue (I've experienced that before)
  23. Offline


    Hi, I'm new to Java and want to use your Util, but it throws one evil Error on me in eclipse:
    fplayer.playFirework(e.getPlayer().getWorld(), e.getPlayer().getLocation(), FireworkEffectPlayer.getRandomFireworkEffect());
    --> The method getRandomFireworkEffect() is undefined for the type FireworkEffectPlayer
    So do i need to create my own method for this?
    If i now paste in this in the FireworkEffectPlayer.java:

    public static void getRandomEffect() {
    return FireworkEffect.builder().withType(Type.BALL).withColor(Color.RED).build();
    This Error returns:
    The method withType(FireworkEffect.Type) is undefined for the type FireworkEffect.Builder
    If i fix the withType to: with(Type.BALL)
    This happens:
    Void methods cannot return a value
    Please help me :) Thanks!
  24. Offline


    I tried to use the method of Rprrr to get the locations in a circle, but now there is a problem. I see the fireworks (not the effects) spawning at the right places, but the effects all go off at one place. What am I doing wrong? codename_B
  25. Offline


    You are returning a firework object with a void method, voids don't return anything.
    Use public FireworkEffect instead.
  26. Offline


    Does anyone have an example of just spawning a red firework at a certain location I'm pretty confused with this :p
  27. Offline


    Not possible, sorry :( Technically you could make a sound louder than the firework noise, but you would still hear the firework.

    I get BALL cannot be resolved or is not a field and Linebreakpoint at line 6 and 9 - getRandomEffect();

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


    Is this on your under 50 line page? Removed all the comments and left reasonable blank lines, 47 lines.
  29. Offline


    Any help with this?
  30. Offline


    2. Player p;
    3. double xcenter = p.getLocation().getBlockX();
    4. double zcenter = p.getLocation().getBlockZ();
    5. double y = p.getLocation().getY();
    6. int radius = 9; //radius of circle from player
    7. //cycle through every degree on a circle
    8. for(int i=0; i<=360; i++){
    9. //cosine function is the x
    10. double tempx = (radius*Math.cos(i))+xcenter;
    11. //sine function is the z
    12. double tempz = (radius*Math.sin(i))+zcenter;
    13. Location loc = new Location(p.getWorld(),tempx,y,tempz);
    14. //do something with this location i.e. play firework
    15. }

    I just made this today to make a circle of stone around a player with a variable radius, you could probably do something with it using fireworks
Thread Status:
Not open for further replies.

Share This Page