Solved Spawn firework particles

Discussion in 'Plugin Development' started by teunie75, Mar 23, 2013.

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

    teunie75

    I'm trying to spawn firework particles on a world, on a location.
    Therefore I want to use the location of an fireball, so fireball.getLocation() I guess.

    I saw a topic explaining this, but it doesn't seem to work in 1.5, because the import changed and I can't find it.
    Also I didn't get the chance of testing out that code because I was already programming with the dev. build of CraftBukkit.

    Can anyone think of an solution for this?

    The code I used after reading to thread:
    Code:
    Firework firework = player.getWorld().spawn(fireball.getLocation(), Firework.class);
    ((CraftWorld) fireball.getWorld()).getHandle().broadcastEntityEffect(
                  ((CraftFirework)firework).getHandle(),
                  (byte)17);
    
    Click here for the original topic
     
  2. Offline

    teunie75

  3. So whats your problem? I thought the code you showed didn't work in 1.5 and the version I showed you uses reflection and should still work.
     
  4. Offline

    teunie75

    The problem is I still don't get how to do it after reading that topic.
     
  5. You simply call the
    playFirework(World world, Location loc, FireworkEffect fe)
    method with the parameters you want (catch the exception ofc).
     
  6. Offline

    teunie75

    Can you tell me what to put at fe
    I tried this:
    Code:
    try{
    fw.playFirework(loc, loc, FireworkEffect.Type.BALL);
    }catch(Exception e){
    e.printStackTrace();
    }
    
     
  7. Use a constuctor for a new FireworkEffect.
     
  8. Offline

    teunie75

    Can you give an example, I'm still not that good in this.
     
  9. The Constructor summary is : boolean, boolean, ImmutableList<Color>, ImmutableList<Color> ,FireworkEffect.Type
    Github seems to have an issue for me so I can't see what the datatypes mean, check for yourself here (if github works for you):
    https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/FireworkEffect.java


    Edit: Works now, booleans: flicker and trail Colorlists: color and fadecolor Type is the type
     
  10. Offline

    teunie75

    mncat77
    Getting an error:
    Code:
    2013-03-24 00:15:41 [SEVERE] java.lang.NullPointerException
    2013-03-24 00:15:41 [SEVERE]    at nl.teun.willems.empire.wandListener.onBlazerodClick(wandListener.java:37)
    2013-03-24 00:15:41 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    2013-03-24 00:15:41 [SEVERE]    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    2013-03-24 00:15:41 [SEVERE]    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    2013-03-24 00:15:41 [SEVERE]    at java.lang.reflect.Method.invoke(Unknown Source)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:181)
    2013-03-24 00:15:41 [SEVERE]    at org.bukkit.craftbukkit.v1_5_R2.event.CraftEventFactory.callPlayerInteractEvent(CraftEventFactory.java:151)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.a(PlayerConnection.java:1006)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.Packet18ArmAnimation.handle(SourceFile:41)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.NetworkManager.b(NetworkManager.java:292)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.PlayerConnection.d(PlayerConnection.java:113)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.ServerConnection.b(SourceFile:35)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.DedicatedServerConnection.b(SourceFile:30)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.r(MinecraftServer.java:580)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.DedicatedServer.r(DedicatedServer.java:225)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.q(MinecraftServer.java:476)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.MinecraftServer.run(MinecraftServer.java:409)
    2013-03-24 00:15:41 [SEVERE]    at net.minecraft.server.v1_5_R2.ThreadServerApplication.run(SourceFile:573)
    With this eventlistener:
    Code:
    public wandListener(Main plugin) {
    this.plugin = plugin;
    }
    public wandListener(FireworkEffectPlayer fw){
    this.fw = fw;
    }
     
     
    @EventHandler(priority = EventPriority.NORMAL)
    public void onBlazerodClick(PlayerInteractEvent event){
    Player player = event.getPlayer();
    if(plugin.effectnum.contains(player.getName()) && player.getItemInHand().getTypeId() == 369){
    World loc = player.getLocation().getWorld();
    Location target = player.getTargetBlock(null, 999).getLocation();
    int k = 6;
    for(;k > 0; --k){
    player.getLocation().setX(player.getLocation().getX() + 1);
    loc.strikeLightning(target);
    loc.createExplosion(target, 12F);
    try {
    fw.playFirework(loc, target, Fwe());
    } catch (Exception e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }
    }
    }
    public FireworkEffect Fwe(){
    return FireworkEffect.builder().with(Type.BALL).withColor(Color.RED).build();
     
    }
    }
    
    I still don't really get it, maybe you can give an example because I (mostly) learn better with that.

    BUMP

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

    teunie75

    ferrybig Already tried that, I used the FireworkEffectPlayer already before your answer.
     
  12. in that case, what is line wandListener.java:37
    EDIT: wait....
    Code:java
    1.  
    2. public wandListener(Main plugin) {
    3. this.plugin = plugin;
    4. }
    5. public wandListener(FireworkEffectPlayer fw){
    6. this.fw = fw;
    7. }
    8.  

    2 contructors???? they both set something else, that may be a bug....
     
  13. Offline

    teunie75

    Code:
    try {
    (this is line 37)              fw.playFirework(player.getWorld(), target, FireworkEffect.builder().withColor(Color.RED).flicker(true).with(Type.BURST).build());
                    } catch (Exception e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
    World loc = player.getLocation().getWorld();
    Location target = player.getTargetBlock(null, 40).getLocation();
    
    Someone? :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 31, 2016
  14. Test if fw is null, if it is thats your problem.
     
  15. Offline

    teunie75

    mncat77 Lol it is.
    Ill put the fireworkEffectPlayer in my main and get it from there, that seems to work for my Arraylist too.
    EDIT: Yes finally it works now!
    Thanks for the help everyone
     
  16. Offline

    Rprrr

    teunie75
    Empire Wand... seems familiar. :p
     
  17. Offline

    teunie75

    Just wanted to do the same (I'm not going to release a public plugin ;))
    I think you want your plugin to be private, so I'm going to leave it that way.
     
Thread Status:
Not open for further replies.

Share This Page