Ender Pearl rider stops riding when i throw it??

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

  1. Hello spigot.
    I am making a hub plugin and it has a enderbutt i got the throwing of a enderbutt well like i throw it and it go ones the pearl and rides it for around 1 sec then the pearl just disappears i think the player is hitting the pearl so it is dismounting the player? I am running 1.7.10 and the server is 1.7.10 - 1.8 Please help!

    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();
            }
        }
     
  2. You have a lot of issues here.

    Firstly, usually people don't do support for versions that aren't the latest, and yours is so old there are people who were born when it came out that now play Minecraft.

    Secondly,
    Code (Text):
      Player player = (Player)event.getEntity().getShooter();
       
        if (!(player instanceof Player)) {
            return;
        }
    No. You can't cast an entity to be player and then return after the fact if it's not a player. First you check if it's a player, then you cast it into a player. This will cause errors.

    Thirdly, and ignoring a few issues along the way,
    Code (Text):
     if (event.getEntityType().equals(EntityType.ENDER_PEARL) && event.getEntity().isOnGround()) {
                event.getEntity().getPassenger().remove();
            }
    This part is just weird and probably causes a lot of issues, maybe even including the one you are currently having. Just rethink whatever it is you're trying to do with that part of the code and then write some other way of doing it. Don't forget that code might run right after the previous if statement.

    Fourthly,
    . What?