More robust backwards compat
This commit is contained in:
parent
cd25930373
commit
107e3b3296
|
@ -518,14 +518,14 @@ public class NMS {
|
||||||
return BRIDGE.getNBT(item);
|
return BRIDGE.getNBT(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Collection<Player> getNearbyPlayers(Player from) {
|
private static Collection<Player> getNearbyPlayers(Entity from) {
|
||||||
return getNearbyPlayers(from, from.getLocation(), 64);
|
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();
|
List<Player> players = Lists.newArrayList();
|
||||||
for (Player player : CitizensAPI.getLocationLookup().getNearbyPlayers(location, radius)) {
|
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)
|
|| location.distance(player.getLocation()) > radius)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
@ -760,12 +760,12 @@ public class NMS {
|
||||||
BRIDGE.sendPositionUpdate(from, to, position, bodyYaw, pitch, headYaw);
|
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(),
|
sendPositionUpdate(from, getNearbyPlayers(from), position, NMS.getYaw(from), from.getLocation().getPitch(),
|
||||||
NMS.getHeadYaw(from));
|
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) {
|
Float headYaw) {
|
||||||
sendPositionUpdate(from, getNearbyPlayers(from), position, bodyYaw, pitch, headYaw);
|
sendPositionUpdate(from, getNearbyPlayers(from), position, bodyYaw, pitch, headYaw);
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,6 +105,20 @@ public class Util {
|
||||||
return !event.isCancelled() ? event.getCollisionVector() : null;
|
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]
|
* 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 final Scoreboard DUMMY_SCOREBOARD = Bukkit.getScoreboardManager().getNewScoreboard();
|
||||||
private static boolean SUPPORTS_BUKKIT_GETENTITY = true;
|
private static boolean SUPPORTS_BUKKIT_GETENTITY = true;
|
||||||
|
private static boolean SUPPORTS_ENTITY_CANSEE = true;
|
||||||
private static final DecimalFormat TWO_DIGIT_DECIMAL = new DecimalFormat();
|
private static final DecimalFormat TWO_DIGIT_DECIMAL = new DecimalFormat();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|
Loading…
Reference in New Issue