mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-01-27 02:01:20 +01:00
Limit hologram view range with small view distance setting
This commit is contained in:
parent
39f3f49504
commit
d76739d332
@ -9,6 +9,7 @@ import me.filoghost.fcommons.logging.Log;
|
|||||||
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
|
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
|
||||||
import me.filoghost.holographicdisplays.core.listener.LineClickListener;
|
import me.filoghost.holographicdisplays.core.listener.LineClickListener;
|
||||||
import me.filoghost.holographicdisplays.core.placeholder.tracking.ActivePlaceholderTracker;
|
import me.filoghost.holographicdisplays.core.placeholder.tracking.ActivePlaceholderTracker;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -73,8 +74,11 @@ public class TickingTask implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Holograms need to disappear before chunks (code taken from Bukkit)
|
||||||
|
int maxViewRange = (Bukkit.getViewDistance() - 1) * 16;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
lineTrackerManager.update(onlinePlayers, movedPlayers);
|
lineTrackerManager.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// Catch all types of Throwable because we're using NMS code
|
// Catch all types of Throwable because we're using NMS code
|
||||||
if (tickClock.getCurrentTick() - lastErrorLogTick >= 20) {
|
if (tickClock.getCurrentTick() - lastErrorLogTick >= 20) {
|
||||||
|
@ -43,8 +43,8 @@ public class ItemLineTracker extends ClickableLineTracker<Viewer> {
|
|||||||
|
|
||||||
@MustBeInvokedByOverriders
|
@MustBeInvokedByOverriders
|
||||||
@Override
|
@Override
|
||||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||||
super.update(onlinePlayers, movedPlayers);
|
super.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||||
|
|
||||||
if (spawnItemEntity && hasViewers() && line.hasPickupCallback()) {
|
if (spawnItemEntity && hasViewers() && line.hasPickupCallback()) {
|
||||||
for (Viewer viewer : getViewers()) {
|
for (Viewer viewer : getViewers()) {
|
||||||
|
@ -54,7 +54,7 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@MustBeInvokedByOverriders
|
@MustBeInvokedByOverriders
|
||||||
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
protected void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||||
boolean sendChangesPackets = false;
|
boolean sendChangesPackets = false;
|
||||||
|
|
||||||
// First, detect the changes if the flag is on and set it off
|
// First, detect the changes if the flag is on and set it off
|
||||||
@ -77,7 +77,7 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Finally, add/remove viewers sending them the full spawn/destroy packets
|
// Finally, add/remove viewers sending them the full spawn/destroy packets
|
||||||
modifyViewersAndSendPackets(onlinePlayers, movedPlayers);
|
modifyViewersAndSendPackets(onlinePlayers, movedPlayers, maxViewRange);
|
||||||
|
|
||||||
if (sendChangesPackets) {
|
if (sendChangesPackets) {
|
||||||
clearDetectedChanges();
|
clearDetectedChanges();
|
||||||
@ -86,7 +86,7 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
|
|
||||||
protected abstract boolean updatePlaceholders();
|
protected abstract boolean updatePlaceholders();
|
||||||
|
|
||||||
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||||
if (!getLine().isInLoadedChunk()) {
|
if (!getLine().isInLoadedChunk()) {
|
||||||
resetViewersAndSendDestroyPackets();
|
resetViewersAndSendDestroyPackets();
|
||||||
return;
|
return;
|
||||||
@ -120,7 +120,7 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
for (int i = 0; i < size; i++) {
|
for (int i = 0; i < size; i++) {
|
||||||
CachedPlayer player = playersToCheck.get(i);
|
CachedPlayer player = playersToCheck.get(i);
|
||||||
Player bukkitPlayer = player.getBukkitPlayer();
|
Player bukkitPlayer = player.getBukkitPlayer();
|
||||||
if (shouldTrackPlayer(player)) {
|
if (shouldTrackPlayer(player, maxViewRange)) {
|
||||||
if (!viewers.containsKey(bukkitPlayer)) {
|
if (!viewers.containsKey(bukkitPlayer)) {
|
||||||
T viewer = createViewer(player);
|
T viewer = createViewer(player);
|
||||||
viewers.put(bukkitPlayer, viewer);
|
viewers.put(bukkitPlayer, viewer);
|
||||||
@ -148,17 +148,22 @@ public abstract class LineTracker<T extends Viewer> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldTrackPlayer(CachedPlayer player) {
|
private boolean shouldTrackPlayer(CachedPlayer player, int maxViewRange) {
|
||||||
Location playerLocation = player.getLocation();
|
Location playerLocation = player.getLocation();
|
||||||
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
double viewRange = getViewRange();
|
||||||
|
if (viewRange > maxViewRange) {
|
||||||
|
viewRange = maxViewRange;
|
||||||
|
}
|
||||||
|
|
||||||
double diffX = Math.abs(playerLocation.getX() - positionCoordinates.getX());
|
double diffX = Math.abs(playerLocation.getX() - positionCoordinates.getX());
|
||||||
double diffZ = Math.abs(playerLocation.getZ() - positionCoordinates.getZ());
|
double diffZ = Math.abs(playerLocation.getZ() - positionCoordinates.getZ());
|
||||||
|
|
||||||
return diffX <= getViewRange()
|
return diffX <= viewRange
|
||||||
&& diffZ <= getViewRange()
|
&& diffZ <= viewRange
|
||||||
&& getLine().isVisibleTo(player.getBukkitPlayer());
|
&& getLine().isVisibleTo(player.getBukkitPlayer());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class LineTrackerManager {
|
|||||||
return tracker;
|
return tracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers) {
|
public void update(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||||
Iterator<LineTracker<?>> iterator = lineTrackers.iterator();
|
Iterator<LineTracker<?>> iterator = lineTrackers.iterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
LineTracker<?> lineTracker = iterator.next();
|
LineTracker<?> lineTracker = iterator.next();
|
||||||
@ -59,7 +59,7 @@ public class LineTrackerManager {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
lineTracker.update(onlinePlayers, movedPlayers);
|
lineTracker.update(onlinePlayers, movedPlayers, maxViewRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user