Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 27, 2024
1 parent 77bf846 commit a4bcd28
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import de.oliver.fancyholograms.main.FancyHologramsPlugin;
import de.oliver.fancyholograms.util.Constants;
import de.oliver.fancylib.MessageHelper;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -38,12 +40,20 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No

switch (args[0].toLowerCase(Locale.ROOT)) {
case "save" -> {
this.plugin.getHologramsManager().saveHolograms();
this.plugin.savePersistentHolograms();
MessageHelper.success(sender, "Saved all holograms");
}
case "reload" -> {
this.plugin.getHologramConfiguration().reload(plugin);
this.plugin.getHologramsManager().reloadHolograms();

this.plugin.getRegistry().clear();
for (World world : Bukkit.getWorlds()) {
Collection<HologramData> hologramData = this.plugin.getStorage().loadAll(world.getName());
for (HologramData data : hologramData) {
Hologram hologram = this.plugin.getHologramFactory().apply(data);
this.plugin.getRegistry().register(hologram);
}
}

MessageHelper.success(sender, "Reloaded config and holograms");
}
Expand Down Expand Up @@ -78,11 +88,11 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
final List<HologramData> holograms = converter.convert(session);

for (final HologramData data : holograms) {
final Hologram hologram = this.plugin.getHologramsManager().create(data);
this.plugin.getHologramsManager().addHologram(hologram);
final Hologram hologram = this.plugin.getHologramFactory().apply(data);
this.plugin.getRegistry().register(hologram);
}

this.plugin.getHologramsManager().saveHolograms();
this.plugin.savePersistentHolograms();
// TODO(matt): Give options to delete them or teleport and a list of IDs please

MessageHelper.success(sender, String.format("Converted successfully, produced %s total holograms!", holograms.size()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
.setScale(new Vector3f(.5f, .5f, .5f))
.setVisibilityDistance(100);

Hologram hologram = this.plugin.getHologramsManager().create(textData);
hologram.createHologram();
hologram.updateShownStateFor(p);
Hologram hologram = this.plugin.getHologramFactory().apply(textData);
hologram.spawnTo(p);
}
}

Expand All @@ -93,9 +92,8 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
.setShadowStrength(3)
.setVisibilityDistance(100);

Hologram hologram = this.plugin.getHologramsManager().create(textData);
hologram.createHologram();
hologram.updateShownStateFor(p);
Hologram hologram = this.plugin.getHologramFactory().apply(textData);
hologram.spawnTo(p);
}

return false;
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/de/oliver/fancyholograms/commands/HologramCMD.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
return new NearbyCMD().run(sender, null, args);
}

final var hologram = this.plugin.getHologramsManager().getHologram(args[1]).orElse(null);
final var hologram = this.plugin.getRegistry().get(args[1]).orElse(null);
if (hologram == null) {
MessageHelper.error(sender, "Could not find hologram: '" + args[1] + "'");
return false;
Expand All @@ -102,10 +102,11 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No

if (updated) {
if (sender instanceof Player p) {
hologram.forceUpdate();
hologram.refreshHologram(p);
plugin.getController().refreshHologram(hologram, p);
}
hologram.queueUpdate();

//TODO: idk
// hologram.queueUpdate();
}

yield updated;
Expand Down Expand Up @@ -138,10 +139,14 @@ public boolean execute(@NotNull CommandSender sender, @NotNull String label, @No
return Collections.emptyList();
}

return this.plugin.getHologramsManager().getPersistentHolograms().stream().map(hologram -> hologram.getData().getName()).filter(input -> input.toLowerCase().startsWith(args[1].toLowerCase(Locale.ROOT))).toList();
return this.plugin.getRegistry().getAllPersistent()
.stream()
.map(hologram -> hologram.getData().getName())
.filter(input -> input.toLowerCase().startsWith(args[1].toLowerCase(Locale.ROOT)))
.toList();
}

final var hologram = this.plugin.getHologramsManager().getHologram(args[1]).orElse(null);
final var hologram = this.plugin.getRegistry().get(args[1]).orElse(null);
if (hologram == null) {
return Collections.emptyList();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,11 @@ public void onEnable() {
metrics.registerLegacy();

if (configuration.isAutosaveEnabled()) {
getHologramThread().scheduleAtFixedRate(() -> {
List<HologramData> toSave = registry.getAllPersistent()
.stream()
.map(Hologram::getData)
.toList();

storage.saveBatch(toSave);
}, configuration.getAutosaveInterval(), configuration.getAutosaveInterval() * 60L, TimeUnit.SECONDS);
getHologramThread().scheduleAtFixedRate(
this::savePersistentHolograms,
configuration.getAutosaveInterval(),
configuration.getAutosaveInterval() * 60L, TimeUnit.SECONDS
);
}

FHConversionRegistry.registerBuiltInConverters();
Expand Down Expand Up @@ -276,6 +273,15 @@ Please update to the newest version (%s).
});
}

public void savePersistentHolograms() {
List<HologramData> toSave = registry.getAllPersistent()
.stream()
.map(Hologram::getData)
.toList();

storage.saveBatch(toSave);
}

@Override
public JavaPlugin getPlugin() {
return INSTANCE;
Expand Down

0 comments on commit a4bcd28

Please sign in to comment.