Skip to content
This repository has been archived by the owner on Mar 8, 2022. It is now read-only.

Commit

Permalink
use getTargetEntity
Browse files Browse the repository at this point in the history
  • Loading branch information
cyilin committed Sep 19, 2018
1 parent 0cf7faa commit 5c9a5be
Showing 1 changed file with 4 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/main/java/cat/nyaa/nyaautils/exhibition/ExhibitionFrame.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package cat.nyaa.nyaautils.exhibition;

import cat.nyaa.nyaacore.utils.RayTraceUtils;
import org.bukkit.ChatColor;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
Expand All @@ -12,7 +13,6 @@
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
import java.util.Optional;

import static org.bukkit.Material.AIR;

Expand Down Expand Up @@ -109,15 +109,9 @@ public static ExhibitionFrame fromItemFrame(ItemFrame frame) {
}

public static ExhibitionFrame fromPlayerEye(Player p) {
Vector eyeVector = p.getEyeLocation().getDirection();
Vector locVec = p.getEyeLocation().toVector().multiply(-1);
Optional<Entity> itemF = p.getNearbyEntities(10, 10, 10).stream()
.filter(entity -> entity instanceof ItemFrame)
.filter(entity -> entity.getLocation().toVector().add(locVec).angle(eyeVector) < 0.5D)
.sorted((e1, e2) -> Double.compare(e1.getLocation().distance(p.getLocation()), e2.getLocation().distance(p.getLocation())))
.findFirst();
if (itemF.isPresent()) {
return new ExhibitionFrame((ItemFrame) itemF.get());
Entity itemF = RayTraceUtils.getTargetEntity(p);
if (itemF instanceof ItemFrame) {
return new ExhibitionFrame((ItemFrame) itemF);
} else {
return null;
}
Expand Down

0 comments on commit 5c9a5be

Please sign in to comment.