[Util] FireworkEffectPlayer v1.0

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

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

    Rprrr

  2. Offline

    mastermustard

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

    chaseoes

    Sure it is. Wanna fight?

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

    Rprrr

    chaseoes
    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

    codename_B

    Bro, do you even catch?
     
  8. Offline

    Qwahchees

    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

    codename_B

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

    funkiben

    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.

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    if(cmd.getName().equalsIgnoreCase("spawnfirework")){ 
    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
     
     
    returntrue;
    } else {
    getLogger().info("You must be a player to do this command!");
    }
    }
    returnfalse; 
    }
     
    
     
  11. Offline

    codename_B

    Bro, do you even catch?
     
  12. Offline

    Qwahchees


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

    Lemme pop my code info ya.

    PHP:
    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

    teunie75

    Wrote some extra things, like totally random fireworks:
    Code:
    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;
    }else
    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;
    }else
    return Color.RED;
    }
     
    //Simple random boolean
    public static boolean randomBoolean(){
    double random3 = newrandom.nextDouble()*8;
    if(random3 <= 4){
    return false;
    }else
    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){
    e.printStackTrace();
    }
    }
     
    //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

    codename_B

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

    Ultimate_n00b

    This looked cool, so I tried it out with some of the code on the forums, but no luck. What is wrong with this?:
    Code:java
    1. package me.ultimate;
    2.  
    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;
    7.  
    8. public final class Circle extends JavaPlugin {
    9.  
    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

    chasechocolate

    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

    Ultimate_n00b

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

    Kainzo

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

    codename_B

    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.


    Seconded.
     
  22. Offline

    codename_B

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

    Jalau

    Hi, I'm new to Java and want to use your Util, but it throws one evil Error on me in eclipse:
    Code:
    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:

    Code:
    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

    ftbastler

    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

    teunie75

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

    AstramG

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

    Rocketboy901

    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

    Ultimate_n00b

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

    AstramG

    Any help with this?
     
  30. Offline

    Rockett8855

    chasechocolate
    Code:java
    1.  
    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. }
    16.  


    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