mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2024-12-26 18:57:40 +01:00
Workaround attempt to fix holograms not displaying after teleport
This commit is contained in:
parent
d76739d332
commit
d670fae7ab
@ -7,22 +7,23 @@ package me.filoghost.holographicdisplays.core.tick;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class CachedPlayer {
|
||||
|
||||
private final Player player;
|
||||
|
||||
private Location location;
|
||||
private boolean movedLastTick;
|
||||
|
||||
public CachedPlayer(Player player) {
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
boolean onTick() {
|
||||
void onTick() {
|
||||
Location newLocation = player.getLocation();
|
||||
boolean moved = isDifferentPosition(location, newLocation);
|
||||
movedLastTick = isDifferentPosition(location, newLocation);
|
||||
location = newLocation;
|
||||
return moved;
|
||||
}
|
||||
|
||||
private boolean isDifferentPosition(Location oldLocation, Location newLocation) {
|
||||
@ -40,10 +41,14 @@ public class CachedPlayer {
|
||||
return player;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
public @Nullable Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public boolean isMovedLastTick() {
|
||||
return movedLastTick;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
@ -6,9 +6,9 @@
|
||||
package me.filoghost.holographicdisplays.core.tick;
|
||||
|
||||
import me.filoghost.fcommons.logging.Log;
|
||||
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
|
||||
import me.filoghost.holographicdisplays.core.listener.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.core.placeholder.tracking.ActivePlaceholderTracker;
|
||||
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -68,8 +68,7 @@ public class TickingTask implements Runnable {
|
||||
|
||||
List<CachedPlayer> movedPlayers = new ArrayList<>();
|
||||
for (CachedPlayer onlinePlayer : onlinePlayers) {
|
||||
boolean moved = onlinePlayer.onTick();
|
||||
if (moved) {
|
||||
if (onlinePlayer.isMovedLastTick()) {
|
||||
movedPlayers.add(onlinePlayer);
|
||||
}
|
||||
}
|
||||
@ -91,7 +90,14 @@ public class TickingTask implements Runnable {
|
||||
// Remove placeholders which were not used by line trackers
|
||||
placeholderTracker.clearInactivePlaceholders();
|
||||
|
||||
// Invoke click listeners
|
||||
lineClickListener.processQueuedClickEvents();
|
||||
|
||||
// Delay position updates, so that they will be handled next tick.
|
||||
// A tick of delay is necessary to avoid issues such as holograms not being visible after a teleport.
|
||||
for (CachedPlayer onlinePlayer : onlinePlayers) {
|
||||
onlinePlayer.onTick();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class ItemLineTracker extends ClickableLineTracker<Viewer> {
|
||||
|
||||
if (spawnItemEntity && hasViewers() && line.hasPickupCallback()) {
|
||||
for (Viewer viewer : getViewers()) {
|
||||
if (CollisionHelper.isInPickupRange(viewer.getLocation(), positionCoordinates)) {
|
||||
if (viewer.getLocation() != null && CollisionHelper.isInPickupRange(viewer.getLocation(), positionCoordinates)) {
|
||||
line.onPickup(viewer.getBukkitPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
* Flag to indicate that the line has changed in some way and there could be the need to send update packets.
|
||||
*/
|
||||
private boolean lineChanged;
|
||||
private boolean inLoadedChunk;
|
||||
private int lastVisibilitySettingsVersion;
|
||||
|
||||
protected LineTracker() {
|
||||
@ -88,12 +89,21 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers, List<CachedPlayer> movedPlayers, int maxViewRange) {
|
||||
if (!getLine().isInLoadedChunk()) {
|
||||
resetViewersAndSendDestroyPackets();
|
||||
if (inLoadedChunk) {
|
||||
inLoadedChunk = false;
|
||||
resetViewersAndSendDestroyPackets();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
boolean checkAllPlayers = false;
|
||||
|
||||
if (!inLoadedChunk) {
|
||||
// The chunk was just loaded, check all players
|
||||
inLoadedChunk = true;
|
||||
checkAllPlayers = true;
|
||||
}
|
||||
|
||||
int visibilitySettingsVersion = getLine().getVisibilitySettings().getVersion();
|
||||
if (visibilitySettingsVersion != lastVisibilitySettingsVersion) {
|
||||
lastVisibilitySettingsVersion = visibilitySettingsVersion;
|
||||
@ -150,7 +160,7 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
private boolean shouldTrackPlayer(CachedPlayer player, int maxViewRange) {
|
||||
Location playerLocation = player.getLocation();
|
||||
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||
if (playerLocation == null || playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import me.filoghost.holographicdisplays.nms.common.PacketGroup;
|
||||
import me.filoghost.holographicdisplays.core.tick.CachedPlayer;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
class Viewer {
|
||||
|
||||
@ -23,7 +24,7 @@ class Viewer {
|
||||
return player.getBukkitPlayer();
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
public @Nullable Location getLocation() {
|
||||
return player.getLocation();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user