Ok so I'm having a small issue here. When you right click a enderpearl it sets the player and rides the pearl. However, after about 1 - 2 seconds the player hits the enderpearl and the pearl gets deleted. Is their a way to make it so this doesn't happen or just make the player move a little slower? Code: Code:java @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile proj = event.getEntity(); if (proj instanceof EnderPearl) { EnderPearl pearl = (EnderPearl)proj; @SuppressWarnings("deprecation") ProjectileSource source = pearl.getShooter(); if (source instanceof Player) { Player player = (Player)source; pearl.setPassenger(player); } } }
Coopah I recommend removing the enderpearl and, either spawning a falling block with a velocity, or just setting the player velocity to the direction the player is looking.
IvanTheForth If I set the players velocity wouldn't it just go in one direction not like a enderpearl? Isn't there a method if the shooter collides with the ender pearl?
Code:java pearl.setShooter(source); Add that line ^^ under Code:java ProjectileSource source = pearl.getShooter();
Captain Dory Now nothing happens? Code: Code:java @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile proj = event.getEntity(); if (proj instanceof EnderPearl) { EnderPearl pearl = (EnderPearl)proj; @SuppressWarnings("deprecation") ProjectileSource source = pearl.getShooter(); pearl.setShooter(source); if (source instanceof Player) { Player player = (Player)source; pearl.setPassenger(player); } } } Anyone? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
Oh, try this under your player variable: Code: pearl.setShooter(player); You can remove the other setShooter method :3
Captain Dory Still nothing happens? Code: Code:java @SuppressWarnings("deprecation") @EventHandler public void onProjectileLaunch(ProjectileLaunchEvent event) { Projectile proj = event.getEntity(); if (proj instanceof EnderPearl) { EnderPearl pearl = (EnderPearl)proj; @SuppressWarnings("deprecation") ProjectileSource source = pearl.getShooter(); if (source instanceof Player) { Player player = (Player)source; pearl.setShooter(player); } } }
Try this code: PHP: @EventHandler public void onLaunch(ProjectileLaunchEvent e) { if (!(e.getEntity().getShooter() instanceof Player) && !(e.getEntity() instanceof EnderPearl)) return; e.getEntity().setPassenger((Player) e.getEntity().getShooter()); }
Captain Dory Code:java package Pearls; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Server;import org.bukkit.command.ConsoleCommandSender;import org.bukkit.entity.EnderPearl;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.entity.ProjectileLaunchEvent;import org.bukkit.plugin.java.JavaPlugin; public class EnderPearls extends JavaPlugin implements Listener { public void onEnable() {Server server = Bukkit.getServer();ConsoleCommandSender console = server.getConsoleSender();console.sendMessage(ChatColor.BLUE + "Legacy Prison> " + ChatColor.GREEN + "Enabling " + ChatColor.LIGHT_PURPLE + "Legacy Prison Pearls! " + ChatColor.DARK_AQUA + "Made by Coopah.");getServer().getPluginManager().registerEvents(this, this);//getCommand("list").setExecutor(new Commands()); } public void onDisable() {Server server = Bukkit.getServer();ConsoleCommandSender console = server.getConsoleSender();console.sendMessage(ChatColor.BLUE + "Legacy Prison> " + ChatColor.GREEN + "Disabling " + ChatColor.LIGHT_PURPLE + "Legacy Prison Pearls");} @SuppressWarnings("deprecation")@EventHandlerpublic void onLaunch(ProjectileLaunchEvent e) { if (!(e.getEntity().getShooter() instanceof Player) && !(e.getEntity() instanceof EnderPearl)) return; e.getEntity().setPassenger((Player) e.getEntity().getShooter()); } }
May I ask what you're using this for? There may be another way. EDIT: Like the actual purpose of why the player needs to ride the enderpearl.
Coopah Coopah, just cancel the enderpearl and set the player velocity to the direction they are looking. That will get you what you want.
IvanTheForth Nonono, I want to make it so it looks like they're actually riding it. Bump EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I know what you could do/try. Cancel the ProjectileHitEvent after checking it is an EnderPearl because the reason it breaks blah blah is because setting the player as a passenger teleports the player to the pearls location so the pearl hits the player and the ender pearls effect takes place, cancel it.
Code:java @EventHandlerpublic void onHitEvent(PlayerTeleportEvent e){ if(e.getCause() == TeleportCause.ENDER_PEARL){ e.setCancelled(true); }} I got it wrong it wasn't ProjectileHitEvent. I meant PlayerTeleportEvent sorry about that. Also this code will stop anyone from using ender pearls to teleport so if you only want it for people that are riding one add their names to an ArrayList then check in the teleport event if they are in the ArrayList use that code and then remove them.