How do I detect if a player is on a horse?

Discussion in 'Plugin Development' started by Ryan00793, Jul 6, 2013.

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

    Ryan00793

    As the title says I want to be able to detect if a player is on a horse or not.
    Another question i have is how do i stop the movement of a horse as well.
     
  2. Offline

    CoderCloud

    i think horses are not supported in the dev build, might take a bit until the horses are imokemented in the bukkit api.
     
  3. Yes they are, Ryan00793 get the 'vehicle' the player is riding and check if the entity is an instance of Horse.
    If you want to mess with the horse AI you should use a library or mess with NMS (Extend EntityHorse).
     
  4. Offline

    SquidDevelops

  5. Offline

    Ryan00793

    thanks to both of you i was thinking that the get vehicle didn't work because i tried to eject the player from the horse without success. Do you guys happen to have

    Thanks for the answer but I don't think that getVehicle returns a horse atm because

    Code:java
    1. Player p = event.getPlayer();
    2.  
    3. if(p.getVehicle() instanceof Horse){
    4. p.sendMessage(ChatColor.RED + "You can not use a shrine while riding a horse.");
    5. Random rand = new Random();
    6. p.getVehicle().setVelocity(new Vector(((double)rand.nextInt(100)-50)/30, 0.3 ((double)rand.nextInt(100)-50)/30));
    7. } else {
    8. Long time = plugin.shrineTimer.get(p.getName());
    9. if (time == null || time < System.currentTimeMillis()) {
    10. to.setY(to.getBlockY());
    11. p.teleport(to);
    12. playerPrompt(shrine.name, p);
    13. }
    14. else {
    15. Random rand = new Random();
    16. p.setVelocity(new Vector(((double)rand.nextInt(100)-50)/30, 0.3,((double)rand.nextInt(100)-50)/30));
    17. p.sendMessage(ChatColor.RED + "Shrine recharging: " + ChatColor.WHITE + ((time - System.currentTimeMillis())/1000) + ChatColor.YELLOW + " seconds left");
    18. }//end of else
    19. }//end of horse check


    This seems to not work any ideas (continues on into the else).
     
  6. Offline

    xize

    hmm
    I'm not sure but for EntityDamageByEntityEvent it worked for me as:

    Code:java
    1.  
    2. if(e.getVerhicle().getType == EntityType.Unknown) {
    3. //do something
    4. }
    5.  


    it seems it automaticly find the horse entity, but I'm not sure there are other entitys aswell when you are using the unkown enum it might can conflict;)
    edit
    as for instanceof Horse the horse instance didn't work for me, I'm not sure if you can use instanceof unknown though:p
     
  7. Offline

    CoderCloud

    You could try to print 'e.getVehicle().getClasss().getName()' to see what class the horse actually is.
     
Thread Status:
Not open for further replies.

Share This Page