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 @EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=false) public void onPlayerInteract(PlayerInteractEvent e) { if (e.getAction() == Action.RIGHT_CLICK_AIR && e.getMaterial() == Material.STICK) { Player player = (Player) e.getPlayer(); player.sendMessage(ChatColor.GOLD + "You triggered the event! Yay!"); } else { e.setCancelled(true); } }
Jake6177 PHP: public void launchFirework(Player p, int speed) { Firework fw = (Firework) p.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.
Yes...I suppose it is, isn't it...Thanks, lol. Also, thanks for that code! Where did you find it, if I may ask?
You forgot to add a ) after (speed) Code:java Firework fw = (Firework) p.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*/); :b
. ... 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.