Riding an enderpearl...

Discussion in 'Plugin Development' started by Benpat9, Aug 16, 2014.

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

    Benpat9

    So basiacly ive got a small plugin which makes you ride an enderpearl if you throw it, and it works... kind of, what happens is when you throw it you start riding it but i think you actualy hit the enderpear in mid air meaning your thrown off does anyone know a solution?

    Code:java
    1. @EventHandler
    2. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    3. if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) {
    4. event.getEntity().setPassenger((Player)event.getEntity().getShooter());
    5. }
    6. }
    7. }
     
  2. Offline

    MasterDoctor

    Could you give us the rest of the snippet, i.e via bitbukkit?
     
  3. Offline

    Benpat9

    @MasterDoctor This is the entire class?

    Code:java
    1. package me.benpat9.enderbutt;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Material;
    6. import org.bukkit.entity.EnderPearl;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.entity.ProjectileLaunchEvent;
    11. import org.bukkit.event.player.PlayerJoinEvent;
    12. import org.bukkit.inventory.ItemStack;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public final class Main extends JavaPlugin implements Listener {
    16.  
    17. public static ArrayList<String> list = new ArrayList<String>();
    18.  
    19. @Override
    20. public void onEnable(){
    21. getServer().getPluginManager().registerEvents(this, this);
    22. getConfig().options().copyDefaults(true);
    23. saveConfig();
    24. }
    25. @Override
    26. public void onDisable() {
    27.  
    28. }
    29. @EventHandler
    30. public void JoinEvent(PlayerJoinEvent event) {
    31. Player player = (Player) event.getPlayer();
    32. player.getInventory().setItem(1, new ItemStack(Material.ENDER_PEARL, 32));
    33. }
    34. @SuppressWarnings("deprecation")
    35. @EventHandler
    36. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    37. if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) {
    38. event.getEntity().setPassenger((Player)event.getEntity().getShooter());
    39. }
    40. }
    41. }
     
  4. Offline

    DinosParkour

    Benpat9 I had encountered this problem before, I know what causes it but I never searched for a solution.
    This problem happens because when the projectile reaches its max Y value, and starts losing height, somehow the passenger gets below the projectile (bugz) so it dissapears.
     
  5. Offline

    Benpat9

    DinosParkour thnx, but i still dont know the solution, but basiacly you have to somehow keep the player above the enderpearl...
     
  6. Offline

    MasterDoctor

    Yes

    Benpat9 DinosParkour - So if you were able to get the enderpearl entity and teleport the player to say the enderpearl entity by (~, ~1, ~) or (~, ~2, ~) (one or two above the enderpearl for the y axis.)
    You could put that in a while loop until the player lands on the ground or until the entity is removed.

    I am not 100% sure on how to do this but you can ask me for a bit of help!

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

    Benpat9

  8. Offline

    qlimax5000

    Maybe have an entity that doesn't collide with enderpeals (like snowballs), make in invisible.
    Then make the player ride that.
     
  9. Offline

    DinosParkour

    Benpat9 try listening to entitydamagebyentity and if the damager is a projectile, re-spawn the projectile and set the event's entity to the passenger?
     
  10. Offline

    Benpat9

    DinosParkour wouldnt that mean the enderpearl would just drop because noone threw it...
     
  11. Offline

    DinosParkour

    Benpat9 no, it means if a projectile (like the enderpearl) hits a player (which is our problem in this case), it will re-spawn that projectile and make the player ride it again
     
  12. Offline

    stormneo7

    Won't work. How would you get the velocity of the projectile then? It'll just be falling down.
    Basically that won't work either.
    I've had experience with this kind of stuff, making a player ride an arrow etc.
    If you shoot the arrow upwards, it'll hit the player riding it, even thou, theortically, that's not possible.
    Minecraft has a strange feature, players in creative mode will are not affected.
    What I did was that I set the gamemode of everybody riding to creative and disallowed them to click their inventories.
    Not the best way but it's how I've done it. You might want to try it.
     
  13. Offline

    MasterDoctor

    An idea could be: Make a boolean for whether the EnderPearl Entity is still active; then in a while loop, put: while the boolean = true, teleport the player to the entity - if the entity breaks, make a new entity.
    You can teleport by doing
    Code:java
    1. player.teleport(Location);
     
  14. Offline

    Benpat9

    @SilentThief
    stormneo7

    this is what ive got but it still stoppes me and changes my gamemode...

    Code:java
    1. @SuppressWarnings("deprecation")
    2. @EventHandler
    3. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    4. Player shooter = (Player) event.getEntity().getShooter();
    5. if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) {
    6. shooter.setGameMode(GameMode.CREATIVE);
    7. event.getEntity().setPassenger((Player)event.getEntity().getShooter());
    8. }
    9. }
    10. @EventHandler
    11. public void onProjLand(ProjectileHitEvent event) {
    12. Player player = (Player) event.getEntity().getPassenger();
    13. player.setGameMode(GameMode.SURVIVAL);
    14. }
    15. }
     
  15. Offline

    SilentThief

    There is an issue with this.
    Teleporting to the Ender Pearl entity is going to be very glitchy. (Because you're probably teleporting every millisecond, which can cause stack overflows and lag) Especially if you throw multiple ender pearls, or if a bit of players are using the same /feature/.

    Also, teleporting to your ender pearl is possible, because Minecraft saves that kind of data, if it didn't, then if one person thew an ender pearl, everyone on the server would teleport to it. You can probably store this data in a hash map.

    On the topic of stopping a player from hitting the ender pearl stormneo7 has the right idea. I don't know if there's any other way of doing it. Unless you can take away the box collider for your player. :3
     
  16. Offline

    stormneo7

    Instead of the ProjectileHitEvent, make a PlayerMoveEvent or scheduler.
    1. Player could get off the vehicle by pressing "shift".
    2. Player could log out.
    3. Player could by teleported away.

    Use this code.
    Code:
    @EventHandler
    public void onMove(PlayerMoveEvent evt){
      if(evt.getPlayer().getVehicle() == null && evt.getPlayer().getGameMode() == GameMode.CREATIVE)
        evt.getPlayer().setGameMode(GameMode.SURVIVAL);
    }
    Edit: Also, since they threw the Enderperal, if they dismount it, the enderperal will still continue to go and it'll teleport the player that threw it when it lands.
    Listen to VehicleExitEvent (I think that's the event name), run your checks, and remove the enderperal if the vehicle was a EnderPeral using the .remove(); method after you've defined it as a entity.
     
  17. Offline

    Benpat9

    stormneo7 im still getting the same result although it doesnt change my gamemode until i start falling rather than instantly when i get dismounted.
     
  18. Offline

    stormneo7

    Code please.
     
  19. Offline

    Benpat9

    stormneo7 SilentThief MasterDoctor
    Code:java
    1. package me.benpat9.enderbutt;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.GameMode;
    6. import org.bukkit.Material;
    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.event.player.PlayerJoinEvent;
    13. import org.bukkit.event.player.PlayerMoveEvent;
    14. import org.bukkit.inventory.ItemStack;
    15. import org.bukkit.plugin.java.JavaPlugin;
    16.  
    17. public final class Main extends JavaPlugin implements Listener {
    18.  
    19. public static ArrayList<String> list = new ArrayList<String>();
    20.  
    21. @Override
    22. public void onEnable(){
    23. getServer().getPluginManager().registerEvents(this, this);
    24. getConfig().options().copyDefaults(true);
    25. saveConfig();
    26. }
    27. @Override
    28. public void onDisable() {
    29.  
    30. }
    31. @EventHandler
    32. public void JoinEvent(PlayerJoinEvent event) {
    33. Player player = (Player) event.getPlayer();
    34. player.getInventory().setItem(1, new ItemStack(Material.ENDER_PEARL, 32));
    35. }
    36. @SuppressWarnings("deprecation")
    37. @EventHandler
    38. public void onProjectileLaunch(ProjectileLaunchEvent event) {
    39. Player shooter = (Player) event.getEntity().getShooter();
    40. if (event.getEntity().getShooter() instanceof Player && event.getEntity() instanceof EnderPearl) {
    41. shooter.setGameMode(GameMode.CREATIVE);
    42. event.getEntity().setPassenger((Player)event.getEntity().getShooter());
    43. }
    44. }
    45. @EventHandler
    46. public void onMove(PlayerMoveEvent evt){
    47. if(evt.getPlayer().getVehicle() == null && evt.getPlayer().getGameMode() == GameMode.CREATIVE)
    48. evt.getPlayer().setGameMode(GameMode.SURVIVAL);
    49. }
    50. }


    stormneo7 Any help?

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

    ChipDev

    Aha,
    1) Get the player direction on the throw of the ender pearl
    2) get the velocity of the ender pearl and give it to the player.
     
  21. Offline

    Benpat9

  22. Offline

    MasterDoctor

  23. Offline

    stormneo7

    useless to use a velocity 'cause the player can move during the velocity event
     
  24. Offline

    Benpat9

  25. Offline

    ChipDev

  26. Offline

    JBoss925

    Why are you still trying to use an enderpearl? If it's for looks, try having the player throw a snowball instead and then spawn an enderpearl and set the snowball's passenger to the ender pearl and the ender pearl's passenger to the player. You can also make the snowball invisible with some NMS.
     
  27. Offline

    stormneo7

    Lol you don't know how much checks you need to do just to do that.

    Also, you'd need to create a scheduler to reapply the movement speed due to the fact that PlayerMoveEvent will only be triggered if the player moves their camera (Players cannot move because their walk speed is 0).
    This creates a short lag second where you are unable to move while the event is being triggered as well as a camera lapse where the client itself adjusts to the new speed (Player FOV deepens while speed is higher, lowers when speed is lower. Speed effect.) Huge discomfort to Players.

    Also, have you considered the fact that enderperals can travel THROUGH small locations such as a 1x1 hole.
    Players cannot, they'll get blocked. Another reason why your method doesn't work.
     
  28. Offline

    ChipDev

    Hmm.. good point.. But I guess they won't be having many 1x1 holes :p
    Save a hash map and check for it on playerTeleportEvent. (EnderPearl by:)
    Code:java
    1. if (event.getCause() != PlayerTeleportEvent.TeleportCause.ENDER_PEARL){;
     
  29. Offline

    AoH_Ruthless

    Benpat9

    EnderPearl is a projectile in Bukkit, and the passenger can be set of it...

    Code:java
    1. @EventHandler
    2. public void onProjectileLaunch(ProjectileLaunchEvent event) { // listen for launching
    3. Projectile pro = event.getEntity();
    4. if (pro instanceof EnderPearl) // EnderPearl is an extension of Projectile
    5. EnderPearl pearl = (EnderPearl) pro;
    6. ProjectileSource source= pearl.getShooter(); // checks to see if shooter is a player.
    7. if (source instanceof Player) {
    8. Player player = (Player) source;
    9. pearl.setPassenger(player); // set passenger
    10. }
    11. }
    12. }


    Hope that works!
     
  30. Offline

    stormneo7

    Have you tried your code? We've already done this in previous comments; it doesn't work.
    If the enderperal is shot upwards, it will hit the player riding it unless they are in Gamemode



    I think he wants the teleport to go through if the player's ride was full and sucessful.
     
Thread Status:
Not open for further replies.

Share This Page