mirror of
https://github.com/FancyInnovations/FancyPlugins.git
synced 2025-12-06 07:43:36 +00:00
fancyholograms-v3: JSON Storage improvements
This commit is contained in:
@@ -88,6 +88,16 @@ public class TextHologramData extends DisplayHologramData {
|
||||
return this;
|
||||
}
|
||||
|
||||
public TextHologramData setBackground(String background) {
|
||||
if (background == null || background.equalsIgnoreCase("")) {
|
||||
return this;
|
||||
}
|
||||
|
||||
String hex = background.substring(1);
|
||||
int argb = (int) Long.parseLong(hex, 16);
|
||||
return setBackground(Color.fromARGB(argb));
|
||||
}
|
||||
|
||||
public TextDisplay.TextAlignment getTextAlignment() {
|
||||
return textAlignment;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,12 @@ package de.oliver.fancyholograms.storage.json;
|
||||
|
||||
import de.oliver.fancyholograms.api.data.*;
|
||||
import de.oliver.fancyholograms.storage.json.model.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Display;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class JsonAdapter {
|
||||
|
||||
@@ -52,7 +58,7 @@ public class JsonAdapter {
|
||||
data.isSeeThrough(),
|
||||
data.getTextAlignment(),
|
||||
data.getTextUpdateInterval(),
|
||||
data.getBackground() == null ? "" : data.getBackground().toString()
|
||||
data.getBackground() == null ? "" : "#"+Integer.toHexString(data.getBackground().asARGB())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -111,6 +117,73 @@ public class JsonAdapter {
|
||||
}
|
||||
|
||||
public static HologramData fromJson(JsonDataUnion data) {
|
||||
return null;
|
||||
Location loc = new Location(
|
||||
Bukkit.getWorld(data.hologram_data().location().world()),
|
||||
data.hologram_data().location().x(),
|
||||
data.hologram_data().location().y(),
|
||||
data.hologram_data().location().z()
|
||||
);
|
||||
Vector3f scale = new Vector3f(
|
||||
data.display_data().scale().x(),
|
||||
data.display_data().scale().y(),
|
||||
data.display_data().scale().z()
|
||||
);
|
||||
Vector3f translation = new Vector3f(
|
||||
data.display_data().translation().x(),
|
||||
data.display_data().translation().y(),
|
||||
data.display_data().translation().z()
|
||||
);
|
||||
|
||||
Display.Brightness brightness = null;
|
||||
if (data.display_data().brightness() != null && data.display_data().brightness().sky_light() != null) {
|
||||
brightness = new Display.Brightness(
|
||||
data.display_data().brightness().block_light(),
|
||||
data.display_data().brightness().sky_light()
|
||||
);
|
||||
}
|
||||
|
||||
HologramData hologramData = switch (data.hologram_data().type()) {
|
||||
case TEXT -> new TextHologramData(data.hologram_data().name(), loc)
|
||||
.setText(data.text_data().text()) // text data
|
||||
.setBackground(data.text_data().background_color())
|
||||
.setTextAlignment(data.text_data().text_alignment())
|
||||
.setTextShadow(data.text_data().text_shadow())
|
||||
.setSeeThrough(data.text_data().see_through())
|
||||
.setTextUpdateInterval(data.text_data().text_update_interval())
|
||||
.setBillboard(data.display_data().billboard()) // display data
|
||||
.setScale(scale)
|
||||
.setTranslation(translation)
|
||||
.setBrightness(brightness)
|
||||
.setShadowRadius(data.display_data().shadow_radius())
|
||||
.setShadowStrength(data.display_data().shadow_strength())
|
||||
.setVisibilityDistance(data.hologram_data().visibilityDistance()) // hologram data
|
||||
.setVisibility(data.hologram_data().visibility())
|
||||
.setLinkedNpcName(data.hologram_data().linkedNpcName());
|
||||
|
||||
case ITEM -> new ItemHologramData(data.hologram_data().name(), loc)
|
||||
.setItemStack(ItemStack.deserializeBytes(data.item_data().item().getBytes())) // item data
|
||||
.setBillboard(data.display_data().billboard()) // display data
|
||||
.setScale(scale)
|
||||
.setTranslation(translation)
|
||||
.setBrightness(brightness)
|
||||
.setShadowRadius(data.display_data().shadow_radius())
|
||||
.setShadowStrength(data.display_data().shadow_strength())
|
||||
.setVisibilityDistance(data.hologram_data().visibilityDistance()) // hologram data
|
||||
.setVisibility(data.hologram_data().visibility())
|
||||
.setLinkedNpcName(data.hologram_data().linkedNpcName());
|
||||
case BLOCK -> new BlockHologramData(data.hologram_data().name(), loc)
|
||||
.setBlock(Material.getMaterial(data.block_data().block_material())) // block data
|
||||
.setBillboard(data.display_data().billboard()) // display data
|
||||
.setScale(scale)
|
||||
.setTranslation(translation)
|
||||
.setBrightness(brightness)
|
||||
.setShadowRadius(data.display_data().shadow_radius())
|
||||
.setShadowStrength(data.display_data().shadow_strength())
|
||||
.setVisibilityDistance(data.hologram_data().visibilityDistance()) // hologram data
|
||||
.setVisibility(data.hologram_data().visibility())
|
||||
.setLinkedNpcName(data.hologram_data().linkedNpcName());
|
||||
};
|
||||
|
||||
return hologramData;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,9 +55,14 @@ public class JsonStorage implements HologramStorage {
|
||||
List<HologramData> holograms = new ArrayList<>();
|
||||
|
||||
try {
|
||||
holograms.addAll(jdb.getAll("worlds/" + world + "/text", TextHologramData.class));
|
||||
holograms.addAll(jdb.getAll("worlds/" + world + "/item", ItemHologramData.class));
|
||||
holograms.addAll(jdb.getAll("worlds/" + world + "/block", BlockHologramData.class));
|
||||
List<JsonDataUnion> allTextUnions = jdb.getAll("worlds/" + world + "/text", JsonDataUnion.class);
|
||||
allTextUnions.forEach(u -> holograms.add(JsonAdapter.fromJson(u)));
|
||||
|
||||
List<JsonDataUnion> allItemUnions = jdb.getAll("worlds/" + world + "/item", JsonDataUnion.class);
|
||||
allItemUnions.forEach(u -> holograms.add(JsonAdapter.fromJson(u)));
|
||||
|
||||
List<JsonDataUnion> allBlockUnions = jdb.getAll("worlds/" + world + "/block", JsonDataUnion.class);
|
||||
allBlockUnions.forEach(u -> holograms.add(JsonAdapter.fromJson(u)));
|
||||
} catch (IOException e) {
|
||||
FancyHolograms.get().getFancyLogger().error("Failed to load all holograms from world " + world);
|
||||
FancyHolograms.get().getFancyLogger().error(e);
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package de.oliver.fancyholograms.storage.json.model;
|
||||
|
||||
public record JsonBrightness(
|
||||
int block_light,
|
||||
int sky_light
|
||||
Integer block_light,
|
||||
Integer sky_light
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import org.bukkit.entity.Display;
|
||||
public record JsonDisplayHologramData(
|
||||
JsonVec3f scale,
|
||||
JsonVec3f translation,
|
||||
float shadow_radius,
|
||||
float shadow_strength,
|
||||
Float shadow_radius,
|
||||
Float shadow_strength,
|
||||
JsonBrightness brightness,
|
||||
Display.Billboard billboard
|
||||
) {
|
||||
|
||||
@@ -7,7 +7,7 @@ public record JsonHologramData(
|
||||
String name,
|
||||
HologramType type,
|
||||
JsonLocation location,
|
||||
int visibilityDistance,
|
||||
Integer visibilityDistance,
|
||||
Visibility visibility,
|
||||
String linkedNpcName
|
||||
) {
|
||||
|
||||
@@ -2,10 +2,10 @@ package de.oliver.fancyholograms.storage.json.model;
|
||||
|
||||
public record JsonLocation(
|
||||
String world,
|
||||
double x,
|
||||
double y,
|
||||
double z,
|
||||
float yaw,
|
||||
float pitch
|
||||
Double x,
|
||||
Double y,
|
||||
Double z,
|
||||
Float yaw,
|
||||
Float pitch
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import java.util.List;
|
||||
|
||||
public record JsonTextHologramData(
|
||||
List<String> text,
|
||||
boolean text_shadow,
|
||||
boolean see_through,
|
||||
Boolean text_shadow,
|
||||
Boolean see_through,
|
||||
TextDisplay.TextAlignment text_alignment,
|
||||
int text_update_interval,
|
||||
Integer text_update_interval,
|
||||
String background_color
|
||||
) {
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package de.oliver.fancyholograms.storage.json.model;
|
||||
|
||||
public record JsonVec3f(
|
||||
float x,
|
||||
float y,
|
||||
float z
|
||||
Float x,
|
||||
Float y,
|
||||
Float z
|
||||
) {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user