Skip to content

Commit

Permalink
Add json models
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Dec 28, 2024
1 parent 1d69a14 commit 0609bc6
Show file tree
Hide file tree
Showing 8 changed files with 138 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package de.oliver.fancyholograms.storage.json;

import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.storage.json.model.*;

public class JsonAdapter {

public static JsonDataUnion toJson(TextHologramData data) {
JsonHologramData hologramData = new JsonHologramData(
data.getName(),
data.getType(),
new JsonLocation(
data.getLocation().getWorld().getName(),
data.getLocation().getX(),
data.getLocation().getY(),
data.getLocation().getZ(),
data.getLocation().getYaw(),
data.getLocation().getPitch()
),
data.getVisibilityDistance(),
data.getVisibility(),
data.getLinkedNpcName()
);

JsonDisplayHologramData displayHologramData = new JsonDisplayHologramData(
new JsonVec3f(
data.getScale().x(),
data.getScale().y(),
data.getScale().z()
),
new JsonVec3f(
data.getTranslation().x(),
data.getTranslation().y(),
data.getTranslation().z()
),
data.getShadowRadius(),
data.getShadowStrength(),
data.getBrightness().getBlockLight(),
data.getBrightness().getSkyLight(),
data.getBillboard()
);

JsonTextHologramData textHologramData = new JsonTextHologramData(
data.getText(),
data.hasTextShadow(),
data.isSeeThrough(),
data.getTextAlignment(),
data.getTextUpdateInterval(),
data.getBackground().toString()
);

return new JsonDataUnion(
hologramData,
displayHologramData,
textHologramData
);
}

public static HologramData fromJson(JsonDataUnion data) {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package de.oliver.fancyholograms.storage;
package de.oliver.fancyholograms.storage.json;

import de.oliver.fancyholograms.api.FancyHolograms;
import de.oliver.fancyholograms.api.data.BlockHologramData;
import de.oliver.fancyholograms.api.data.HologramData;
import de.oliver.fancyholograms.api.data.ItemHologramData;
import de.oliver.fancyholograms.api.data.TextHologramData;
import de.oliver.fancyholograms.storage.HologramStorage;
import de.oliver.fancylib.jdb.JDB;

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

public class JsonStorage implements HologramStorage{
public class JsonStorage implements HologramStorage {

private final JDB jdb;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.oliver.fancyholograms.storage.json.model;

public record JsonDataUnion(
JsonHologramData hologram_data,
JsonDisplayHologramData display_hologram_data,
JsonTextHologramData text_hologram_data
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.oliver.fancyholograms.storage.json.model;

import org.bukkit.entity.Display;

public record JsonDisplayHologramData(
JsonVec3f scale,
JsonVec3f translation,
float shadow_radius,
float shadow_strength,
int block_brightness,
int sky_brightness,
Display.Billboard billboard
) {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.oliver.fancyholograms.storage.json.model;

import de.oliver.fancyholograms.api.data.property.Visibility;
import de.oliver.fancyholograms.api.hologram.HologramType;

public record JsonHologramData(
String name,
HologramType type,
JsonLocation location,
int visibilityDistance,
Visibility visibility,
String linkedNpcName
) {
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package de.oliver.fancyholograms.storage.json.model;

public record JsonLocation(
String world,
double x,
double y,
double z,
float yaw,
float pitch
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.oliver.fancyholograms.storage.json.model;

import org.bukkit.entity.TextDisplay;

import java.util.List;

public record JsonTextHologramData(
List<String> text,
boolean text_shadow,
boolean see_through,
TextDisplay.TextAlignment text_alignment,
int text_update_interval,
String background_color
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.oliver.fancyholograms.storage.json.model;

public record JsonVec3f(
float x,
float y,
float z
) {
}

0 comments on commit 0609bc6

Please sign in to comment.