Advertisement
iSynx

EntityUtil.java

Mar 21st, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. package com.desle.staffmode;
  2.  
  3. import org.bukkit.entity.Entity;
  4. import org.bukkit.entity.Player;
  5.  
  6. public class EntityUtil
  7. {
  8. public EntityUtil() {}
  9.  
  10. public static Entity getPlayerInSight(Player player)
  11. {
  12. Entity entity = null;
  13.  
  14. for (Entity nearbyEntity : player.getNearbyEntities(10.0D, 10.0D, 10.0D)) {
  15. if (((nearbyEntity instanceof Player)) && (isLookingAtEntity(player, nearbyEntity))) {
  16. entity = nearbyEntity;
  17. }
  18. }
  19. return entity;
  20. }
  21.  
  22. public static boolean isLookingAtEntity(Player player, Entity entity) {
  23. org.bukkit.Location eye = player.getEyeLocation();
  24. org.bukkit.util.Vector toEntity = entity.getLocation().toVector().subtract(eye.toVector());
  25. double dot = toEntity.normalize().dot(eye.getDirection());
  26.  
  27. if (dot > 0.99D)
  28. return true;
  29. return false;
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement