mirror of
https://github.com/filoghost/HolographicDisplays.git
synced 2025-02-16 20:11:19 +01:00
Merge related classes
This commit is contained in:
parent
e0d47284b7
commit
8018e52bbb
@ -13,7 +13,7 @@ import me.filoghost.holographicdisplays.core.listener.LineClickListener;
|
||||
import me.filoghost.holographicdisplays.core.tick.TickClock;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
public abstract class ClickableLineTracker<T extends Viewer> extends PositionBasedLineTracker<T> {
|
||||
public abstract class ClickableLineTracker<T extends Viewer> extends LineTracker<T> {
|
||||
|
||||
private final ClickableNMSPacketEntity clickableEntity;
|
||||
private final double positionOffsetY;
|
||||
|
@ -5,9 +5,11 @@
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.tracking;
|
||||
|
||||
import me.filoghost.holographicdisplays.common.PositionCoordinates;
|
||||
import me.filoghost.holographicdisplays.core.base.BaseHologramLine;
|
||||
import me.filoghost.holographicdisplays.core.tick.CachedPlayer;
|
||||
import me.filoghost.holographicdisplays.core.tick.TickClock;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
@ -15,6 +17,7 @@ import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
@ -24,6 +27,9 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
private final Map<Player, T> viewers;
|
||||
private final Viewers<T> iterableViewers;
|
||||
|
||||
protected PositionCoordinates position;
|
||||
private boolean positionChanged;
|
||||
|
||||
/**
|
||||
* Flag to indicate that the line has changed in some way and there could be the need to send update packets.
|
||||
*/
|
||||
@ -80,10 +86,6 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
modifyViewersAndSendPackets(onlinePlayers);
|
||||
}
|
||||
|
||||
protected abstract void detectChanges();
|
||||
|
||||
protected abstract void clearDetectedChanges();
|
||||
|
||||
protected abstract boolean updatePlaceholders();
|
||||
|
||||
private void modifyViewersAndSendPackets(List<CachedPlayer> onlinePlayers) {
|
||||
@ -134,9 +136,23 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract T createViewer(CachedPlayer cachedPlayer);
|
||||
private boolean shouldTrackPlayer(CachedPlayer player) {
|
||||
Location playerLocation = player.getLocation();
|
||||
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean shouldTrackPlayer(CachedPlayer cachedPlayer);
|
||||
double diffX = Math.abs(playerLocation.getX() - position.getX());
|
||||
double diffZ = Math.abs(playerLocation.getZ() - position.getZ());
|
||||
|
||||
return diffX <= getViewRange()
|
||||
&& diffZ <= getViewRange()
|
||||
&& getLine().isVisibleTo(player.getBukkitPlayer());
|
||||
}
|
||||
|
||||
protected abstract double getViewRange();
|
||||
|
||||
protected abstract T createViewer(CachedPlayer cachedPlayer);
|
||||
|
||||
protected final boolean hasViewers() {
|
||||
return !viewers.isEmpty();
|
||||
@ -154,6 +170,20 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
viewers.remove(player);
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
protected void detectChanges() {
|
||||
PositionCoordinates position = getLine().getPosition();
|
||||
if (!Objects.equals(this.position, position)) {
|
||||
this.position = position;
|
||||
this.positionChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
protected void clearDetectedChanges() {
|
||||
this.positionChanged = false;
|
||||
}
|
||||
|
||||
protected final void resetViewersAndSendDestroyPackets() {
|
||||
if (!hasViewers()) {
|
||||
return;
|
||||
@ -167,6 +197,13 @@ public abstract class LineTracker<T extends Viewer> {
|
||||
|
||||
protected abstract void sendDestroyPackets(Viewers<T> viewers);
|
||||
|
||||
protected abstract void sendChangesPackets(Viewers<T> viewers);
|
||||
@MustBeInvokedByOverriders
|
||||
protected void sendChangesPackets(Viewers<T> viewers) {
|
||||
if (positionChanged) {
|
||||
sendPositionChangePackets(viewers);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void sendPositionChangePackets(Viewers<T> viewers);
|
||||
|
||||
}
|
||||
|
@ -1,68 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) filoghost and contributors
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||
*/
|
||||
package me.filoghost.holographicdisplays.core.tracking;
|
||||
|
||||
import me.filoghost.holographicdisplays.common.PositionCoordinates;
|
||||
import me.filoghost.holographicdisplays.core.tick.CachedPlayer;
|
||||
import me.filoghost.holographicdisplays.core.tick.TickClock;
|
||||
import org.bukkit.Location;
|
||||
import org.jetbrains.annotations.MustBeInvokedByOverriders;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
abstract class PositionBasedLineTracker<T extends Viewer> extends LineTracker<T> {
|
||||
|
||||
protected PositionCoordinates position;
|
||||
private boolean positionChanged;
|
||||
|
||||
protected PositionBasedLineTracker(TickClock tickClock) {
|
||||
super(tickClock);
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@Override
|
||||
protected void detectChanges() {
|
||||
PositionCoordinates position = getLine().getPosition();
|
||||
if (!Objects.equals(this.position, position)) {
|
||||
this.position = position;
|
||||
this.positionChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@Override
|
||||
protected void clearDetectedChanges() {
|
||||
this.positionChanged = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final boolean shouldTrackPlayer(CachedPlayer player) {
|
||||
Location playerLocation = player.getLocation();
|
||||
if (playerLocation.getWorld() != getLine().getWorldIfLoaded()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
double diffX = Math.abs(playerLocation.getX() - position.getX());
|
||||
double diffZ = Math.abs(playerLocation.getZ() - position.getZ());
|
||||
|
||||
return diffX <= getViewRange()
|
||||
&& diffZ <= getViewRange()
|
||||
&& getLine().isVisibleTo(player.getBukkitPlayer());
|
||||
}
|
||||
|
||||
@MustBeInvokedByOverriders
|
||||
@Override
|
||||
protected void sendChangesPackets(Viewers<T> viewers) {
|
||||
if (positionChanged) {
|
||||
sendPositionChangePackets(viewers);
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void sendPositionChangePackets(Viewers<T> viewers);
|
||||
|
||||
protected abstract double getViewRange();
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user