mirror of
https://github.com/HibiscusMC/HibiscusCommons.git
synced 2025-12-20 23:49:18 +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 com.comphenix.protocol.wrappers.WrappedSignedProperty;
|
||||||
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
import me.lojosho.hibiscuscommons.nms.NMSHandlers;
|
||||||
import org.bukkit.Color;
|
import org.bukkit.Color;
|
||||||
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ServerUtils {
|
public class ServerUtils {
|
||||||
|
|
||||||
@@ -92,6 +96,21 @@ public class ServerUtils {
|
|||||||
return nextYaw;
|
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) {
|
public static boolean hasClass(String className) {
|
||||||
try {
|
try {
|
||||||
Class.forName(className);
|
Class.forName(className);
|
||||||
|
|||||||
Reference in New Issue
Block a user