Move VisibilitySettings to BaseHologram

This commit is contained in:
filoghost 2022-06-01 23:33:05 +02:00
parent 5727de44dc
commit e0d47284b7
5 changed files with 12 additions and 26 deletions

View File

@ -12,7 +12,6 @@ import me.filoghost.holographicdisplays.api.beta.hologram.PlaceholderSetting;
import me.filoghost.holographicdisplays.core.base.BaseHologram;
import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
@ -21,7 +20,6 @@ class APIHologram extends BaseHologram implements Hologram {
private final APIHologramLines lines;
private final Plugin plugin;
private final APIHologramManager hologramManager;
private final DefaultVisibilitySettings visibilitySettings;
private @NotNull PlaceholderSetting placeholderSetting;
@ -35,7 +33,6 @@ class APIHologram extends BaseHologram implements Hologram {
this.lines = new APIHologramLines(this);
this.plugin = plugin;
this.hologramManager = hologramManager;
this.visibilitySettings = new DefaultVisibilitySettings();
this.placeholderSetting = PlaceholderSetting.DEFAULT;
}
@ -44,11 +41,6 @@ class APIHologram extends BaseHologram implements Hologram {
return lines;
}
@Override
public @NotNull DefaultVisibilitySettings getVisibilitySettings() {
return visibilitySettings;
}
@Override
public void setPosition(@NotNull Position position) {
super.setPosition(ImmutablePosition.of(position));
@ -79,11 +71,6 @@ class APIHologram extends BaseHologram implements Hologram {
return plugin;
}
@Override
public boolean isVisibleTo(Player player) {
return visibilitySettings.isVisibleTo(player);
}
@Override
public void delete() {
hologramManager.deleteHologram(this);

View File

@ -16,7 +16,6 @@ import me.filoghost.holographicdisplays.core.base.ImmutablePosition;
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
@ -39,7 +38,7 @@ class V2Hologram extends BaseHologram implements Hologram {
this.plugin = plugin;
this.hologramManager = hologramManager;
this.lines = new BaseHologramLines<>(this);
this.visibilityManager = new V2VisibilityManager();
this.visibilityManager = new V2VisibilityManager(getVisibilitySettings());
this.creationTimestamp = System.currentTimeMillis();
}
@ -48,11 +47,6 @@ class V2Hologram extends BaseHologram implements Hologram {
return lines;
}
@Override
protected boolean isVisibleTo(Player player) {
return visibilityManager.isVisibleTo(player);
}
@Override
public Plugin getCreatorPlugin() {
return plugin;

View File

@ -6,6 +6,7 @@
package me.filoghost.holographicdisplays.core.api.v2;
import com.gmail.filoghost.holographicdisplays.api.VisibilityManager;
import me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings;
import me.filoghost.holographicdisplays.api.beta.hologram.VisibilitySettings.Visibility;
import me.filoghost.holographicdisplays.core.api.current.DefaultVisibilitySettings;
import org.bukkit.entity.Player;
@ -13,9 +14,9 @@ import org.bukkit.entity.Player;
@SuppressWarnings("deprecation")
class V2VisibilityManager implements VisibilityManager {
private final DefaultVisibilitySettings v3VisibilitySettings;
private final VisibilitySettings v3VisibilitySettings;
V2VisibilityManager() {
V2VisibilityManager(VisibilitySettings visibilitySettings) {
this.v3VisibilitySettings = new DefaultVisibilitySettings();
}

View File

@ -6,11 +6,11 @@
package me.filoghost.holographicdisplays.core.base;
import me.filoghost.fcommons.Preconditions;
import me.filoghost.holographicdisplays.core.api.current.DefaultVisibilitySettings;
import me.filoghost.holographicdisplays.core.tracking.LineTrackerManager;
import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@ -18,17 +18,17 @@ import org.jetbrains.annotations.Nullable;
public abstract class BaseHologram extends BaseHologramComponent {
private final HologramPosition hologramPosition;
private final DefaultVisibilitySettings visibilitySettings;
private final LineTrackerManager lineTrackerManager;
public BaseHologram(ImmutablePosition position, LineTrackerManager lineTrackerManager) {
this.hologramPosition = new HologramPosition(position);
this.visibilitySettings = new DefaultVisibilitySettings();
this.lineTrackerManager = lineTrackerManager;
}
public abstract BaseHologramLines<? extends EditableHologramLine> getLines();
protected abstract boolean isVisibleTo(Player player);
public abstract Plugin getCreatorPlugin();
protected final LineTrackerManager getTrackerManager() {
@ -45,6 +45,10 @@ public abstract class BaseHologram extends BaseHologramComponent {
return hologramPosition.getPosition();
}
public @NotNull DefaultVisibilitySettings getVisibilitySettings() {
return visibilitySettings;
}
public @Nullable World getWorldIfLoaded() {
return hologramPosition.getWorldIfLoaded();
}

View File

@ -61,7 +61,7 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements
}
public final boolean isVisibleTo(Player player) {
return hologram.isVisibleTo(player);
return hologram.getVisibilitySettings().isVisibleTo(player);
}
public final Plugin getCreatorPlugin() {