diff --git a/common/src/main/java/me/lojosho/hibiscuscommons/util/ServerUtils.java b/common/src/main/java/me/lojosho/hibiscuscommons/util/ServerUtils.java index e82436a..014e9bc 100644 --- a/common/src/main/java/me/lojosho/hibiscuscommons/util/ServerUtils.java +++ b/common/src/main/java/me/lojosho/hibiscuscommons/util/ServerUtils.java @@ -4,10 +4,14 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedSignedProperty; import me.lojosho.hibiscuscommons.nms.NMSHandlers; import org.bukkit.Color; +import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; public class ServerUtils { @@ -92,6 +96,21 @@ public class ServerUtils { return nextYaw; } + /** + * Get the viewers of an entity (Players only) that can see the entity in the world. + * This ignores config view distances and checks directly with the server. + * @param entity + * @return + */ + @NotNull + public static List getViewers(@NotNull Entity entity) { + ArrayList viewers = new ArrayList<>(); + for (Player player : entity.getLocation().getWorld().getPlayers()) { + if (player.canSee(entity)) viewers.add(player); + } + return viewers; + } + public static boolean hasClass(String className) { try { Class.forName(className);