From 5a1a273b7d7d89f987bb3e79e2511dbdc2d08cb7 Mon Sep 17 00:00:00 2001 From: Oliver Date: Sat, 28 Dec 2024 00:06:35 +0100 Subject: [PATCH] get stuff together --- .../fancyholograms/api/FancyHolograms.java | 14 +- .../fancyholograms/api/HologramManager.java | 30 - .../fancyholograms/HologramManagerImpl.java | 621 +++++++++--------- .../commands/hologram/BackgroundCMD.java | 2 +- .../commands/hologram/BillboardCMD.java | 2 +- .../commands/hologram/BlockCMD.java | 2 +- .../commands/hologram/BrightnessCMD.java | 2 +- .../commands/hologram/CenterCMD.java | 2 +- .../commands/hologram/CopyCMD.java | 2 +- .../commands/hologram/InsertAfterCMD.java | 2 +- .../commands/hologram/InsertBeforeCMD.java | 2 +- .../commands/hologram/ItemCMD.java | 2 +- .../commands/hologram/LinkWithNpcCMD.java | 2 +- .../commands/hologram/MoveHereCMD.java | 2 +- .../commands/hologram/ScaleCMD.java | 2 +- .../commands/hologram/SeeThroughCMD.java | 2 +- .../commands/hologram/SetLineCMD.java | 2 +- .../commands/hologram/ShadowRadiusCMD.java | 2 +- .../commands/hologram/ShadowStrengthCMD.java | 2 +- .../commands/hologram/TextAlignmentCMD.java | 2 +- .../commands/hologram/TextShadowCMD.java | 2 +- .../commands/hologram/TranslateCommand.java | 2 +- .../commands/hologram/UnlinkWithNpcCMD.java | 2 +- .../hologram/UpdateTextIntervalCMD.java | 2 +- .../commands/hologram/VisibilityCMD.java | 2 +- .../hologram/VisibilityDistanceCMD.java | 2 +- .../main/FancyHologramsPlugin.java | 44 +- .../fancyholograms/metrics/FHMetrics.java | 1 - 28 files changed, 359 insertions(+), 397 deletions(-) delete mode 100644 api/src/main/java/de/oliver/fancyholograms/api/HologramManager.java diff --git a/api/src/main/java/de/oliver/fancyholograms/api/FancyHolograms.java b/api/src/main/java/de/oliver/fancyholograms/api/FancyHolograms.java index aaf9b09c..f77cca8c 100644 --- a/api/src/main/java/de/oliver/fancyholograms/api/FancyHolograms.java +++ b/api/src/main/java/de/oliver/fancyholograms/api/FancyHolograms.java @@ -25,20 +25,14 @@ static boolean isEnabled() { ExtendedFancyLogger getFancyLogger(); - HologramManager getHologramManager(); - - /** - * Returns the configuration of the plugin. - * - * @return The configuration. - */ HologramConfiguration getHologramConfiguration(); - /** - * @return The hologram thread - */ ScheduledExecutorService getHologramThread(); + HologramRegistry getRegistry(); + + HologramController getController(); + class EnabledChecker { diff --git a/api/src/main/java/de/oliver/fancyholograms/api/HologramManager.java b/api/src/main/java/de/oliver/fancyholograms/api/HologramManager.java deleted file mode 100644 index 835cfc2f..00000000 --- a/api/src/main/java/de/oliver/fancyholograms/api/HologramManager.java +++ /dev/null @@ -1,30 +0,0 @@ -package de.oliver.fancyholograms.api; - -import de.oliver.fancyholograms.api.data.HologramData; -import de.oliver.fancyholograms.api.hologram.Hologram; - -import java.util.Collection; -import java.util.Optional; - -@Deprecated -public interface HologramManager { - - Optional getHologram(String name); - - Collection getPersistentHolograms(); - - Collection getHolograms(); - - void addHologram(Hologram hologram); - - void removeHologram(Hologram hologram); - - Hologram create(HologramData hologramData); - - void loadHolograms(); - - void saveHolograms(); - - void reloadHolograms(); - -} diff --git a/src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java b/src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java index 82af5e85..5c1498b8 100644 --- a/src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java +++ b/src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java @@ -1,312 +1,309 @@ -package de.oliver.fancyholograms; - -import com.google.common.cache.CacheBuilder; -import com.google.common.collect.ImmutableList; -import de.oliver.fancyholograms.api.HologramManager; -import de.oliver.fancyholograms.api.data.DisplayHologramData; -import de.oliver.fancyholograms.api.data.HologramData; -import de.oliver.fancyholograms.api.data.TextHologramData; -import de.oliver.fancyholograms.api.events.HologramsLoadedEvent; -import de.oliver.fancyholograms.api.events.HologramsUnloadedEvent; -import de.oliver.fancyholograms.api.hologram.Hologram; -import de.oliver.fancyholograms.main.FancyHologramsPlugin; -import de.oliver.fancynpcs.api.FancyNpcsPlugin; -import org.bukkit.Bukkit; -import org.bukkit.World; -import org.bukkit.entity.Player; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.UnmodifiableView; -import org.joml.Vector3f; - -import java.time.Duration; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; - -/** - * The FancyHologramsManager class is responsible for managing holograms in the FancyHolograms plugin. - * It provides methods for adding, removing, and retrieving holograms, as well as other related operations. - */ -public final class HologramManagerImpl implements HologramManager { - - private final @NotNull FancyHologramsPlugin plugin; - /** - * The adapter function used to create holograms from hologram data. - */ - private final @NotNull Function adapter; - /** - * A map of hologram names to their corresponding hologram instances. - */ - private final Map holograms = new ConcurrentHashMap<>(); - /** - * Whether holograms are loaded or not - */ - private boolean isLoaded = false; - - public HologramManagerImpl(@NotNull final FancyHologramsPlugin plugin, @NotNull final Function adapter) { - this.plugin = plugin; - this.adapter = adapter; - } - - /** - * @return A read-only collection of loaded holograms. - */ - @Override - public @NotNull - @UnmodifiableView Collection getHolograms() { - return Collections.unmodifiableCollection(this.holograms.values()); - } - - /** - * Returns a read-only view of the currently loaded persistent holograms. - * - * @return A read-only collection of holograms. - */ - @Override - public @NotNull - @UnmodifiableView Collection getPersistentHolograms() { - return this.holograms.values().stream().filter(hologram -> hologram.getData().isPersistent()).toList(); - } - - - /** - * Finds a hologram by name. - * - * @param name The name of the hologram to lookup. - * @return An optional containing the found hologram, or empty if not found. - */ - public @NotNull Optional getHologram(@NotNull final String name) { - return Optional.ofNullable(this.holograms.get(name.toLowerCase(Locale.ROOT))); - } - - /** - * Adds a hologram to this manager. - * - * @param hologram The hologram to add. - */ - public void addHologram(@NotNull final Hologram hologram) { - this.holograms.put(hologram.getData().getName().toLowerCase(Locale.ROOT), hologram); - } - - /** - * Removes a hologram from this manager. - * - * @param hologram The hologram to remove. - */ - public void removeHologram(@NotNull final Hologram hologram) { - removeHologram(hologram.getData().getName()); - } - - /** - * Removes a hologram from this manager by name. - * - * @param name The name of the hologram to remove. - * @return An optional containing the removed hologram, or empty if not found. - */ - public @NotNull Optional removeHologram(@NotNull final String name) { - Optional optionalHologram = Optional.ofNullable(this.holograms.remove(name.toLowerCase(Locale.ROOT))); - - optionalHologram.ifPresent(hologram -> { - for (UUID viewer : hologram.getViewers()) { - Player player = Bukkit.getPlayer(viewer); - if (player != null) { - FancyHologramsPlugin.get().getHologramThread().submit(() -> hologram.forceHideHologram(player)); - } - } - - FancyHologramsPlugin.get().getHologramThread().submit(() -> plugin.getHologramStorage().delete(hologram.getData())); - } - ); - - return optionalHologram; - } - - /** - * Creates a new hologram with the specified hologram data. - * - * @param data The hologram data for the new hologram. - * @return The created hologram. - */ - public @NotNull Hologram create(@NotNull final HologramData data) { - Hologram hologram = this.adapter.apply(data); - hologram.createHologram(); - return hologram; - } - - public void saveHolograms() { - if (!isLoaded) { - return; - } - - plugin.getHologramStorage().saveBatch(getPersistentHolograms().stream().map(Hologram::getData).toList()); - } - - @Override - public void loadHolograms() { - for (World world : Bukkit.getWorlds()) { - loadHolograms(world.getName()); - } - - isLoaded = true; - - FancyHologramsPlugin.get().getFancyLogger().info("Loaded holograms for all loaded worlds"); - } - - public void loadHolograms(String world) { - ImmutableList loaded = ImmutableList.copyOf(plugin.getHologramStorage().loadAll(world)); - List allLoaded = new ArrayList<>(); - - for (HologramData hologramData : loaded) { - Hologram hologram = this.adapter.apply(hologramData); - addHologram(hologram); - allLoaded.add(hologram); - } - - FancyHologramsPlugin.get().getHologramThread().submit(() -> Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded)))); - - FancyHologramsPlugin.get().getFancyLogger().info(String.format("Loaded %d holograms for world %s", loaded.size(), world)); - } - - /** - * Initializes tasks for managing holograms, such as loading and refreshing them. - *

- * This method is intended to be called internally by the plugin. - */ - public void initializeTasks() { - ScheduledExecutorService hologramThread = plugin.getHologramThread(); - hologramThread.submit(() -> { - loadHolograms(); - - hologramThread.scheduleAtFixedRate(() -> { - for (final Hologram hologram : this.plugin.getHologramsManager().getHolograms()) { - for (final Player player : Bukkit.getOnlinePlayers()) { - hologram.forceUpdateShownStateFor(player); - } - } - }, 0, 1, TimeUnit.SECONDS); - }); - - final var updateTimes = CacheBuilder.newBuilder() - .expireAfterAccess(Duration.ofMinutes(5)) - .build(); - - hologramThread.scheduleAtFixedRate(() -> { - final var time = System.currentTimeMillis(); - - for (final var hologram : getHolograms()) { - HologramData data = hologram.getData(); - if (data.hasChanges()) { - hologram.forceUpdate(); - hologram.refreshForViewersInWorld(); - data.setHasChanges(false); - - if (data instanceof TextHologramData) { - updateTimes.put(hologram.getData().getName(), time); - } - } - } - }, 50, 1000, TimeUnit.MILLISECONDS); - - hologramThread.scheduleAtFixedRate(() -> { - final var time = System.currentTimeMillis(); - - for (final var hologram : getHolograms()) { - if (hologram.getData() instanceof TextHologramData textData) { - final var interval = textData.getTextUpdateInterval(); - if (interval < 1) { - continue; // doesn't update - } - - final var lastUpdate = updateTimes.asMap().get(textData.getName()); - if (lastUpdate != null && time < (lastUpdate + interval)) { - continue; - } - - if (lastUpdate == null || time > (lastUpdate + interval)) { - hologram.refreshForViewersInWorld(); - updateTimes.put(textData.getName(), time); - } - } - } - }, 50, 50, TimeUnit.MILLISECONDS); - } - - /** - * Reloads holograms by clearing the existing holograms and loading them again from the plugin's configuration. - */ - public void reloadHolograms() { - unloadHolograms(); - loadHolograms(); - } - - public void unloadHolograms() { - FancyHologramsPlugin.get().getHologramThread().submit(() -> { - List unloaded = new ArrayList<>(); - - for (final var hologram : this.getPersistentHolograms()) { - this.holograms.remove(hologram.getName()); - unloaded.add(hologram); - - for (UUID viewer : hologram.getViewers()) { - Player player = Bukkit.getPlayer(viewer); - if (player != null) { - hologram.forceHideHologram(player); - } - } - } - - Bukkit.getPluginManager().callEvent(new HologramsUnloadedEvent(ImmutableList.copyOf(unloaded))); - }); - } - - public void unloadHolograms(String world) { - final var online = List.copyOf(Bukkit.getOnlinePlayers()); - - FancyHologramsPlugin.get().getHologramThread().submit(() -> { - List h = getPersistentHolograms().stream() - .filter(hologram -> hologram.getData().getLocation().getWorld().getName().equals(world)) - .toList(); - - FancyHologramsPlugin.get().getHologramStorage().saveBatch(h.stream().map(Hologram::getData).toList()); - - for (final Hologram hologram : h) { - this.holograms.remove(hologram.getName()); - online.forEach(hologram::forceHideHologram); - } - - Bukkit.getPluginManager().callEvent(new HologramsUnloadedEvent(ImmutableList.copyOf(h))); - }); - } - - /** - * Syncs a hologram with its linked NPC, if any. - * - * @param hologram The hologram to sync. - */ - public void syncHologramWithNpc(@NotNull final Hologram hologram) { - final var linkedNpcName = hologram.getData().getLinkedNpcName(); - if (linkedNpcName == null) { - return; - } - - final var npc = FancyNpcsPlugin.get().getNpcManager().getNpc(linkedNpcName); - if (npc == null) { - return; - } - - npc.getData().setDisplayName(""); - npc.getData().setShowInTab(false); - npc.updateForAll(); - - final var npcScale = npc.getData().getScale(); - - if(hologram.getData() instanceof DisplayHologramData displayData) { - displayData.setScale(new Vector3f(npcScale)); - } - - final var location = npc.getData().getLocation().clone().add(0, (npc.getEyeHeight() * npcScale) + (0.5 * npcScale), 0); - hologram.getData().setLocation(location); - } -} +//package de.oliver.fancyholograms; +// +//import com.google.common.cache.CacheBuilder; +//import com.google.common.collect.ImmutableList; +//import de.oliver.fancyholograms.api.data.DisplayHologramData; +//import de.oliver.fancyholograms.api.data.HologramData; +//import de.oliver.fancyholograms.api.data.TextHologramData; +//import de.oliver.fancyholograms.api.events.HologramsLoadedEvent; +//import de.oliver.fancyholograms.api.events.HologramsUnloadedEvent; +//import de.oliver.fancyholograms.api.hologram.Hologram; +//import de.oliver.fancyholograms.main.FancyHologramsPlugin; +//import de.oliver.fancynpcs.api.FancyNpcsPlugin; +//import org.bukkit.Bukkit; +//import org.bukkit.World; +//import org.bukkit.entity.Player; +//import org.jetbrains.annotations.NotNull; +//import org.jetbrains.annotations.UnmodifiableView; +//import org.joml.Vector3f; +// +//import java.time.Duration; +//import java.util.*; +//import java.util.concurrent.ConcurrentHashMap; +//import java.util.concurrent.ScheduledExecutorService; +//import java.util.concurrent.TimeUnit; +//import java.util.function.Function; +// +///** +// * The FancyHologramsManager class is responsible for managing holograms in the FancyHolograms plugin. +// * It provides methods for adding, removing, and retrieving holograms, as well as other related operations. +// */ +//@Deprecated(forRemoval = true) +//public final class HologramManagerImpl { +// +// private final @NotNull FancyHologramsPlugin plugin; +// /** +// * The adapter function used to create holograms from hologram data. +// */ +// private final @NotNull Function adapter; +// /** +// * A map of hologram names to their corresponding hologram instances. +// */ +// private final Map holograms = new ConcurrentHashMap<>(); +// /** +// * Whether holograms are loaded or not +// */ +// private boolean isLoaded = false; +// +// public HologramManagerImpl(@NotNull final FancyHologramsPlugin plugin, @NotNull final Function adapter) { +// this.plugin = plugin; +// this.adapter = adapter; +// } +// +// /** +// * @return A read-only collection of loaded holograms. +// */ +// public @NotNull +// @UnmodifiableView Collection getHolograms() { +// return Collections.unmodifiableCollection(this.holograms.values()); +// } +// +// /** +// * Returns a read-only view of the currently loaded persistent holograms. +// * +// * @return A read-only collection of holograms. +// */ +// public @NotNull +// @UnmodifiableView Collection getPersistentHolograms() { +// return this.holograms.values().stream().filter(hologram -> hologram.getData().isPersistent()).toList(); +// } +// +// +// /** +// * Finds a hologram by name. +// * +// * @param name The name of the hologram to lookup. +// * @return An optional containing the found hologram, or empty if not found. +// */ +// public @NotNull Optional getHologram(@NotNull final String name) { +// return Optional.ofNullable(this.holograms.get(name.toLowerCase(Locale.ROOT))); +// } +// +// /** +// * Adds a hologram to this manager. +// * +// * @param hologram The hologram to add. +// */ +// public void addHologram(@NotNull final Hologram hologram) { +// this.holograms.put(hologram.getData().getName().toLowerCase(Locale.ROOT), hologram); +// } +// +// /** +// * Removes a hologram from this manager. +// * +// * @param hologram The hologram to remove. +// */ +// public void removeHologram(@NotNull final Hologram hologram) { +// removeHologram(hologram.getData().getName()); +// } +// +// /** +// * Removes a hologram from this manager by name. +// * +// * @param name The name of the hologram to remove. +// * @return An optional containing the removed hologram, or empty if not found. +// */ +// public @NotNull Optional removeHologram(@NotNull final String name) { +// Optional optionalHologram = Optional.ofNullable(this.holograms.remove(name.toLowerCase(Locale.ROOT))); +// +// optionalHologram.ifPresent(hologram -> { +// for (UUID viewer : hologram.getViewers()) { +// Player player = Bukkit.getPlayer(viewer); +// if (player != null) { +// FancyHologramsPlugin.get().getHologramThread().submit(() -> hologram.forceHideHologram(player)); +// } +// } +// +// FancyHologramsPlugin.get().getHologramThread().submit(() -> plugin.getStorage().delete(hologram.getData())); +// } +// ); +// +// return optionalHologram; +// } +// +// /** +// * Creates a new hologram with the specified hologram data. +// * +// * @param data The hologram data for the new hologram. +// * @return The created hologram. +// */ +// public @NotNull Hologram create(@NotNull final HologramData data) { +// Hologram hologram = this.adapter.apply(data); +// hologram.createHologram(); +// return hologram; +// } +// +// public void saveHolograms() { +// if (!isLoaded) { +// return; +// } +// +// plugin.getStorage().saveBatch(getPersistentHolograms().stream().map(Hologram::getData).toList()); +// } +// +// public void loadHolograms() { +// for (World world : Bukkit.getWorlds()) { +// loadHolograms(world.getName()); +// } +// +// isLoaded = true; +// +// FancyHologramsPlugin.get().getFancyLogger().info("Loaded holograms for all loaded worlds"); +// } +// +// public void loadHolograms(String world) { +// ImmutableList loaded = ImmutableList.copyOf(plugin.getStorage().loadAll(world)); +// List allLoaded = new ArrayList<>(); +// +// for (HologramData hologramData : loaded) { +// Hologram hologram = this.adapter.apply(hologramData); +// addHologram(hologram); +// allLoaded.add(hologram); +// } +// +// FancyHologramsPlugin.get().getHologramThread().submit(() -> Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded)))); +// +// FancyHologramsPlugin.get().getFancyLogger().info(String.format("Loaded %d holograms for world %s", loaded.size(), world)); +// } +// +// /** +// * Initializes tasks for managing holograms, such as loading and refreshing them. +// *

+// * This method is intended to be called internally by the plugin. +// */ +// public void initializeTasks() { +// ScheduledExecutorService hologramThread = plugin.getHologramThread(); +// hologramThread.submit(() -> { +// loadHolograms(); +// +// hologramThread.scheduleAtFixedRate(() -> { +// for (final Hologram hologram : this.plugin.getHologramsManager().getHolograms()) { +// for (final Player player : Bukkit.getOnlinePlayers()) { +// hologram.forceUpdateShownStateFor(player); +// } +// } +// }, 0, 1, TimeUnit.SECONDS); +// }); +// +// final var updateTimes = CacheBuilder.newBuilder() +// .expireAfterAccess(Duration.ofMinutes(5)) +// .build(); +// +// hologramThread.scheduleAtFixedRate(() -> { +// final var time = System.currentTimeMillis(); +// +// for (final var hologram : getHolograms()) { +// HologramData data = hologram.getData(); +// if (data.hasChanges()) { +// hologram.forceUpdate(); +// hologram.refreshForViewersInWorld(); +// data.setHasChanges(false); +// +// if (data instanceof TextHologramData) { +// updateTimes.put(hologram.getData().getName(), time); +// } +// } +// } +// }, 50, 1000, TimeUnit.MILLISECONDS); +// +// hologramThread.scheduleAtFixedRate(() -> { +// final var time = System.currentTimeMillis(); +// +// for (final var hologram : getHolograms()) { +// if (hologram.getData() instanceof TextHologramData textData) { +// final var interval = textData.getTextUpdateInterval(); +// if (interval < 1) { +// continue; // doesn't update +// } +// +// final var lastUpdate = updateTimes.asMap().get(textData.getName()); +// if (lastUpdate != null && time < (lastUpdate + interval)) { +// continue; +// } +// +// if (lastUpdate == null || time > (lastUpdate + interval)) { +// hologram.refreshForViewersInWorld(); +// updateTimes.put(textData.getName(), time); +// } +// } +// } +// }, 50, 50, TimeUnit.MILLISECONDS); +// } +// +// /** +// * Reloads holograms by clearing the existing holograms and loading them again from the plugin's configuration. +// */ +// public void reloadHolograms() { +// unloadHolograms(); +// loadHolograms(); +// } +// +// public void unloadHolograms() { +// FancyHologramsPlugin.get().getHologramThread().submit(() -> { +// List unloaded = new ArrayList<>(); +// +// for (final var hologram : this.getPersistentHolograms()) { +// this.holograms.remove(hologram.getName()); +// unloaded.add(hologram); +// +// for (UUID viewer : hologram.getViewers()) { +// Player player = Bukkit.getPlayer(viewer); +// if (player != null) { +// hologram.forceHideHologram(player); +// } +// } +// } +// +// Bukkit.getPluginManager().callEvent(new HologramsUnloadedEvent(ImmutableList.copyOf(unloaded))); +// }); +// } +// +// public void unloadHolograms(String world) { +// final var online = List.copyOf(Bukkit.getOnlinePlayers()); +// +// FancyHologramsPlugin.get().getHologramThread().submit(() -> { +// List h = getPersistentHolograms().stream() +// .filter(hologram -> hologram.getData().getLocation().getWorld().getName().equals(world)) +// .toList(); +// +// FancyHologramsPlugin.get().getStorage().saveBatch(h.stream().map(Hologram::getData).toList()); +// +// for (final Hologram hologram : h) { +// this.holograms.remove(hologram.getName()); +// online.forEach(hologram::forceHideHologram); +// } +// +// Bukkit.getPluginManager().callEvent(new HologramsUnloadedEvent(ImmutableList.copyOf(h))); +// }); +// } +// +// /** +// * Syncs a hologram with its linked NPC, if any. +// * +// * @param hologram The hologram to sync. +// */ +// public void syncHologramWithNpc(@NotNull final Hologram hologram) { +// final var linkedNpcName = hologram.getData().getLinkedNpcName(); +// if (linkedNpcName == null) { +// return; +// } +// +// final var npc = FancyNpcsPlugin.get().getNpcManager().getNpc(linkedNpcName); +// if (npc == null) { +// return; +// } +// +// npc.getData().setDisplayName(""); +// npc.getData().setShowInTab(false); +// npc.updateForAll(); +// +// final var npcScale = npc.getData().getScale(); +// +// if(hologram.getData() instanceof DisplayHologramData displayData) { +// displayData.setScale(new Vector3f(npcScale)); +// } +// +// final var location = npc.getData().getLocation().clone().add(0, (npc.getEyeHeight() * npcScale) + (0.5 * npcScale), 0); +// hologram.getData().setLocation(location); +// } +//} diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/BackgroundCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/BackgroundCMD.java index 304331a9..ff12f004 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/BackgroundCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/BackgroundCMD.java @@ -82,7 +82,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setBackground(copied.getBackground()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed background color"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/BillboardCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/BillboardCMD.java index 6e76b720..6e2ae09b 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/BillboardCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/BillboardCMD.java @@ -64,7 +64,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ displayData.setBillboard(copied.getBillboard()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed the billboard to " + StringUtils.capitalize(billboard.name().toLowerCase(Locale.ROOT))); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/BlockCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/BlockCMD.java index 42c4e5dc..02cba224 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/BlockCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/BlockCMD.java @@ -59,7 +59,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ blockData.setBlock(block); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Set block to '" + block.name() + "'"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/BrightnessCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/BrightnessCMD.java index 6dbd9b81..61cbdad9 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/BrightnessCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/BrightnessCMD.java @@ -62,7 +62,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ displayData.setBrightness(new Display.Brightness(blockBrightness, skyBrightness)); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed " + brightnessType.toLowerCase() + " brightness to " + brightnessValue); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/CenterCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/CenterCMD.java index 0e1801fb..77c9275b 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/CenterCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/CenterCMD.java @@ -37,7 +37,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ hologram.getData().setLocation(location); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Centered the hologram to %s/%s/%s %s\u00B0 %s\u00B0".formatted( diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/CopyCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/CopyCMD.java index 1c715d54..213c8a80 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/CopyCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/CopyCMD.java @@ -73,7 +73,7 @@ public boolean run(@NotNull CommandSender sender, @Nullable Hologram hologram, @ FancyHologramsPlugin.get().getHologramsManager().addHologram(copy); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(sender, "Copied the hologram"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertAfterCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertAfterCMD.java index 1370326f..65235495 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertAfterCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertAfterCMD.java @@ -71,7 +71,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setText(copied.getText()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Inserted line"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertBeforeCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertBeforeCMD.java index c6f28617..63e6b238 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertBeforeCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/InsertBeforeCMD.java @@ -73,7 +73,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setText(copied.getText()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Inserted line"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/ItemCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/ItemCMD.java index 9094b2c1..2cf63798 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/ItemCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/ItemCMD.java @@ -67,7 +67,7 @@ public boolean run(@NotNull CommandSender sender, @Nullable Hologram hologram, @ itemData.setItemStack(item); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Set the item to '" + item.getType().name() + "'"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/LinkWithNpcCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/LinkWithNpcCMD.java index 6adf0769..44d56bf9 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/LinkWithNpcCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/LinkWithNpcCMD.java @@ -51,7 +51,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ FancyHologramsPlugin.get().getHologramsManager().syncHologramWithNpc(hologram); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Linked hologram with NPC"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/MoveHereCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/MoveHereCMD.java index 33a06a2b..843b98cd 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/MoveHereCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/MoveHereCMD.java @@ -40,7 +40,7 @@ public static boolean setLocation(Player player, Hologram hologram, Location loc hologram.getData().setLocation(copied.getLocation()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Moved the hologram to %s/%s/%s %s\u00B0 %s\u00B0".formatted( diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/ScaleCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/ScaleCMD.java index b830a8a3..3e665950 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/ScaleCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/ScaleCMD.java @@ -71,7 +71,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ copied.getScale().z())); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed scale to " + scaleX + ", " + scaleY + ", " + scaleZ); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/SeeThroughCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/SeeThroughCMD.java index 511516f2..1b75f611 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/SeeThroughCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/SeeThroughCMD.java @@ -65,7 +65,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setSeeThrough(copied.isSeeThrough()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed see through"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/SetLineCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/SetLineCMD.java index 179fe0a6..630a1cc8 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/SetLineCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/SetLineCMD.java @@ -49,7 +49,7 @@ public static boolean setLine(CommandSender player, Hologram hologram, int index textData.setText(copied.getText()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed text for line " + (Math.min(index, lines.size() - 1) + 1)); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowRadiusCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowRadiusCMD.java index 4185a9b7..429ab600 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowRadiusCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowRadiusCMD.java @@ -61,7 +61,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ displayData.setShadowRadius(copied.getShadowRadius()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed shadow radius"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowStrengthCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowStrengthCMD.java index c4700e5b..221e869f 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowStrengthCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/ShadowStrengthCMD.java @@ -61,7 +61,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ displayData.setShadowStrength(copied.getShadowStrength()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed shadow strength"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/TextAlignmentCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/TextAlignmentCMD.java index 9589c362..0d26a247 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/TextAlignmentCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/TextAlignmentCMD.java @@ -63,7 +63,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setTextAlignment(((TextHologramData) copied).getTextAlignment()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed text alignment"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/TextShadowCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/TextShadowCMD.java index 99c08ce3..6d8b2663 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/TextShadowCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/TextShadowCMD.java @@ -65,7 +65,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setTextShadow(copied.hasTextShadow()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed text shadow"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/TranslateCommand.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/TranslateCommand.java index 485c30b5..a8b1effd 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/TranslateCommand.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/TranslateCommand.java @@ -71,7 +71,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ copied.getTranslation().z())); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed translation to " + translateX + ", " + translateY + ", " + translateZ); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/UnlinkWithNpcCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/UnlinkWithNpcCMD.java index 0a214f09..c1e56469 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/UnlinkWithNpcCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/UnlinkWithNpcCMD.java @@ -48,7 +48,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ } if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Unlinked hologram with NPC"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/UpdateTextIntervalCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/UpdateTextIntervalCMD.java index 025c73bf..da44c899 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/UpdateTextIntervalCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/UpdateTextIntervalCMD.java @@ -88,7 +88,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ textData.setTextUpdateInterval(copied.getTextUpdateInterval()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed the text update interval"); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java index 5b9110c3..fe0b9fd2 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityCMD.java @@ -47,7 +47,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ hologram.getData().setVisibility(copied.getVisibility()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed visibility to " + visibility); diff --git a/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityDistanceCMD.java b/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityDistanceCMD.java index db5222ae..4e737cd6 100644 --- a/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityDistanceCMD.java +++ b/src/main/java/de/oliver/fancyholograms/commands/hologram/VisibilityDistanceCMD.java @@ -59,7 +59,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @ hologram.getData().setVisibilityDistance(copied.getVisibilityDistance()); if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) { - FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData()); + FancyHologramsPlugin.get().getStorage().save(hologram.getData()); } MessageHelper.success(player, "Changed visibility distance"); diff --git a/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java b/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java index 61ee0864..1b95444b 100644 --- a/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java +++ b/src/main/java/de/oliver/fancyholograms/main/FancyHologramsPlugin.java @@ -6,10 +6,10 @@ import de.oliver.fancyanalytics.logger.appender.Appender; import de.oliver.fancyanalytics.logger.appender.ConsoleAppender; import de.oliver.fancyanalytics.logger.appender.JsonAppender; -import de.oliver.fancyholograms.HologramManagerImpl; import de.oliver.fancyholograms.api.FancyHolograms; import de.oliver.fancyholograms.api.HologramConfiguration; -import de.oliver.fancyholograms.api.HologramManager; +import de.oliver.fancyholograms.api.HologramController; +import de.oliver.fancyholograms.api.HologramRegistry; import de.oliver.fancyholograms.api.data.HologramData; import de.oliver.fancyholograms.api.hologram.Hologram; import de.oliver.fancyholograms.commands.FancyHologramsCMD; @@ -17,6 +17,7 @@ import de.oliver.fancyholograms.commands.HologramCMD; import de.oliver.fancyholograms.config.FHConfiguration; import de.oliver.fancyholograms.config.FHFeatureFlags; +import de.oliver.fancyholograms.controller.HologramControllerImpl; import de.oliver.fancyholograms.converter.FHConversionRegistry; import de.oliver.fancyholograms.hologram.version.*; import de.oliver.fancyholograms.listeners.BedrockPlayerListener; @@ -24,6 +25,7 @@ import de.oliver.fancyholograms.listeners.PlayerListener; import de.oliver.fancyholograms.listeners.WorldListener; import de.oliver.fancyholograms.metrics.FHMetrics; +import de.oliver.fancyholograms.registry.HologramRegistryImpl; import de.oliver.fancyholograms.storage.HologramStorage; import de.oliver.fancyholograms.storage.YamlHologramStorage; import de.oliver.fancyholograms.util.PluginUtils; @@ -38,7 +40,6 @@ import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.plugin.java.JavaPlugin; -import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -68,9 +69,10 @@ public final class FancyHologramsPlugin extends JavaPlugin implements FancyHolog private final ExecutorService storageThread; private final HologramConfiguration configuration; - private HologramStorage hologramStorage; - private HologramManagerImpl hologramsManager; + private HologramStorage storage; + private HologramRegistry registry; + private HologramController controller; public FancyHologramsPlugin() { INSTANCE = this; @@ -133,7 +135,9 @@ public void onLoad() { fancyLogger.setCurrentLevel(logLevel); IFancySitula.LOGGER.setCurrentLevel(logLevel); - hologramStorage = new YamlHologramStorage(); + storage = new YamlHologramStorage(); + registry = new HologramRegistryImpl(); + controller = new HologramControllerImpl(); if (!ServerSoftware.isPaper()) { fancyLogger.warn(""" @@ -161,8 +165,6 @@ Please update the server to one of (%s). return; } - hologramsManager = new HologramManagerImpl(this, adapter); - fancyLogger.info("Successfully loaded FancyHolograms version %s".formatted(getDescription().getVersion())); } @@ -181,13 +183,14 @@ public void onEnable() { metrics.register(); metrics.registerLegacy(); - hologramsManager.initializeTasks(); - if (configuration.isAutosaveEnabled()) { getHologramThread().scheduleAtFixedRate(() -> { - if (hologramsManager != null) { - hologramsManager.saveHolograms(); - } + List toSave = registry.getAllPersistent() + .stream() + .map(Hologram::getData) + .toList(); + + storage.saveBatch(toSave); }, configuration.getAutosaveInterval(), configuration.getAutosaveInterval() * 60L, TimeUnit.SECONDS); } @@ -198,7 +201,6 @@ public void onEnable() { @Override public void onDisable() { - hologramsManager.saveHolograms(); hologramThread.shutdown(); storageThread.shutdown(); @@ -294,14 +296,14 @@ public FHMetrics getMetrics() { return versionConfig; } - @ApiStatus.Internal - public @NotNull HologramManagerImpl getHologramsManager() { - return Objects.requireNonNull(this.hologramsManager, "plugin is not initialized"); + @Override + public HologramController getController() { + return controller; } @Override - public HologramManager getHologramManager() { - return Objects.requireNonNull(this.hologramsManager, "plugin is not initialized"); + public HologramRegistry getRegistry() { + return registry; } @Override @@ -309,8 +311,8 @@ public HologramConfiguration getHologramConfiguration() { return configuration; } - public HologramStorage getHologramStorage() { - return hologramStorage; + public HologramStorage getStorage() { + return storage; } public ScheduledExecutorService getHologramThread() { diff --git a/src/main/java/de/oliver/fancyholograms/metrics/FHMetrics.java b/src/main/java/de/oliver/fancyholograms/metrics/FHMetrics.java index 086ea98a..02513a0a 100644 --- a/src/main/java/de/oliver/fancyholograms/metrics/FHMetrics.java +++ b/src/main/java/de/oliver/fancyholograms/metrics/FHMetrics.java @@ -3,7 +3,6 @@ import de.oliver.fancyanalytics.api.FancyAnalyticsAPI; import de.oliver.fancyanalytics.api.metrics.MetricSupplier; import de.oliver.fancyanalytics.logger.ExtendedFancyLogger; -import de.oliver.fancyholograms.api.HologramManager; import de.oliver.fancyholograms.config.FHFeatureFlags; import de.oliver.fancyholograms.main.FancyHologramsPlugin; import de.oliver.fancylib.Metrics;