Check If Player Is Riding an Entity

Discussion in 'Spigot Plugin Development' started by Bladian, May 14, 2015.

  1. Using a run task later scheduler, but can't find if a player is riding an entity.

    I know it's something along the lines, p.getEntity().getVehicle() instanceof CustomMob but can't really find it.
  2. Just to add onto the question. I would like to check if the player is riding a horse.
  3. p.getVehicle() works for me.

    But I'd first check if the player is in a vehicle:

    and then what you did (instanceof) for Horse.
    • Useful Useful x 1
  4. I tried it out with this:

    Code (Text):
    public void onTime(final Player p) {
            Bukkit.getScheduler().runTaskLater(Core.getInstance(), new Runnable() {
                public void run() {
                    if(p.isInsideVehicle()) {
                        if (p.getVehicle() != null) {
                            if (!(p.getVehicle() instanceof Horse)) {
                                Entity entity = p.getVehicle();
  5. Yep that should work. However there is no reason to check whether vehicle != null, since you already checked whether the player is in a vehicle.