Skip to content

Commit

Permalink
json storage
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 27, 2024
1 parent 4b4ad91 commit afb64bb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ public FancyHologramsPlugin() {
JsonAppender jsonAppender = new JsonAppender(false, false, true, logsFile.getPath());
fancyLogger = new ExtendedFancyLogger("FancyHolograms", LogLevel.INFO, List.of(consoleAppender, jsonAppender), new ArrayList<>());

metrics = new FHMetrics();

versionFetcher = new MasterVersionFetcher("FancyHolograms");
versionConfig = new VersionConfig(this, versionFetcher);

metrics = new FHMetrics();

hologramThread = Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setNameFormat("FancyHolograms-Hologram")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ public class FHMetrics {

public FHMetrics() {
logger = FancyHologramsPlugin.get().getFancyLogger();
isDevelopmentBuild = !FancyHologramsPlugin.get().getVersionConfig().getBuild().equalsIgnoreCase("undefined");
}

public void register() {
isDevelopmentBuild = !FancyHologramsPlugin.get().getVersionConfig().getBuild().equalsIgnoreCase("undefined");

fancyAnalytics = new FancyAnalyticsAPI("3b77bd59-2b01-46f2-b3aa-a9584401797f", "E2gW5zc2ZTk1OGFkNGY2ZDQ0ODlM6San");
fancyAnalytics.getConfig().setDisableLogging(true);

Expand Down
64 changes: 64 additions & 0 deletions src/main/java/de/oliver/fancyholograms/storage/JsonStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package de.oliver.fancyholograms.storage;

import de.oliver.fancyholograms.api.FancyHolograms;
import de.oliver.fancyholograms.api.hologram.Hologram;
import de.oliver.fancylib.jdb.JDB;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;

public class JsonStorage implements HologramStorage{

private final JDB jdb;

public JsonStorage() {
this.jdb = new JDB("data/holograms");
}

@Override
public void saveBatch(Collection<Hologram> holograms, boolean override) {
for (Hologram hologram : holograms) {
save(hologram);
}
}

@Override
public void save(Hologram hologram) {
try {
jdb.set("worlds/" + hologram.getData().getLocation().getWorld().getName() + "/" + hologram.getData().getName(), hologram);
} catch (IOException e) {
FancyHolograms.get().getFancyLogger().error("Failed to save hologram " + hologram.getData().getName());
FancyHolograms.get().getFancyLogger().error(e);
}
}

@Override
public void delete(Hologram hologram) {
jdb.delete("worlds/" + hologram.getData().getLocation().getWorld().getName() + "/" + hologram.getData().getName());
}

@Override
public Collection<Hologram> loadAll() {
try {
return jdb.getAll("worlds", Hologram.class);
} catch (IOException e) {
FancyHolograms.get().getFancyLogger().error("Failed to load all holograms");
FancyHolograms.get().getFancyLogger().error(e);
}

return new ArrayList<>();
}

@Override
public Collection<Hologram> loadAll(String world) {
try {
return jdb.getAll("worlds/"+world, Hologram.class);
} catch (IOException e) {
FancyHolograms.get().getFancyLogger().error("Failed to load all holograms from world " + world);
FancyHolograms.get().getFancyLogger().error(e);
}

return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.oliver.fancyholograms.storage;

public enum StorageType {

@Deprecated YAML,
JSON,

}

0 comments on commit afb64bb

Please sign in to comment.