Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.desle.staffmode;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Player;
- public class EntityUtil
- {
- public EntityUtil() {}
- public static Entity getPlayerInSight(Player player)
- {
- Entity entity = null;
- for (Entity nearbyEntity : player.getNearbyEntities(10.0D, 10.0D, 10.0D)) {
- if (((nearbyEntity instanceof Player)) && (isLookingAtEntity(player, nearbyEntity))) {
- entity = nearbyEntity;
- }
- }
- return entity;
- }
- public static boolean isLookingAtEntity(Player player, Entity entity) {
- org.bukkit.Location eye = player.getEyeLocation();
- org.bukkit.util.Vector toEntity = entity.getLocation().toVector().subtract(eye.toVector());
- double dot = toEntity.normalize().dot(eye.getDirection());
- if (dot > 0.99D)
- return true;
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement