How to make a ender pearl rider?

Discussion in 'Spigot Plugin Development' started by MGPro, Nov 17, 2017.

  1. Hello spigot,
    I'm trying to make a enderpearl rider so like when you throw a pearl you pretty much ride it till it lands then u can go ahead and do whatever. So like i would pearl then i would be on top of the pearl like sitting down on it and going the entire length of the pearl in till it hits the ground. And also if there in the air and they do it again while in the air it removes the other pearl and carry's on with the new pearl. Does anyone know how to do this?
     
  2. I haven't tested this but I believe this will work.
    Code (Text):
    @EventHandler
        public void enderpearlThrow(ProjectileLaunchEvent event) {
            Player player = (Player)event.getEntity().getShooter();
           
            if (!(player instanceof Player)) {
                return;
            }
           
            if (event.getEntityType().equals(EntityType.ENDER_PEARL)) {
                if (player.hasPermission("enderpearl.ride") || player.isOp()) {
                    event.getEntity().setPassenger(player);
                }
            }
           
            if (event.getEntityType().equals(EntityType.ENDER_PEARL) && event.getEntity().isOnGround()) {
                event.getEntity().getPassenger().remove();
            }
        }
     
    • Informative Informative x 1
  3. Please, don’t spoonfeed. Just give him the docs the event and maybe some pseudo code. That will do. Also you should check enums by == and not #equals
     
  4. Please do not spoonfeed code.

    #addPassenger() should be used instead of #setPassenger() I believe
     
  5. Yea, sorry about that.

    EDIT:
    setting the passenger will just remove all other passengers and set who you want it to, it don't matter
     
  6. He is using PaperSpigot 1.7 this is deprecated.
     
    • Agree Agree x 1
  7. You can use entity#setPassenger()
     
    • Agree Agree x 1
    • Optimistic Optimistic x 1
  8. But you *shouldn't* if #addPassenger() is a thing.
     
  9. But you *can* if there will never be any other passengers ;)
     
    • Optimistic Optimistic x 1
  10. Other plugins might add passengers.
     
  11. Not if you don't have said plugins, of course :p

    Don't worry I understand your point hahaha
     
  12. please at least spoonfeed proper code, if you're going to D:

    Code (Text):
    if (!(player instanceof Player)) {
                return;
            }
    unneeded conditional.

    Code (Text):
    if (event.getEntityType().equals(EntityType.ENDER_PEARL)) {
    compare enums with the equality operator

    Code (Text):
    if (event.getEntityType().equals(EntityType.ENDER_PEARL)) {
                if (player.hasPermission("enderpearl.ride") || player.isOp()) {
    invert conditionals
     
  13. The plugin works pretty well, just one thing when i pearl i follow it for like 3 seconds then i get like hit off it?? any ideas?
     
  14. Thank you for that! I've been looking for how to do this for a while, but never bothered asking. FWIW, I don't care if it is "spoon feeding." Different people learn from different methods. Some people can learn from an explanation without any examples. Other people need a live instructor whom they can ask questions of. Yet other people need complete examples that they can examine and change around to understand how a thing works. IMO, there should be no shame in either learning style.
     
    • Optimistic Optimistic x 1
  15. If you always need help and instruction on how to learn Bukkit API, feel free to PM me, I'd be glad to help you out in learning how to code bukkit plugins
     
    • Like Like x 1