[Util] FireworkEffectPlayer V2.0 [No NMS or Reflection Needed]

Discussion in 'Resources' started by DevRosemberg, Jan 5, 2014.

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

    DevRosemberg

    Hello Everyone, i have found a way to create the Explosion of a Firework without using NMS or Reflection. There is a Version with only colors and one with full FireworkEffect.

    The Colored version:

    Code:java
    1. public void playFirework(Location location, Color color) {
    2. Firework firework = location.getWorld().spawn(location, Firework.class);
    3. FireworkMeta fMeta = firework.getFireworkMeta();
    4. fMeta.addEffect(FireworkEffect.builder().withColor(color).build());
    5. firework.setFireworkMeta(fMeta);
    6. firework.detonate();
    7. }


    And the full FireworkEffect Version:

    Code:java
    1. public void playFirework(Location location, FireworkEffect effect) {
    2. Firework firework = location.getWorld().spawn(location, Firework.class);
    3. FireworkMeta fMeta = firework.getFireworkMeta();
    4. fMeta.addEffect(effect);
    5. firework.setFireworkMeta(fMeta);
    6. new BukkitRunnable() {
    7. @Override
    8. public void run() {
    9. firework.detonate();
    10. }
    11. }.runTaskLater(plugin, 1);
    12. }


    Thanks to Ultimate_n00b for the second version of it.

    With this code you wont need FireworkEffect or Worlds, you just need to Specify the location and the color that you want for it and done. An example usage of this can be:

    Code:java
    1. @EventHandler
    2. public void onPlayerJoin(PlayerJoinEvent event) {
    3. playFirework(event.getPlayer().getLocation(), Color.AQUA);
    4. }


    Hope you like it and i look forward to seeing Games and Plugins with this, you should also check out codename_B 's Version of this as it is awsome aswell.

    Regards.
     
    Plo124 and chasechocolate like this.
  2. Offline

    HeavyMine13

  3. Offline

    macguy8

    HeavyMine13 No, this is far better. Codename_b's uses reflection which is clunky and slow, whereas this uses an inbuilt Bukkit method with is much more efficient.
     
  4. Offline

    bigteddy98

    The problem of this is that you will see the ignition and you will hear the sound of the ignition. But ofcourse, this is also possible.
     
  5. Offline

    macguy8

    bigteddy98 You'll see the ignition in the original library as well for a small amount of time, but the sound is a problem. However, something like protocol lib or such could solve that if it's a huge deal to people.
     
  6. Offline

    RentAMonkey

    DevRosemberg
    You should probably update it, so you can also set the type of the firework.
     
  7. Offline

    DevRosemberg

    RentAMonkey Yes i was thinking of doing that and i will in some minutes.
     
  8. Offline

    Ultimate_n00b

    Code:java
    1. public void playFirework(Location location, FireworkEffect effect) {
    2. Firework firework = location.getWorld().spawn(location, Firework.class);
    3. FireworkMeta fMeta = firework.getFireworkMeta();
    4. fMeta.addEffect(effect);
    5. firework.setFireworkMeta(fMeta);
    6. new BukkitRunnable() {
    7. @Override
    8. public void run() {
    9. firework.detonate();
    10. }
    11. }.runTaskLater(plugin, 1);
    12. }


    Someone asked for a version where you could control the firework.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  9. Offline

    DevRosemberg

    Ultimate_n00b Yeah relised that after reading FireworkEffect, thanks a lot for it, i didnt manage to write it as it failed quite a bunch of times. Added it and gave you credit in the main post.
     
  10. Offline

    macguy8

    Ultimate_n00b There's no need to wait 1 tick - All you'd do is make the small delay you do see the firework launching for longer.
     
  11. Offline

    Ultimate_n00b

    You actually don't see anything else.
     
  12. Offline

    macguy8

    Ultimate_n00b You do based on server lag. Regardless, the client will always see a little bit of it. Even if I was wrong, your method would make a 1 tick delay instead of doing it in one tick which is A. More taxing on the server and B. Completely unneeded and C. Will let the client see some of the firework before it detonates.
     
    fromgate likes this.
  13. Offline

    DevRosemberg

  14. Offline

    DevRosemberg

    Any ideas on what else should i add?
     
  15. Offline

    fromgate

    detonate() method exploding new firework after one tick.
    You must set ticksFlown field of EntityFireworks to value exceeding the value of expectedLifespan (or equal) to detonate firework immediately. I used this in my plugin PlayEffect and it works nice.
     
  16. Offline

    LCastr0

    How can I change how many ticks it'll last in the air before detonating?
     
  17. Offline

    DevRosemberg

    LCastr0 Add a timer before the explosion and there put firework.detonate();
     
  18. Offline

    HungerCraftNL

    PHP:
    public void giveFireworkEffect(Location locationFireworkEffect effectColor color) {
        final 
    Firework firework location.getWorld().spawn(locationFirework.class);
        
    FireworkMeta fMeta firework.getFireworkMeta();
        
    fMeta.addEffect(effect);
        
    fMeta.addEffect(FireworkEffect.builder().withColor(color).build());
        
    firework.setFireworkMeta(fMeta);
        
    Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
            public 
    void run() {
                
    firework.detonate();
            }
        }, 
    1L);
    }
    This is what I use.
     
  19. Offline

    DevRosemberg

  20. Offline

    HungerCraftNL

    I know, but both in one. It's just an exemple.
     
  21. Offline

    DoctorDark

    DevRosemberg

    This is great. Is there a way to only broadcast the firework to a specific player however?

    Thanks.
     
  22. Offline

    Garris0n

    DoctorDark

    Create an EntityFireworks, set everything up (and send the spawn packet to the player), and then use a packetPlayOutEntityStatus with 17.

    https://github.com/Bukkit/CraftBukk...net/minecraft/server/EntityFireworks.java#L82
    https://github.com/Bukkit/CraftBukk...in/java/net/minecraft/server/WorldServer.java
    https://github.com/Bukkit/mc-dev/blob/master/net/minecraft/server/PacketPlayOutEntityStatus.java

    Edit: I don't know why I just (loosely) explained that, it occurs to me that the predecessor to this Util is one that did exactly what you asked.
     
    DarkBladee12 likes this.
  23. Offline

    Iroh

    Removed linking of another resource.

    If you believe there is a problem with a resource suggest improvements. Do not link to your own resource saying that it is better. Resources are unique and belong in their own threads.
     
    xTigerRebornx likes this.
  24. Offline

    NerdsWBNerds

    DevRosemberg There is a simpler way of also playing the effect (with no sound, which is what a lot of people are looking for) which is explained in my Lib.

    I understand what you're saying, but also, understand what I'm saying. I looked all over for what my resource did, and didn't find it, but among the posts I did find was this one. So knowing that people looking for mine, would stumble across this, I thought it would be helpful to post mine so that if people were looking for my resource , they would be able to use it. I'd like to point out that mine and his do two different (similar, but different) things. I'm not just posting a link here to get popular, I'm posting a link here to allow people who are looking for what my resource does, to be able to find my resource .

    I was never suggesting something was wrong with this resource . This resource does exactly what it was made to do. My resource is similar, and thus people looking for what mine does often end up here. I am simply trying to help those people, and save them time. If this resource is what people are looking for, then they'll stay with this resource, and not use mine.

    As fromgate said, in the post you oh so graciously deleted, him being tagged in this allowed him to find my recourse, which is what he was looking for when he came across this one.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page