mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-19 15:09:26 +00:00
feat: add getViewers in ServerUtils that uses new canSee method
This commit is contained in:
@@ -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<Player> getViewers(@NotNull Entity entity) {
|
||||
ArrayList<Player> 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);
|
||||
|
||||
Reference in New Issue
Block a user