-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b4ad91
commit afb64bb
Showing
4 changed files
with
76 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/de/oliver/fancyholograms/storage/JsonStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/de/oliver/fancyholograms/storage/StorageType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
|
||
} |