More robust backwards compat

This commit is contained in:
fullwall 2024-01-13 14:05:57 +08:00
parent cd25930373
commit 107e3b3296
2 changed files with 20 additions and 5 deletions

View File

@ -518,14 +518,14 @@ public class NMS {
return BRIDGE.getNBT(item);
}
private static Collection<Player> getNearbyPlayers(Player from) {
private static Collection<Player> getNearbyPlayers(Entity from) {
return getNearbyPlayers(from, from.getLocation(), 64);
}
private static Collection<Player> getNearbyPlayers(Player from, Location location, double radius) {
private static Collection<Player> getNearbyPlayers(Entity from, Location location, double radius) {
List<Player> players = Lists.newArrayList();
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
if (location.getWorld() != player.getWorld() || from != null && !player.canSee(from)
if (location.getWorld() != player.getWorld() || from != null && Util.canSee(player, from)
|| location.distance(player.getLocation()) > radius)
continue;
@ -760,12 +760,12 @@ public class NMS {
BRIDGE.sendPositionUpdate(from, to, position, bodyYaw, pitch, headYaw);
}
public static void sendPositionUpdateNearby(Player from, boolean position) {
public static void sendPositionUpdateNearby(Entity from, boolean position) {
sendPositionUpdate(from, getNearbyPlayers(from), position, NMS.getYaw(from), from.getLocation().getPitch(),
NMS.getHeadYaw(from));
}
public static void sendPositionUpdateNearby(Player from, boolean position, Float bodyYaw, Float pitch,
public static void sendPositionUpdateNearby(Entity from, boolean position, Float bodyYaw, Float pitch,
Float headYaw) {
sendPositionUpdate(from, getNearbyPlayers(from), position, bodyYaw, pitch, headYaw);
}

View File

@ -105,6 +105,20 @@ public class Util {
return !event.isCancelled() ? event.getCollisionVector() : null;
}
public static boolean canSee(Player player, Entity from) {
if (from instanceof Player) {
return player.canSee((Player) from);
}
if (SUPPORTS_ENTITY_CANSEE) {
try {
return player.canSee(from);
} catch (NoSuchMethodError t) {
SUPPORTS_ENTITY_CANSEE = false;
}
}
return true;
}
/**
* Clamps the rotation angle to [-180, 180]
*/
@ -598,6 +612,7 @@ public class Util {
private static final Scoreboard DUMMY_SCOREBOARD = Bukkit.getScoreboardManager().getNewScoreboard();
private static boolean SUPPORTS_BUKKIT_GETENTITY = true;
private static boolean SUPPORTS_ENTITY_CANSEE = true;
private static final DecimalFormat TWO_DIGIT_DECIMAL = new DecimalFormat();
static {