EnderPearl

Discussion in 'Plugin Development' started by Coopah, Apr 19, 2014.

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

    Coopah

    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
    1. @EventHandler
    2. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    3. Projectile proj = event.getEntity();
    4. if (proj instanceof EnderPearl) {
    5. EnderPearl pearl = (EnderPearl)proj;
    6. @SuppressWarnings("deprecation")
    7. ProjectileSource source = pearl.getShooter();
    8. if (source instanceof Player) {
    9. Player player = (Player)source;
    10. pearl.setPassenger(player);
    11. }
    12. }
    13. }
     
  2. Offline

    IvanTheForth

    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.
     
  3. Offline

    Coopah

    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?
     
  4. Offline

    IvanTheForth

    Coopah
    Setting a players velocity to their direction would have almost the same result.
     
  5. Offline

    Captain Dory

    Code:java
    1. pearl.setShooter(source);

    Add that line ^^ under
    Code:java
    1. ProjectileSource source = pearl.getShooter();
     
  6. Offline

    Coopah

    Captain Dory
    Now nothing happens?
    Code:
    Code:java
    1. @EventHandler
    2. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    3. Projectile proj = event.getEntity();
    4. if (proj instanceof EnderPearl) {
    5. EnderPearl pearl = (EnderPearl)proj;
    6. @SuppressWarnings("deprecation")
    7. ProjectileSource source = pearl.getShooter();
    8. pearl.setShooter(source);
    9. if (source instanceof Player) {
    10. Player player = (Player)source;
    11. pearl.setPassenger(player);
    12. }
    13. }
    14. }


    Anyone?

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

    Captain Dory

    Oh, try this under your player variable:
    Code:
    pearl.setShooter(player);
    You can remove the other setShooter method :3
     
  8. Offline

    Coopah

    Captain Dory
    Still nothing happens?
    Code:
    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    4. Projectile proj = event.getEntity();
    5. if (proj instanceof EnderPearl) {
    6. EnderPearl pearl = (EnderPearl)proj;
    7. @SuppressWarnings("deprecation")
    8. ProjectileSource source = pearl.getShooter();
    9. if (source instanceof Player) {
    10. Player player = (Player)source;
    11. pearl.setShooter(player);
    12. }
    13. }
    14. }
     
  9. Offline

    Captain Dory

    Try this code:
    PHP:
    @EventHandler
        
    public void onLaunch(ProjectileLaunchEvent e) {
           
            if (!(
    e.getEntity().getShooter() instanceof Player) && !(e.getEntity() instanceof EnderPearl)) return;
           
            
    e.getEntity().setPassenger((Playere.getEntity().getShooter());
           
        }
     
  10. Offline

    Coopah

    Captain Dory
    Same error, you catch up to the ender pearl and it breaks.
     
  11. Offline

    Captain Dory

    Post your full class.
     
  12. Offline

    Coopah

    Captain Dory
    Code:java
    1. package Pearls;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.ChatColor;
    5. import org.bukkit.Server;
    6. import org.bukkit.command.ConsoleCommandSender;
    7. import org.bukkit.entity.EnderPearl;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.event.EventHandler;
    10. import org.bukkit.event.Listener;
    11. import org.bukkit.event.entity.ProjectileLaunchEvent;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14. public class EnderPearls extends JavaPlugin implements Listener {
    15.  
    16. public void onEnable() {
    17. Server server = Bukkit.getServer();
    18. ConsoleCommandSender console = server.getConsoleSender();
    19. console.sendMessage(ChatColor.BLUE + "Legacy Prison> " + ChatColor.GREEN + "Enabling " + ChatColor.LIGHT_PURPLE + "Legacy Prison Pearls! " + ChatColor.DARK_AQUA + "Made by Coopah.");
    20. getServer().getPluginManager().registerEvents(this, this);
    21. //getCommand("list").setExecutor(new Commands());
    22.  
    23. }
    24.  
    25. public void onDisable() {
    26. Server server = Bukkit.getServer();
    27. ConsoleCommandSender console = server.getConsoleSender();
    28. console.sendMessage(ChatColor.BLUE + "Legacy Prison> " + ChatColor.GREEN + "Disabling " + ChatColor.LIGHT_PURPLE + "Legacy Prison Pearls");
    29. }
    30.  
    31. @SuppressWarnings("deprecation")
    32. @EventHandler
    33. public void onLaunch(ProjectileLaunchEvent e) {
    34.  
    35. if (!(e.getEntity().getShooter() instanceof Player) && !(e.getEntity() instanceof EnderPearl)) return;
    36.  
    37. e.getEntity().setPassenger((Player) e.getEntity().getShooter());
    38.  
    39. }
    40.  
    41.  
    42. }
     
  13. Offline

    Captain Dory

    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.
     
  14. Offline

    Coopah

  15. Offline

    IvanTheForth

    Coopah
    Coopah, just cancel the enderpearl and set the player velocity to the direction they are looking. That will get you what you want.
     
  16. Offline

    Coopah

    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.
     
    Last edited by a moderator: Jun 7, 2016
  17. Offline

    itzrobotix

    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.
     
  18. Offline

    Coopah

    itzrobotix
    How would I do this?
    Instance of player, instance of entity?
     
  19. Offline

    itzrobotix

    Code:java
    1. @EventHandler
    2. public void onHitEvent(PlayerTeleportEvent e){
    3. if(e.getCause() == TeleportCause.ENDER_PEARL){
    4. e.setCancelled(true);
    5. }
    6. }

    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.
     
Thread Status:
Not open for further replies.

Share This Page