Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 27, 2024
1 parent afb64bb commit 7df28ce
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 83 deletions.
30 changes: 14 additions & 16 deletions src/main/java/de/oliver/fancyholograms/HologramManagerImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void removeHologram(@NotNull final Hologram hologram) {
}
}

FancyHologramsPlugin.get().getHologramThread().submit(() -> plugin.getHologramStorage().delete(hologram));
FancyHologramsPlugin.get().getHologramThread().submit(() -> plugin.getHologramStorage().delete(hologram.getData()));
}
);

Expand All @@ -140,33 +140,31 @@ public void saveHolograms() {
return;
}

plugin.getHologramStorage().saveBatch(getPersistentHolograms(), false);
plugin.getHologramStorage().saveBatch(getPersistentHolograms().stream().map(Hologram::getData).toList());
}

@Override
public void loadHolograms() {
List<Hologram> allLoaded = new ArrayList<>();

for (World world : Bukkit.getWorlds()) {
Collection<Hologram> loaded = plugin.getHologramStorage().loadAll(world.getName());
loaded.forEach(this::addHologram);

allLoaded.addAll(loaded);
loadHolograms(world.getName());
}
isLoaded = true;

FancyHologramsPlugin.get().getHologramThread().submit(() -> Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(allLoaded))));
isLoaded = true;

FancyHologramsPlugin.get().getFancyLogger().info(String.format("Loaded %d holograms for all loaded worlds", allLoaded.size()));
FancyHologramsPlugin.get().getFancyLogger().info("Loaded holograms for all loaded worlds");
}

public void loadHolograms(String world) {
ImmutableList<Hologram> loaded = ImmutableList.copyOf(plugin.getHologramStorage().loadAll(world));
loaded.forEach(this::addHologram);
ImmutableList<HologramData> loaded = ImmutableList.copyOf(plugin.getHologramStorage().loadAll(world));
List<Hologram> allLoaded = new ArrayList<>();

isLoaded = true;
for (HologramData hologramData : loaded) {
Hologram hologram = this.adapter.apply(hologramData);
addHologram(hologram);
allLoaded.add(hologram);
}

Bukkit.getPluginManager().callEvent(new HologramsLoadedEvent(ImmutableList.copyOf(loaded)));
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));
}
Expand Down Expand Up @@ -271,7 +269,7 @@ public void unloadHolograms(String world) {
.filter(hologram -> hologram.getData().getLocation().getWorld().getName().equals(world))
.toList();

FancyHologramsPlugin.get().getHologramStorage().saveBatch(h, false);
FancyHologramsPlugin.get().getHologramStorage().saveBatch(h.stream().map(Hologram::getData).toList());

for (final Hologram hologram : h) {
this.holograms.remove(hologram.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed background color");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed the billboard to " + StringUtils.capitalize(billboard.name().toLowerCase(Locale.ROOT)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Set block to '" + block.name() + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed " + brightnessType.toLowerCase() + " brightness to " + brightnessValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Centered the hologram to %s/%s/%s %s\u00B0 %s\u00B0".formatted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(sender, "Copied the hologram");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Inserted line");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Inserted line");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Set the item to '" + item.getType().name() + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Linked hologram with NPC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Moved the hologram to %s/%s/%s %s\u00B0 %s\u00B0".formatted(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed scale to " + scaleX + ", " + scaleY + ", " + scaleZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed see through");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed text for line " + (Math.min(index, lines.size() - 1) + 1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed shadow radius");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed shadow strength");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed text alignment");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed text shadow");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed translation to " + translateX + ", " + translateY + ", " + translateZ);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public boolean run(@NotNull CommandSender player, @Nullable Hologram hologram, @
}

if (FancyHologramsPlugin.get().getHologramConfiguration().isSaveOnChangedEnabled()) {
FancyHologramsPlugin.get().getHologramStorage().save(hologram);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Unlinked hologram with NPC");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed the text update interval");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed visibility to " + visibility);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
FancyHologramsPlugin.get().getHologramStorage().save(hologram.getData());
}

MessageHelper.success(player, "Changed visibility distance");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import de.oliver.fancyholograms.listeners.WorldListener;
import de.oliver.fancyholograms.metrics.FHMetrics;
import de.oliver.fancyholograms.storage.HologramStorage;
import de.oliver.fancyholograms.storage.YamlHologramStorage;
import de.oliver.fancyholograms.storage.JsonStorage;
import de.oliver.fancyholograms.util.PluginUtils;
import de.oliver.fancylib.FancyLib;
import de.oliver.fancylib.VersionConfig;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void onLoad() {
fancyLogger.setCurrentLevel(logLevel);
IFancySitula.LOGGER.setCurrentLevel(logLevel);

hologramStorage = new YamlHologramStorage();
hologramStorage = new JsonStorage();

if (!ServerSoftware.isPaper()) {
fancyLogger.warn("""
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.oliver.fancyholograms.storage;

import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancyholograms.api.data.HologramData;

import java.util.Collection;

Expand All @@ -10,36 +10,28 @@ public interface HologramStorage {
* Saves a collection of holograms.
*
* @param holograms The holograms to save.
* @param override Whether to override existing holograms.
*/
void saveBatch(Collection<Hologram> holograms, boolean override);
void saveBatch(Collection<HologramData> holograms);

/**
* Saves a hologram.
*
* @param hologram The hologram to save.
*/
void save(Hologram hologram);
void save(HologramData hologram);

/**
* Deletes a hologram.
*
* @param hologram The hologram to delete.
*/
void delete(Hologram hologram);

/**
* Loads all holograms from all worlds
*
* @return A collection of all loaded holograms.
*/
Collection<Hologram> loadAll();
void delete(HologramData hologram);

/**
* Loads all holograms from a specific world
*
* @param world The world to load the holograms from.
* @return A collection of all loaded holograms.
*/
Collection<Hologram> loadAll(String world);
Collection<HologramData> loadAll(String world);
}
Loading

0 comments on commit 7df28ce

Please sign in to comment.