Check is players target is armor stand

Discussion in 'Spigot Plugin Development' started by zLegendXP, Jul 1, 2018.

Thread Status:
Not open for further replies.
  1. omg I spent so much time trying to figure this out and I just cannot. I want to check if when a players target is an armor stand. Ive tried if(p.getTargetBlock((Set<Material>) null, 5).getType == Material.ArmorStand) doesn't work So then I looped through every armor stand in the world that the player was in, checked is the players target block was the the armor stands location and that didn't work. I am so frustrated someone help.
  2. An armour stand is actually an entity, so use the following method
    Code (Text):
    private Entity getLookingAt(Player player) {
        int range = 5;
        Location eye = player.getEyeLocation();
        Entity lookingAt = null;
        for (Entity entity : player.getNearbyEntities(range, range, range)) {
            Vector vector = entity.getLocation().toVector().subtract(eye.toVector());
            if (vector.normalize().dot(eye.getDirection()) > 0.9D) {
                lookingAt = entity;
        return lookingAt;
    Then in your command or wherever you are using the method, just check
    Code (Text):
    if (getLookingAt(player) instanceof ArmourStand && getLookingAt(player) != null) {
          // do your stuff
    The range integer in the lookingAt method is how many blocks away the armour stand can be for the method to return it.

    Thanks @Mr.Midnight for your post here that I based this on.
    • Like Like x 1
  3. ill try it thx :)
  4. it ended up working thx so much
  5. Just saying, an optimistic rating is used as a negative rating.
    Personally, I don't mind, but you might end up accidentally offending some people by rating their posts optimistic.
  6. I though optimistic was like the best rating sorry ::eek:
    • Like Like x 1
  7. It's fine, haha.

    Good luck with your plugin.
    • Friendly Friendly x 1
  8. The definition of optimistic is to be hopeful of the future. But, since the disagree rating was removed, everyone started using optimistic. Kinda stupid, really. Anyway remember to mark this as solved and lock it.
    • Agree Agree x 1
Thread Status:
Not open for further replies.