Launch firework

Discussion in 'Plugin Development' started by Jake6177, Oct 25, 2013.

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

    Jake6177

    I have an onPlayerInteract listener currently listening for left clicking of the air w/ a stick. What I want it to do when they do this is launch a firework in the air (or forward if possible, like a wand).

    Is this possible? How can I do it? This is my listener code:
    Code:java
    1. @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=false)
    2. public void onPlayerInteract(PlayerInteractEvent e) {
    3. if (e.getAction() == Action.RIGHT_CLICK_AIR && e.getMaterial() == Material.STICK) {
    4. Player player = (Player) e.getPlayer();
    5. player.sendMessage(ChatColor.GOLD + "You triggered the event! Yay!");
    6. }
    7. else {
    8. e.setCancelled(true);
    9. }
    10. }
     
  2. Offline

    xTrollxDudex

    Jake6177
    PHP:
    public void launchFirework(Player pint speed) {
        
    Firework fw = (Fireworkp.getWorld().spawn(p.getEyeLocation(), Firework.class);
        
    FireworkMeta meta fw.getFireworkMeta();
        
    //use meta to customize the firework or add parameters to the method
        
    fw.setVelocity(p.getLocation().getDirection().multiply(speed);
        
    //speed is how fast the firework flies
    }

    //use like so:
    launchFirework(e.getPlayer(), 69/*random number I thought of first*/);
    Also, your cast to player in the player field is really redundant.
     
  3. Offline

    Jake6177

    Yes...I suppose it is, isn't it...Thanks, lol.

    Also, thanks for that code! Where did you find it, if I may ask?
     
  4. Offline

    xTrollxDudex

  5. Offline

    whitebradcam

    You forgot to add a ) after (speed)
    Code:java
    1. Firework fw = (Firework) p.getWorld().spawn(p.getEyeLocation(), Firework.class);
    2. FireworkMeta meta = fw.getFireworkMeta();
    3. //use meta to customize the firework or add parameters to the method
    4. fw.setVelocity(p.getLocation().getDirection().multiply(speed));
    5. //speed is how fast the firework flies
    6. }
    7.  
    8. //use like so:
    9. launchFirework(e.getPlayer(), 69/*random number I thought of first*/);

    :b
     
  6. Offline

    xTrollxDudex

    .
    ... This is a year old. You can tell me in a PM or something, but you don't have to bump a thread to tell me of a syntax error, most logical people can figure that out.
     
    AoH_Ruthless likes this.
Thread Status:
Not open for further replies.

Share This Page