From f854b937753f892f6479bace09e976ba19e0d37b Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sat, 12 Sep 2026 22:49:52 +0200 Subject: [PATCH 1/4] feat(entity): add ground base entity --- .../vulpes/api/model/AbstractEntity.java | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java new file mode 100644 index 0000000..b5c34b9 --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java @@ -0,0 +1,72 @@ +package net.onelitefeather.vulpes.api.model; + +import io.micronaut.data.annotation.DateCreated; +import io.micronaut.data.annotation.DateUpdated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import net.onelitefeather.vulpes.api.generator.VulpesGenerator; + +import java.time.Instant; +import java.util.UUID; + +/** + * Base class for all entities of the Vulpes model. Bundles the fields that are common to every + * entity: the generated identifier and the creation/modification timestamps, which are maintained + * automatically by Micronaut Data. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 2.2.0 + */ +@MappedSuperclass +public abstract class AbstractEntity implements VulpesModel { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @VulpesGenerator + private UUID id; + + @DateCreated + private Instant creationDate; + + @DateUpdated + private Instant modificationDate; + + /** + * Returns the unique identifier of the entity. + * + * @return the unique identifier + */ + public UUID getId() { + return id; + } + + /** + * Sets the unique identifier of the entity. + * + * @param id the unique identifier to set + */ + public void setId(UUID id) { + this.id = id; + } + + /** + * Returns the point in time at which the entity was created. + * + * @return the creation date + */ + public Instant getCreationDate() { + return creationDate; + } + + /** + * Returns the point in time at which the entity was last modified. + * + * @return the modification date + */ + public Instant getModificationDate() { + return modificationDate; + } +} From 176245a9f4ba0e5bfcae91dc0e4968b050c9df5e Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sat, 12 Sep 2026 23:15:02 +0200 Subject: [PATCH 2/4] chore(model): update interchange --- .../vulpes/api/model/AttributeEntity.java | 69 +++++++----------- .../vulpes/api/model/FontEntity.java | 59 ++++++--------- .../vulpes/api/model/ItemEntity.java | 68 +++++++---------- .../vulpes/api/model/NotificationEntity.java | 67 +++++++---------- .../dimension/DimensionAttributeEntity.java | 38 ++-------- .../dimension/DimensionTimelineEntity.java | 38 ++-------- .../model/dimension/DimensionTypeEntity.java | 72 +++++++----------- .../api/model/font/FontStringEntity.java | 37 ++-------- .../api/model/item/ItemEnchantmentEntity.java | 37 ++-------- .../vulpes/api/model/item/ItemFlagEntity.java | 37 ++-------- .../vulpes/api/model/item/ItemLoreEntity.java | 37 ++-------- .../api/model/project/ProjectEntity.java | 33 +-------- .../api/model/sound/SoundEventEntity.java | 73 ++++++++----------- .../api/model/sound/SoundFileSource.java | 38 ++-------- 14 files changed, 203 insertions(+), 500 deletions(-) diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java index 4b4da40..38a1bef 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java @@ -1,14 +1,10 @@ package net.onelitefeather.vulpes.api.model; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -28,14 +24,10 @@ @Table(name = "attributes", indexes = { @Index(name = "idx_attributes_project_id", columnList = "project_id") }) -public class AttributeEntity implements VulpesModel { +public class AttributeEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; + private String key; private double defaultValue; private double maximumValue; @ManyToOne @@ -58,15 +50,15 @@ public AttributeEntity() { * * @param id the unique identifier of the attribute * @param uiName the model name associated with the attribute - * @param variableName the name of the attribute + * @param key the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}) * @param defaultValue the default value of the attribute * @param maximumValue the maximum value of the attribute * @param project the project this attribute belongs to */ - public AttributeEntity(UUID id, String uiName, String variableName, double defaultValue, double maximumValue, ProjectEntity project) { - this.id = id; + public AttributeEntity(UUID id, String uiName, String key, double defaultValue, double maximumValue, ProjectEntity project) { + this.setId(id); this.uiName = uiName; - this.variableName = variableName; + this.key = key; this.defaultValue = defaultValue; this.maximumValue = maximumValue; this.project = project; @@ -74,24 +66,6 @@ public AttributeEntity(UUID id, String uiName, String variableName, double defau // Getters and setters for each field - /** - * Returns the unique identifier of the attribute - * - * @return the unique identifier of the attribute - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the attribute - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the model name associated with the attribute * @@ -111,21 +85,32 @@ public void setUiName(String modelName) { } /** - * Returns the name of the attribute + * Returns the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}). * - * @return the name of the attribute + * @return the namespaced key of the attribute */ - public String getVariableName() { - return variableName; + public String getKey() { + return key; + } + + /** + * Sets the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}). + * + * @param key the namespaced key to set + */ + public void setKey(String key) { + this.key = key; } /** - * Sets the name of the attribute + * Derives the variable name of the attribute from its namespaced key, e.g. {@code minecraft:generic.max_health} + * becomes {@code GENERIC.MAX_HEALTH}. * - * @param name the name to set + * @return the derived variable name of the attribute */ - public void setVariableName(String name) { - this.variableName = name; + public String getVariableName() { + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } /** @@ -190,9 +175,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "AttributeModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", name='" + variableName + '\'' + + ", key='" + key + '\'' + ", defaultValue=" + defaultValue + ", maximumValue=" + maximumValue + ", project=" + project + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java index b51aa30..1107487 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java @@ -2,15 +2,11 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; import net.onelitefeather.vulpes.api.model.font.FontStringEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.OnDelete; @@ -32,14 +28,10 @@ @Table(name = "fonts", indexes = { @Index(name = "idx_fonts_project_id", columnList = "project_id") }) -public class FontEntity implements VulpesModel { +public class FontEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; + private String key; private String provider; private String mapper = "font"; private String texturePath; @@ -69,7 +61,7 @@ public FontEntity() { * * @param id the unique identifier of the font * @param uiName the user interface name of the font - * @param variableName the variable name of the font + * @param key the namespaced key of the font (e.g. {@code minecraft:default}) * @param provider the provider of the font * @param texturePath the path to the texture of the font * @param comment a comment or description for the font @@ -81,7 +73,7 @@ public FontEntity() { public FontEntity( UUID id, String uiName, - String variableName, + String key, String provider, String texturePath, String comment, @@ -90,9 +82,9 @@ public FontEntity( List chars, ProjectEntity project ) { - this.id = id; + this.setId(id); this.uiName = uiName; - this.variableName = variableName; + this.key = key; this.provider = provider; this.texturePath = texturePath; this.comment = comment; @@ -104,24 +96,6 @@ public FontEntity( // Getters and setters for each field - /** - * Returns the unique identifier of the font - * - * @return the unique identifier of the font - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the font - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - public void setUiName(String uiName) { this.uiName = uiName; } @@ -130,12 +104,23 @@ public String getUiName() { return uiName; } - public void setVariableName(String variableName) { - this.variableName = variableName; + public void setKey(String key) { + this.key = key; + } + + public String getKey() { + return key; } + /** + * Derives the variable name of the font from its namespaced key, e.g. {@code minecraft:default} + * becomes {@code DEFAULT}. + * + * @return the derived variable name of the font + */ public String getVariableName() { - return variableName; + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } public void setMapper(String mapper) { @@ -245,9 +230,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "FontEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + key + '\'' + ", provider='" + provider + '\'' + ", mapper='" + mapper + '\'' + ", texturePath='" + texturePath + '\'' + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java index a40efa5..679ddf4 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java @@ -2,15 +2,11 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity; import net.onelitefeather.vulpes.api.model.item.ItemFlagEntity; import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity; @@ -34,15 +30,10 @@ @Table(name = "items", indexes = { @Index(name = "idx_items_project_id", columnList = "project_id") }) -public class ItemEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class ItemEntity extends AbstractEntity { private String uiName; - private String variableName; + private String key; private String comment; private String displayName; private String material; @@ -76,7 +67,7 @@ public ItemEntity() { * * @param id the unique identifier of the item * @param uiName the model name associated with the item - * @param variableName the name of the item + * @param key the namespaced key of the item (e.g. {@code minecraft:dirt}) * @param comment a description of the item * @param displayName the display name of the item * @param material the material type associated with the item @@ -91,7 +82,7 @@ public ItemEntity() { public ItemEntity( UUID id, String uiName, - String variableName, + String key, String comment, String displayName, String material, @@ -103,9 +94,9 @@ public ItemEntity( List flags, ProjectEntity project ) { - this.id = id; + this.setId(id); this.uiName = uiName; - this.variableName = variableName; + this.key = key; this.comment = comment; this.displayName = displayName; this.material = material; @@ -120,24 +111,6 @@ public ItemEntity( // Getters and setters for each field - /** - * Returns the unique identifier of the item. - * - * @return the unique identifier of the item - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the item. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the name representation for the ui * @@ -157,21 +130,32 @@ public String getUiName() { } /** - * Sets the variable name for the notification + * Sets the namespaced key for the item (e.g. {@code minecraft:dirt}). + * + * @param key the namespaced key to set + */ + public void setKey(String key) { + this.key = key; + } + + /** + * Returns the namespaced key for the item (e.g. {@code minecraft:dirt}). * - * @param variableName the variable name to set + * @return the namespaced key of the item */ - public void setVariableName(String variableName) { - this.variableName = variableName; + public String getKey() { + return key; } /** - * Returns the variable name for the notification + * Derives the variable name of the item from its namespaced key, e.g. {@code minecraft:dirt} + * becomes {@code DIRT}. * - * @return the variable name of the notification + * @return the derived variable name of the item */ public String getVariableName() { - return variableName; + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } /** @@ -362,9 +346,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "ItemModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", name='" + variableName + '\'' + + ", key='" + key + '\'' + ", comment='" + comment + '\'' + ", displayName='" + displayName + '\'' + ", material='" + material + '\'' + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java index 1fae6da..4836283 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java @@ -1,14 +1,10 @@ package net.onelitefeather.vulpes.api.model; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -28,14 +24,10 @@ @Table(name = "notifications", indexes = { @Index(name = "idx_notifications_project_id", columnList = "project_id") }) -public class NotificationEntity implements VulpesModel { +public class NotificationEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; + private String key; private String comment; private String material; private String frameType; @@ -60,17 +52,17 @@ public NotificationEntity() { * * @param id the unique identifier of the notification * @param uiName the user interface name of the notification - * @param variableName the variable name of the notification + * @param key the namespaced key of the notification (e.g. {@code minecraft:achievement}) * @param comment a comment for the description * @param material the material type associated with the notification * @param frameType the frame type associated with the notification * @param title the title of the notification * @param project the project this notification belongs to */ - public NotificationEntity(UUID id, String uiName, String variableName, String comment, String material, String frameType, String title, ProjectEntity project) { - this.id = id; + public NotificationEntity(UUID id, String uiName, String key, String comment, String material, String frameType, String title, ProjectEntity project) { + this.setId(id); this.uiName = uiName; - this.variableName = variableName; + this.key = key; this.comment = comment; this.material = material; this.frameType = frameType; @@ -78,24 +70,6 @@ public NotificationEntity(UUID id, String uiName, String variableName, String co this.project = project; } - /** - * Returns the unique identifier of the notification - * - * @return the unique identifier of the notification - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the notification - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the name representation for the ui * @@ -115,21 +89,32 @@ public String getUiName() { } /** - * Sets the variable name for the notification + * Sets the namespaced key for the notification (e.g. {@code minecraft:achievement}). + * + * @param key the namespaced key to set + */ + public void setKey(String key) { + this.key = key; + } + + /** + * Returns the namespaced key for the notification (e.g. {@code minecraft:achievement}). * - * @param variableName the variable name to set + * @return the namespaced key of the notification */ - public void setVariableName(String variableName) { - this.variableName = variableName; + public String getKey() { + return key; } /** - * Returns the variable name for the notification + * Derives the variable name of the notification from its namespaced key, e.g. {@code minecraft:achievement} + * becomes {@code ACHIEVEMENT}. * - * @return the variable name of the notification + * @return the derived variable name of the notification */ public String getVariableName() { - return variableName; + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } /** @@ -230,9 +215,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "NotificationModel{" + - "id='" + id + '\'' + + "id='" + getId() + '\'' + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + key + '\'' + ", description='" + comment + '\'' + ", material='" + material + '\'' + ", frameType='" + frameType + '\'' + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java index 2b324a7..028317d 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java @@ -3,15 +3,12 @@ import jakarta.persistence.Entity; import jakarta.persistence.EnumType; import jakarta.persistence.Enumerated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -37,12 +34,7 @@ @Table(name = "dimension_attributes", indexes = { @Index(name = "idx_dimension_attributes_type_key", columnList = "dimension_type_id, attribute_key", unique = true) }) -public final class DimensionAttributeEntity { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class DimensionAttributeEntity extends AbstractEntity { @NotNull @Enumerated(EnumType.STRING) @@ -81,30 +73,12 @@ public DimensionAttributeEntity( AttributeOperator operator, String attributeValue ) { - this.id = id; + this.setId(id); this.attributeKey = attributeKey; this.operator = operator; this.attributeValue = attributeValue; } - /** - * Sets the unique identifier of the attribute entry. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the attribute entry. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the key identifying the environment attribute. * @@ -182,7 +156,7 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (DimensionAttributeEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.attributeKey, that.attributeKey) && this.operator == that.operator && Objects.equals(this.attributeValue, that.attributeValue) && @@ -191,13 +165,13 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(id, attributeKey, operator, attributeValue, dimensionType); + return Objects.hash(getId(), attributeKey, operator, attributeValue, dimensionType); } @Override public String toString() { return "DimensionAttributeEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "attributeKey=" + attributeKey + ", " + "operator=" + operator + ", " + "attributeValue=" + attributeValue + ", " + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java index 6338e05..1c2b42a 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java @@ -1,15 +1,12 @@ package net.onelitefeather.vulpes.api.model.dimension; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -33,12 +30,7 @@ @Table(name = "dimension_timelines", indexes = { @Index(name = "idx_dimension_timelines_type_key", columnList = "dimension_type_id, timeline_key", unique = true) }) -public final class DimensionTimelineEntity { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class DimensionTimelineEntity extends AbstractEntity { @NotNull private String timelineKey; @@ -65,28 +57,10 @@ public DimensionTimelineEntity( UUID id, String timelineKey ) { - this.id = id; + this.setId(id); this.timelineKey = timelineKey; } - /** - * Sets the unique identifier of the timeline reference. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the timeline reference. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the registry key of the referenced timeline. * @@ -128,20 +102,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (DimensionTimelineEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.timelineKey, that.timelineKey) && Objects.equals(this.dimensionType, that.dimensionType); } @Override public int hashCode() { - return Objects.hash(id, timelineKey, dimensionType); + return Objects.hash(getId(), timelineKey, dimensionType); } @Override public String toString() { return "DimensionTimelineEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "timelineKey=" + timelineKey + ", " + "dimensionType=" + dimensionType + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java index 9475d67..b6d5602 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java @@ -5,9 +5,6 @@ import jakarta.persistence.Entity; import jakarta.persistence.Enumerated; import jakarta.persistence.EnumType; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; @@ -18,8 +15,7 @@ import jakarta.validation.constraints.Max; import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; @@ -53,18 +49,13 @@ @Table(name = "dimension_types", indexes = { @Index(name = "idx_dimension_types_project_id", columnList = "project_id") }) -public class DimensionTypeEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class DimensionTypeEntity extends AbstractEntity { @NotNull private String uiName; @NotNull - private String variableName; + private String key; @ColumnDefault("false") private boolean hasFixedTime; @@ -141,7 +132,7 @@ public DimensionTypeEntity() { * * @param id the unique identifier of the dimension type * @param uiName the user interface name of the dimension type - * @param variableName the variable name of the dimension type + * @param key the namespaced key of the dimension type (e.g. {@code minecraft:overworld}) * @param hasFixedTime whether the dimension type has a fixed time * @param hasSkylight whether the dimension type has skylight * @param hasCeiling whether the dimension type has a ceiling @@ -164,7 +155,7 @@ public DimensionTypeEntity() { public DimensionTypeEntity( UUID id, String uiName, - String variableName, + String key, boolean hasFixedTime, boolean hasSkylight, boolean hasCeiling, @@ -184,9 +175,9 @@ public DimensionTypeEntity( List timelines, ProjectEntity project ) { - this.id = id; + this.setId(id); this.uiName = uiName; - this.variableName = variableName; + this.key = key; this.hasFixedTime = hasFixedTime; this.hasSkylight = hasSkylight; this.hasCeiling = hasCeiling; @@ -209,24 +200,6 @@ public DimensionTypeEntity( // Getters and setters for each field - /** - * Returns the unique identifier of the dimension type. - * - * @return the unique identifier of the dimension type - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the dimension type. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the user interface name of the dimension type. * @@ -246,21 +219,32 @@ public void setUiName(String uiName) { } /** - * Returns the variable name of the dimension type. + * Returns the namespaced key of the dimension type (e.g. {@code minecraft:overworld}). * - * @return the variable name + * @return the namespaced key */ - public String getVariableName() { - return variableName; + public String getKey() { + return key; } /** - * Sets the variable name of the dimension type. + * Sets the namespaced key of the dimension type (e.g. {@code minecraft:overworld}). * - * @param variableName the variable name to set + * @param key the namespaced key to set */ - public void setVariableName(String variableName) { - this.variableName = variableName; + public void setKey(String key) { + this.key = key; + } + + /** + * Derives the variable name of the dimension type from its namespaced key, e.g. {@code minecraft:overworld} + * becomes {@code OVERWORLD}. + * + * @return the derived variable name + */ + public String getVariableName() { + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } /** @@ -591,9 +575,9 @@ public void setProject(ProjectEntity project) { @Override public String toString() { return "DimensionTypeEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + key + '\'' + ", hasFixedTime=" + hasFixedTime + ", hasSkylight=" + hasSkylight + ", hasCeiling=" + hasCeiling + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java index ecf9ce5..bc8aca1 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.font; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.FontEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -15,11 +12,7 @@ import java.util.UUID; @Entity(name = "font_string") -public final class FontStringEntity implements Comparable { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class FontStringEntity extends AbstractEntity implements Comparable { private String line; @ManyToOne @JoinColumn(name = "font_id", nullable = false) @@ -46,29 +39,11 @@ public FontStringEntity( String content, int orderIndex ) { - this.id = id; + this.setId(id); this.line = content; this.orderIndex = orderIndex; } - /** - * Sets the unique identifier of the font string. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the font string. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the content of the font string. * @@ -128,20 +103,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (FontStringEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.line, that.line) && Objects.equals(this.font, that.font); } @Override public int hashCode() { - return Objects.hash(id, line, font); + return Objects.hash(getId(), line, font); } @Override public String toString() { return "FontLoreEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "line=" + line + ", " + "font=" + font + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java index 821bfae..b152304 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -15,11 +12,7 @@ import java.util.UUID; @Entity(name = "item_enchantments") -public final class ItemEnchantmentEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemEnchantmentEntity extends AbstractEntity { private String name; private short level; private boolean unsafe; @@ -49,30 +42,12 @@ public ItemEnchantmentEntity( short level, boolean unsafe ) { - this.id = id; + this.setId(id); this.name = name; this.level = level; this.unsafe = unsafe; } - /** - * Returns the unique identifier of the item enchantment. - * - * @return the id - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the item enchantment. - * - * @param id the id to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the name of the enchantment. * @@ -150,7 +125,7 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemEnchantmentEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.name, that.name) && this.level == that.level && this.unsafe == that.unsafe && @@ -159,13 +134,13 @@ public boolean equals(Object obj) { @Override public int hashCode() { - return Objects.hash(id, name, level, unsafe, item); + return Objects.hash(getId(), name, level, unsafe, item); } @Override public String toString() { return "ItemEnchantmentEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "name=" + name + ", " + "level=" + level + ", " + "unsafe=" + unsafe + ", " + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java index 27df451..c9349fd 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -22,11 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_flags") -public final class ItemFlagEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemFlagEntity extends AbstractEntity { private String flag; @ManyToOne @JoinColumn(name = "item_id") @@ -50,28 +43,10 @@ public ItemFlagEntity( UUID id, String flag ) { - this.id = id; + this.setId(id); this.flag = flag; } - /** - * Sets the unique identifier of the item flag. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the item flag. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the flag associated with the item. * @@ -113,20 +88,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemFlagEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.flag, that.flag) && Objects.equals(this.item, that.item); } @Override public int hashCode() { - return Objects.hash(id, flag, item); + return Objects.hash(getId(), flag, item); } @Override public String toString() { return "ItemFlagEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "text=" + flag + ", " + "item=" + item + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java index e658300..4ce2876 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java @@ -1,12 +1,9 @@ package net.onelitefeather.vulpes.api.model.item; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -22,11 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_lore") -public final class ItemLoreEntity implements Comparable { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public final class ItemLoreEntity extends AbstractEntity implements Comparable { private String text; @ManyToOne @JoinColumn(name = "item_id", nullable = false) @@ -52,29 +45,11 @@ public ItemLoreEntity( String text, int orderIndex ) { - this.id = id; + this.setId(id); this.text = text; this.orderIndex = orderIndex; } - /** - * Sets the unique identifier of the lore entry. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - - /** - * Gets the unique identifier of the lore entry. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - /** * Sets the item associated with this lore entry. * @@ -134,20 +109,20 @@ public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != this.getClass()) return false; var that = (ItemLoreEntity) obj; - return Objects.equals(this.id, that.id) && + return Objects.equals(this.getId(), that.getId()) && Objects.equals(this.text, that.text) && Objects.equals(this.item, that.item); } @Override public int hashCode() { - return Objects.hash(id, text, item); + return Objects.hash(getId(), text, item); } @Override public String toString() { return "ItemLoreEntity[" + - "id=" + id + ", " + + "id=" + getId() + ", " + "text=" + text + ", " + "item=" + item + ']'; } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java index 01b6737..5aa4c32 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java @@ -3,14 +3,10 @@ import jakarta.annotation.Nullable; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import org.hibernate.annotations.ColumnDefault; import java.util.UUID; @@ -32,12 +28,7 @@ @Table(name = "projects", indexes = { @Index(name = "idx_projects_key", columnList = "project_key", unique = true) }) -public class ProjectEntity implements VulpesModel { - - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; +public class ProjectEntity extends AbstractEntity { @NotNull private String displayName; @@ -90,7 +81,7 @@ public ProjectEntity( @Nullable String description, boolean labor ) { - this.id = id; + this.setId(id); this.displayName = displayName; this.key = key; this.projectUrl = projectUrl; @@ -99,15 +90,6 @@ public ProjectEntity( this.labor = labor; } - /** - * Sets the unique identifier of the project. - * - * @param id of the project - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the display name of the project. * @@ -162,15 +144,6 @@ public void setLabor(boolean labor) { this.labor = labor; } - /** - * Returns the unique identifier of the project. - * - * @return the unique identifier of the project - */ - public UUID getId() { - return id; - } - /** * Returns the display name of the project. * diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java index db62020..472305e 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java @@ -2,16 +2,12 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.Index; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; @@ -35,14 +31,10 @@ @Table(name = "sounds", indexes = { @Index(name = "idx_sounds_project_id", columnList = "project_id") }) -public class SoundEventEntity implements VulpesModel { +public class SoundEventEntity extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String uiName; - private String variableName; + private String key; private String keyName; @Column(name = "replace_flag") @ColumnDefault("false") @@ -77,42 +69,24 @@ public SoundEventEntity() { * * @param id the unique identifier of the sound model * @param uiName the user interface name for the sound model - * @param variableName the variable name for the sound model + * @param key the namespaced key for the sound model (e.g. {@code minecraft:ambient.cave}) * @param keyName the key name for the sound model * @param replace whether to replace an existing sound model * @param subTitle the subtitle for the sound model * @param dataEntities the list of sound data entities related to this sound model * @param project the project this sound event belongs to */ - public SoundEventEntity(UUID id, String uiName, String variableName, String keyName, boolean replace, String subTitle, List dataEntities, ProjectEntity project) { - this.id = id; + public SoundEventEntity(UUID id, String uiName, String key, String keyName, boolean replace, String subTitle, List dataEntities, ProjectEntity project) { + this.setId(id); this.uiName = uiName; this.keyName = keyName; - this.variableName = variableName; + this.key = key; this.replace = replace; this.subTitle = subTitle; this.dataEntities = dataEntities; this.project = project; } - /** - * Returns the unique identifier of the sound model - * - * @return the unique identifier of the sound model - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the sound model - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Returns the user interface name for the sound model * @@ -150,21 +124,32 @@ public String getKeyName() { } /** - * Set the name for the variable associated with this sound model. + * Set the namespaced key associated with this sound model (e.g. {@code minecraft:ambient.cave}). + * + * @param key the namespaced key to set + */ + public void setKey(String key) { + this.key = key; + } + + /** + * Returns the namespaced key associated with this sound model (e.g. {@code minecraft:ambient.cave}). * - * @param variableName the name of the variable to set + * @return the namespaced key */ - public void setVariableName(String variableName) { - this.variableName = variableName; + public String getKey() { + return key; } /** - * Returns the name of the variable associated with this sound model. + * Derives the variable name of the sound model from its namespaced key, e.g. {@code minecraft:ambient.cave} + * becomes {@code AMBIENT.CAVE}. * - * @return the name of the variable + * @return the derived variable name of the sound model */ public String getVariableName() { - return variableName; + int separatorIndex = key.indexOf(':'); + return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); } /** @@ -226,20 +211,20 @@ public void setProject(ProjectEntity project) { public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SoundEventEntity that = (SoundEventEntity) o; - return replace == that.replace && Objects.equals(id, that.id) && Objects.equals(uiName, that.uiName) && Objects.equals(variableName, that.variableName) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(project, that.project); + return replace == that.replace && Objects.equals(getId(), that.getId()) && Objects.equals(uiName, that.uiName) && Objects.equals(key, that.key) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(project, that.project); } @Override public int hashCode() { - return Objects.hash(id, uiName, variableName, keyName, replace, subTitle, dataEntities, project); + return Objects.hash(getId(), uiName, key, keyName, replace, subTitle, dataEntities, project); } @Override public String toString() { return "SoundEventEntity{" + - "id=" + id + + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", variableName='" + variableName + '\'' + + ", key='" + key + '\'' + ", keyName='" + keyName + '\'' + ", replace=" + replace + ", subTitle='" + subTitle + '\'' + diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java index 2f4e3cd..dda7edb 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java @@ -1,13 +1,9 @@ package net.onelitefeather.vulpes.api.model.sound; import jakarta.persistence.Entity; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; -import net.onelitefeather.vulpes.api.model.VulpesModel; +import net.onelitefeather.vulpes.api.model.AbstractEntity; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -24,12 +20,8 @@ * @since 0.1.0 */ @Entity(name = "sound_data") -public class SoundFileSource implements VulpesModel { +public class SoundFileSource extends AbstractEntity { - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; private String name; @ColumnDefault("1.0") private float volume; @@ -84,7 +76,7 @@ public SoundFileSource( boolean preload, String type ) { - this.id = id; + this.setId(id); this.name = name; this.volume = volume; this.pitch = pitch; @@ -97,24 +89,6 @@ public SoundFileSource( // Getters and setters for each field - /** - * Returns the unique identifier of the data. - * - * @return the unique identifier - */ - public UUID getId() { - return id; - } - - /** - * Sets the unique identifier of the sound data. - * - * @param id the unique identifier to set - */ - public void setId(UUID id) { - this.id = id; - } - /** * Sets the name of the sound data * @@ -253,18 +227,18 @@ public void setSoundEvent(SoundEventEntity soundEvent) { public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SoundFileSource that = (SoundFileSource) o; - return Float.compare(volume, that.volume) == 0 && Float.compare(pitch, that.pitch) == 0 && weight == that.weight && stream == that.stream && attenuationDistance == that.attenuationDistance && preload == that.preload && Objects.equals(id, that.id) && Objects.equals(name, that.name) && Objects.equals(type, that.type); + return Float.compare(volume, that.volume) == 0 && Float.compare(pitch, that.pitch) == 0 && weight == that.weight && stream == that.stream && attenuationDistance == that.attenuationDistance && preload == that.preload && Objects.equals(getId(), that.getId()) && Objects.equals(name, that.name) && Objects.equals(type, that.type); } @Override public int hashCode() { - return Objects.hash(id, name, volume, pitch, weight, stream, attenuationDistance, preload, type); + return Objects.hash(getId(), name, volume, pitch, weight, stream, attenuationDistance, preload, type); } @Override public String toString() { return "SoundDataEntity{" + - "id=" + id + + "id=" + getId() + ", name='" + name + '\'' + ", volume=" + volume + ", pitch=" + pitch + From dc722c6cd54d9e29d77d168b0b3470e000e30983 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sun, 13 Sep 2026 22:12:54 +0200 Subject: [PATCH 3/4] refactor(entity): update base entities --- .../vulpes/api/model/AbstractEntity.java | 106 ++++++++++++------ .../vulpes/api/model/IdentifiableEntity.java | 72 ++++++++++++ 2 files changed, 141 insertions(+), 37 deletions(-) create mode 100644 src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java index b5c34b9..3a4759e 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AbstractEntity.java @@ -1,72 +1,104 @@ package net.onelitefeather.vulpes.api.model; -import io.micronaut.data.annotation.DateCreated; -import io.micronaut.data.annotation.DateUpdated; -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.GenerationType; -import jakarta.persistence.Id; +import jakarta.persistence.JoinColumn; +import jakarta.persistence.ManyToOne; import jakarta.persistence.MappedSuperclass; -import net.onelitefeather.vulpes.api.generator.VulpesGenerator; - -import java.time.Instant; -import java.util.UUID; +import jakarta.validation.constraints.NotNull; +import net.onelitefeather.vulpes.api.model.project.ProjectEntity; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; /** - * Base class for all entities of the Vulpes model. Bundles the fields that are common to every - * entity: the generated identifier and the creation/modification timestamps, which are maintained - * automatically by Micronaut Data. + * Base class for every entity that belongs to a {@link ProjectEntity}. Adds the project + * reference and the entity's local key, which combine into a namespaced key + * (e.g. {@code cygnus:whatever}) via {@link #getNamespacedKey()}. * * @author theEvilReaper * @version 1.0.0 * @since 2.2.0 */ @MappedSuperclass -public abstract class AbstractEntity implements VulpesModel { +public abstract class AbstractEntity extends IdentifiableEntity { + + @ManyToOne + @JoinColumn(name = "project_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) + private ProjectEntity project; + + @NotNull + private String key; - @Id - @GeneratedValue(strategy = GenerationType.UUID) - @VulpesGenerator - private UUID id; + /** + * Default constructor for JPA and Micronaut Data. + */ + protected AbstractEntity() { + // No-argument constructor for JPA + } - @DateCreated - private Instant creationDate; + /** + * Constructs a new {@link AbstractEntity} with the specified local key and project. + * + * @param key the local key of the entity within the project's namespace + * @param project the project this entity belongs to + */ + protected AbstractEntity(String key, ProjectEntity project) { + this.key = key; + this.project = project; + } - @DateUpdated - private Instant modificationDate; + /** + * Returns the project this entity belongs to. + * + * @return the project of the entity + */ + public ProjectEntity getProject() { + return project; + } + + /** + * Sets the project this entity belongs to. + * + * @param project the project to set + */ + public void setProject(ProjectEntity project) { + this.project = project; + } /** - * Returns the unique identifier of the entity. + * Returns the local key of the entity within its project's namespace (e.g. {@code whatever}). * - * @return the unique identifier + * @return the local key of the entity */ - public UUID getId() { - return id; + public String getKey() { + return key; } /** - * Sets the unique identifier of the entity. + * Sets the local key of the entity within its project's namespace (e.g. {@code whatever}). * - * @param id the unique identifier to set + * @param key the local key to set */ - public void setId(UUID id) { - this.id = id; + public void setKey(String key) { + this.key = key; } /** - * Returns the point in time at which the entity was created. + * Returns the full namespaced key, combining the project's key with this entity's local key + * (e.g. project key {@code cygnus} and local key {@code whatever} become {@code cygnus:whatever}). * - * @return the creation date + * @return the namespaced key of the entity */ - public Instant getCreationDate() { - return creationDate; + public String getNamespacedKey() { + return project.getKey() + ":" + key; } /** - * Returns the point in time at which the entity was last modified. + * Derives the variable name of the entity from its local key, e.g. local key {@code whatever} + * becomes {@code WHATEVER}. * - * @return the modification date + * @return the derived variable name of the entity */ - public Instant getModificationDate() { - return modificationDate; + public String getVariableName() { + return key.toUpperCase(); } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java new file mode 100644 index 0000000..17fa250 --- /dev/null +++ b/src/main/java/net/onelitefeather/vulpes/api/model/IdentifiableEntity.java @@ -0,0 +1,72 @@ +package net.onelitefeather.vulpes.api.model; + +import io.micronaut.data.annotation.DateCreated; +import io.micronaut.data.annotation.DateUpdated; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import jakarta.persistence.MappedSuperclass; +import net.onelitefeather.vulpes.api.generator.VulpesGenerator; + +import java.time.Instant; +import java.util.UUID; + +/** + * Base class for all entities of the Vulpes model. Bundles the fields that are common to every + * entity: the generated identifier and the creation/modification timestamps, which are maintained + * automatically by Micronaut Data. + * + * @author theEvilReaper + * @version 1.0.0 + * @since 2.2.0 + */ +@MappedSuperclass +public abstract class IdentifiableEntity implements VulpesModel { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + @VulpesGenerator + private UUID id; + + @DateCreated + private Instant creationDate; + + @DateUpdated + private Instant modificationDate; + + /** + * Returns the unique identifier of the entity. + * + * @return the unique identifier + */ + public UUID getId() { + return id; + } + + /** + * Sets the unique identifier of the entity. + * + * @param id the unique identifier to set + */ + public void setId(UUID id) { + this.id = id; + } + + /** + * Returns the point in time at which the entity was created. + * + * @return the creation date + */ + public Instant getCreationDate() { + return creationDate; + } + + /** + * Returns the point in time at which the entity was last modified. + * + * @return the modification date + */ + public Instant getModificationDate() { + return modificationDate; + } +} From 9d4f970a309ffc62d9815127641d8a5c2a9c1cc3 Mon Sep 17 00:00:00 2001 From: theEvilReaper Date: Sun, 13 Sep 2026 22:13:16 +0200 Subject: [PATCH 4/4] chore(entity): update inheritance of specialized entities --- .../vulpes/api/model/AttributeEntity.java | 70 +++--------------- .../vulpes/api/model/FontEntity.java | 61 +++------------ .../vulpes/api/model/ItemEntity.java | 71 +++--------------- .../vulpes/api/model/NotificationEntity.java | 70 +++--------------- .../dimension/DimensionAttributeEntity.java | 4 +- .../dimension/DimensionTimelineEntity.java | 4 +- .../model/dimension/DimensionTypeEntity.java | 72 +++--------------- .../api/model/font/FontStringEntity.java | 4 +- .../api/model/item/ItemEnchantmentEntity.java | 4 +- .../vulpes/api/model/item/ItemFlagEntity.java | 4 +- .../vulpes/api/model/item/ItemLoreEntity.java | 4 +- .../api/model/project/ProjectEntity.java | 4 +- .../api/model/sound/SoundEventEntity.java | 74 +++---------------- .../api/model/sound/SoundFileSource.java | 4 +- 14 files changed, 72 insertions(+), 378 deletions(-) diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java index 38a1bef..b8ad4f4 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/AttributeEntity.java @@ -2,12 +2,9 @@ import jakarta.persistence.Entity; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.UUID; @@ -23,17 +20,14 @@ @Entity(name = "attributes") @Table(name = "attributes", indexes = { @Index(name = "idx_attributes_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_attributes_project_key", columnNames = {"project_id", "key"}) }) public class AttributeEntity extends AbstractEntity { private String uiName; - private String key; private double defaultValue; private double maximumValue; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; /** * Default constructor for JPA and Micronaut Data. @@ -50,18 +44,19 @@ public AttributeEntity() { * * @param id the unique identifier of the attribute * @param uiName the model name associated with the attribute - * @param key the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}) + * @param key the local key of the attribute within the project's namespace + * (e.g. {@code generic.max_health}, becomes {@code :generic.max_health} + * via {@link #getNamespacedKey()}) * @param defaultValue the default value of the attribute * @param maximumValue the maximum value of the attribute * @param project the project this attribute belongs to */ public AttributeEntity(UUID id, String uiName, String key, double defaultValue, double maximumValue, ProjectEntity project) { + super(key, project); this.setId(id); this.uiName = uiName; - this.key = key; this.defaultValue = defaultValue; this.maximumValue = maximumValue; - this.project = project; } // Getters and setters for each field @@ -84,35 +79,6 @@ public void setUiName(String modelName) { this.uiName = modelName; } - /** - * Returns the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}). - * - * @return the namespaced key of the attribute - */ - public String getKey() { - return key; - } - - /** - * Sets the namespaced key of the attribute (e.g. {@code minecraft:generic.max_health}). - * - * @param key the namespaced key to set - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Derives the variable name of the attribute from its namespaced key, e.g. {@code minecraft:generic.max_health} - * becomes {@code GENERIC.MAX_HEALTH}. - * - * @return the derived variable name of the attribute - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } - /** * Returns the default value of the attribute * @@ -149,24 +115,6 @@ public void setMaximumValue(double maximumValue) { this.maximumValue = maximumValue; } - /** - * Returns the project this attribute belongs to. - * - * @return the project of the attribute - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this attribute belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the AttributeModel * @@ -177,10 +125,10 @@ public String toString() { return "AttributeModel{" + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", defaultValue=" + defaultValue + ", maximumValue=" + maximumValue + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java index 1107487..f423f4d 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/FontEntity.java @@ -3,14 +3,11 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.font.FontStringEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -27,11 +24,12 @@ @Entity(name = "fonts") @Table(name = "fonts", indexes = { @Index(name = "idx_fonts_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_fonts_project_key", columnNames = {"project_id", "key"}) }) public class FontEntity extends AbstractEntity { private String uiName; - private String key; private String provider; private String mapper = "font"; private String texturePath; @@ -41,11 +39,6 @@ public class FontEntity extends AbstractEntity { @OneToMany(mappedBy = "font", cascade = CascadeType.ALL) private List chars; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -61,7 +54,9 @@ public FontEntity() { * * @param id the unique identifier of the font * @param uiName the user interface name of the font - * @param key the namespaced key of the font (e.g. {@code minecraft:default}) + * @param key the local key of the font within the project's namespace + * (e.g. {@code default}, becomes {@code :default} + * via {@link #getNamespacedKey()}) * @param provider the provider of the font * @param texturePath the path to the texture of the font * @param comment a comment or description for the font @@ -82,16 +77,15 @@ public FontEntity( List chars, ProjectEntity project ) { + super(key, project); this.setId(id); this.uiName = uiName; - this.key = key; this.provider = provider; this.texturePath = texturePath; this.comment = comment; this.height = height; this.ascent = ascent; this.chars = chars; - this.project = project; } // Getters and setters for each field @@ -104,25 +98,6 @@ public String getUiName() { return uiName; } - public void setKey(String key) { - this.key = key; - } - - public String getKey() { - return key; - } - - /** - * Derives the variable name of the font from its namespaced key, e.g. {@code minecraft:default} - * becomes {@code DEFAULT}. - * - * @return the derived variable name of the font - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } - public void setMapper(String mapper) { this.mapper = mapper; } @@ -209,30 +184,12 @@ public void setChars(List chars) { this.chars = chars; } - /** - * Returns the project this font belongs to. - * - * @return the project of the font - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this font belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public String toString() { return "FontEntity{" + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", provider='" + provider + '\'' + ", mapper='" + mapper + '\'' + ", texturePath='" + texturePath + '\'' + @@ -240,7 +197,7 @@ public String toString() { ", height=" + height + ", ascent=" + ascent + ", chars=" + chars + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java index 679ddf4..5722fc1 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java @@ -3,16 +3,13 @@ import jakarta.persistence.CascadeType; import jakarta.persistence.Entity; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity; import net.onelitefeather.vulpes.api.model.item.ItemFlagEntity; import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -29,11 +26,12 @@ @Entity(name = "items") @Table(name = "items", indexes = { @Index(name = "idx_items_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_items_project_key", columnNames = {"project_id", "key"}) }) public class ItemEntity extends AbstractEntity { private String uiName; - private String key; private String comment; private String displayName; private String material; @@ -47,11 +45,6 @@ public class ItemEntity extends AbstractEntity { @OneToMany(mappedBy = "item", cascade = CascadeType.ALL) private List flags; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -67,7 +60,9 @@ public ItemEntity() { * * @param id the unique identifier of the item * @param uiName the model name associated with the item - * @param key the namespaced key of the item (e.g. {@code minecraft:dirt}) + * @param key the local key of the item within the project's namespace + * (e.g. {@code dirt}, becomes {@code :dirt} + * via {@link #getNamespacedKey()}) * @param comment a description of the item * @param displayName the display name of the item * @param material the material type associated with the item @@ -94,9 +89,9 @@ public ItemEntity( List flags, ProjectEntity project ) { + super(key, project); this.setId(id); this.uiName = uiName; - this.key = key; this.comment = comment; this.displayName = displayName; this.material = material; @@ -106,7 +101,6 @@ public ItemEntity( this.enchantments = enchantments; this.lore = lore; this.flags = flags; - this.project = project; } // Getters and setters for each field @@ -129,35 +123,6 @@ public String getUiName() { return uiName; } - /** - * Sets the namespaced key for the item (e.g. {@code minecraft:dirt}). - * - * @param key the namespaced key to set - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Returns the namespaced key for the item (e.g. {@code minecraft:dirt}). - * - * @return the namespaced key of the item - */ - public String getKey() { - return key; - } - - /** - * Derives the variable name of the item from its namespaced key, e.g. {@code minecraft:dirt} - * becomes {@code DIRT}. - * - * @return the derived variable name of the item - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } - /** * Returns the comment of the notification * @@ -320,24 +285,6 @@ public void setFlags(List flags) { this.flags = flags; } - /** - * Returns the project this item belongs to. - * - * @return the project of the item - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this item belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the ItemModel. * @@ -348,7 +295,7 @@ public String toString() { return "ItemModel{" + "id='" + getId() + '\'' + ", modelName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", comment='" + comment + '\'' + ", displayName='" + displayName + '\'' + ", material='" + material + '\'' + @@ -358,7 +305,7 @@ public String toString() { ", enchantments=" + enchantments + ", lore=" + lore + ", flags=" + flags + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java index 4836283..aaf9acc 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/NotificationEntity.java @@ -2,12 +2,9 @@ import jakarta.persistence.Entity; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.UUID; @@ -23,19 +20,16 @@ @Entity(name = "notifications") @Table(name = "notifications", indexes = { @Index(name = "idx_notifications_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_notifications_project_key", columnNames = {"project_id", "key"}) }) public class NotificationEntity extends AbstractEntity { private String uiName; - private String key; private String comment; private String material; private String frameType; private String title; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; /** * Default constructor for JPA and Micronaut Data. @@ -52,7 +46,9 @@ public NotificationEntity() { * * @param id the unique identifier of the notification * @param uiName the user interface name of the notification - * @param key the namespaced key of the notification (e.g. {@code minecraft:achievement}) + * @param key the local key of the notification within the project's namespace + * (e.g. {@code achievement}, becomes {@code :achievement} + * via {@link #getNamespacedKey()}) * @param comment a comment for the description * @param material the material type associated with the notification * @param frameType the frame type associated with the notification @@ -60,14 +56,13 @@ public NotificationEntity() { * @param project the project this notification belongs to */ public NotificationEntity(UUID id, String uiName, String key, String comment, String material, String frameType, String title, ProjectEntity project) { + super(key, project); this.setId(id); this.uiName = uiName; - this.key = key; this.comment = comment; this.material = material; this.frameType = frameType; this.title = title; - this.project = project; } /** @@ -88,35 +83,6 @@ public String getUiName() { return uiName; } - /** - * Sets the namespaced key for the notification (e.g. {@code minecraft:achievement}). - * - * @param key the namespaced key to set - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Returns the namespaced key for the notification (e.g. {@code minecraft:achievement}). - * - * @return the namespaced key of the notification - */ - public String getKey() { - return key; - } - - /** - * Derives the variable name of the notification from its namespaced key, e.g. {@code minecraft:achievement} - * becomes {@code ACHIEVEMENT}. - * - * @return the derived variable name of the notification - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } - /** * Returns the comment of the notification * @@ -189,24 +155,6 @@ public void setTitle(String title) { this.title = title; } - /** - * Returns the project this notification belongs to. - * - * @return the project of the notification - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this notification belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - /** * Provides a string representation of the NotificationModel * @@ -217,12 +165,12 @@ public String toString() { return "NotificationModel{" + "id='" + getId() + '\'' + ", uiName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", description='" + comment + '\'' + ", material='" + material + '\'' + ", frameType='" + frameType + '\'' + ", title='" + title + '\'' + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java index 028317d..07e35a6 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionAttributeEntity.java @@ -8,7 +8,7 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -34,7 +34,7 @@ @Table(name = "dimension_attributes", indexes = { @Index(name = "idx_dimension_attributes_type_key", columnList = "dimension_type_id, attribute_key", unique = true) }) -public final class DimensionAttributeEntity extends AbstractEntity { +public final class DimensionAttributeEntity extends IdentifiableEntity { @NotNull @Enumerated(EnumType.STRING) diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java index 1c2b42a..cc2fc72 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTimelineEntity.java @@ -6,7 +6,7 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -30,7 +30,7 @@ @Table(name = "dimension_timelines", indexes = { @Index(name = "idx_dimension_timelines_type_key", columnList = "dimension_type_id, timeline_key", unique = true) }) -public final class DimensionTimelineEntity extends AbstractEntity { +public final class DimensionTimelineEntity extends IdentifiableEntity { @NotNull private String timelineKey; diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java index b6d5602..da209a9 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/dimension/DimensionTypeEntity.java @@ -6,10 +6,9 @@ import jakarta.persistence.Enumerated; import jakarta.persistence.EnumType; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import jakarta.validation.constraints.DecimalMax; import jakarta.validation.constraints.DecimalMin; import jakarta.validation.constraints.Max; @@ -18,8 +17,6 @@ import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.UUID; @@ -48,15 +45,14 @@ @Entity(name = "dimension_types") @Table(name = "dimension_types", indexes = { @Index(name = "idx_dimension_types_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_dimension_types_project_key", columnNames = {"project_id", "key"}) }) public class DimensionTypeEntity extends AbstractEntity { @NotNull private String uiName; - @NotNull - private String key; - @ColumnDefault("false") private boolean hasFixedTime; @@ -112,11 +108,6 @@ public class DimensionTypeEntity extends AbstractEntity { @OneToMany(mappedBy = "dimensionType", cascade = CascadeType.ALL) private List timelines; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -132,7 +123,9 @@ public DimensionTypeEntity() { * * @param id the unique identifier of the dimension type * @param uiName the user interface name of the dimension type - * @param key the namespaced key of the dimension type (e.g. {@code minecraft:overworld}) + * @param key the local key of the dimension type within the project's namespace + * (e.g. {@code overworld}, becomes {@code :overworld} + * via {@link #getNamespacedKey()}) * @param hasFixedTime whether the dimension type has a fixed time * @param hasSkylight whether the dimension type has skylight * @param hasCeiling whether the dimension type has a ceiling @@ -175,9 +168,9 @@ public DimensionTypeEntity( List timelines, ProjectEntity project ) { + super(key, project); this.setId(id); this.uiName = uiName; - this.key = key; this.hasFixedTime = hasFixedTime; this.hasSkylight = hasSkylight; this.hasCeiling = hasCeiling; @@ -195,7 +188,6 @@ public DimensionTypeEntity( this.defaultClock = defaultClock; this.attributes = attributes; this.timelines = timelines; - this.project = project; } // Getters and setters for each field @@ -218,34 +210,6 @@ public void setUiName(String uiName) { this.uiName = uiName; } - /** - * Returns the namespaced key of the dimension type (e.g. {@code minecraft:overworld}). - * - * @return the namespaced key - */ - public String getKey() { - return key; - } - - /** - * Sets the namespaced key of the dimension type (e.g. {@code minecraft:overworld}). - * - * @param key the namespaced key to set - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Derives the variable name of the dimension type from its namespaced key, e.g. {@code minecraft:overworld} - * becomes {@code OVERWORLD}. - * - * @return the derived variable name - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } /** * Returns whether the dimension type has a fixed time. @@ -554,30 +518,12 @@ public void setTimelines(List timelines) { this.timelines = timelines; } - /** - * Returns the project this dimension type belongs to. - * - * @return the project of the dimension type - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this dimension type belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public String toString() { return "DimensionTypeEntity{" + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", hasFixedTime=" + hasFixedTime + ", hasSkylight=" + hasSkylight + ", hasCeiling=" + hasCeiling + @@ -595,7 +541,7 @@ public String toString() { ", defaultClock='" + defaultClock + '\'' + ", attributes=" + attributes + ", timelines=" + timelines + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java index bc8aca1..4dde75f 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/font/FontStringEntity.java @@ -3,7 +3,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.FontEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -12,7 +12,7 @@ import java.util.UUID; @Entity(name = "font_string") -public final class FontStringEntity extends AbstractEntity implements Comparable { +public final class FontStringEntity extends IdentifiableEntity implements Comparable { private String line; @ManyToOne @JoinColumn(name = "font_id", nullable = false) diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java index b152304..914a7d9 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemEnchantmentEntity.java @@ -3,7 +3,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -12,7 +12,7 @@ import java.util.UUID; @Entity(name = "item_enchantments") -public final class ItemEnchantmentEntity extends AbstractEntity { +public final class ItemEnchantmentEntity extends IdentifiableEntity { private String name; private short level; private boolean unsafe; diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java index c9349fd..8125034 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemFlagEntity.java @@ -3,7 +3,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -19,7 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_flags") -public final class ItemFlagEntity extends AbstractEntity { +public final class ItemFlagEntity extends IdentifiableEntity { private String flag; @ManyToOne @JoinColumn(name = "item_id") diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java index 4ce2876..3360d6e 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/item/ItemLoreEntity.java @@ -3,7 +3,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import net.onelitefeather.vulpes.api.model.ItemEntity; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -19,7 +19,7 @@ * @since 1.6.0 */ @Entity(name = "item_lore") -public final class ItemLoreEntity extends AbstractEntity implements Comparable { +public final class ItemLoreEntity extends IdentifiableEntity implements Comparable { private String text; @ManyToOne @JoinColumn(name = "item_id", nullable = false) diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java index 5aa4c32..02b84ee 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/project/ProjectEntity.java @@ -6,7 +6,7 @@ import jakarta.persistence.Index; import jakarta.persistence.Table; import jakarta.validation.constraints.NotNull; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.ColumnDefault; import java.util.UUID; @@ -28,7 +28,7 @@ @Table(name = "projects", indexes = { @Index(name = "idx_projects_key", columnList = "project_key", unique = true) }) -public class ProjectEntity extends AbstractEntity { +public class ProjectEntity extends IdentifiableEntity { @NotNull private String displayName; diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java index 472305e..437f37d 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundEventEntity.java @@ -3,15 +3,12 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.Index; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import jakarta.persistence.OneToMany; import jakarta.persistence.Table; +import jakarta.persistence.UniqueConstraint; import net.onelitefeather.vulpes.api.model.AbstractEntity; import net.onelitefeather.vulpes.api.model.project.ProjectEntity; import org.hibernate.annotations.ColumnDefault; -import org.hibernate.annotations.OnDelete; -import org.hibernate.annotations.OnDeleteAction; import java.util.List; import java.util.Objects; @@ -30,11 +27,12 @@ @Entity(name = "sounds") @Table(name = "sounds", indexes = { @Index(name = "idx_sounds_project_id", columnList = "project_id") +}, uniqueConstraints = { + @UniqueConstraint(name = "uq_sounds_project_key", columnNames = {"project_id", "key"}) }) public class SoundEventEntity extends AbstractEntity { private String uiName; - private String key; private String keyName; @Column(name = "replace_flag") @ColumnDefault("false") @@ -49,11 +47,6 @@ public class SoundEventEntity extends AbstractEntity { @OneToMany(mappedBy = "soundEvent") private List dataEntities; - @ManyToOne - @JoinColumn(name = "project_id", nullable = false) - @OnDelete(action = OnDeleteAction.CASCADE) - private ProjectEntity project; - /** * Default constructor for JPA and Micronaut Data. *

@@ -69,7 +62,9 @@ public SoundEventEntity() { * * @param id the unique identifier of the sound model * @param uiName the user interface name for the sound model - * @param key the namespaced key for the sound model (e.g. {@code minecraft:ambient.cave}) + * @param key the local key of the sound model within the project's namespace + * (e.g. {@code ambient.cave}, becomes {@code :ambient.cave} + * via {@link #getNamespacedKey()}) * @param keyName the key name for the sound model * @param replace whether to replace an existing sound model * @param subTitle the subtitle for the sound model @@ -77,14 +72,13 @@ public SoundEventEntity() { * @param project the project this sound event belongs to */ public SoundEventEntity(UUID id, String uiName, String key, String keyName, boolean replace, String subTitle, List dataEntities, ProjectEntity project) { + super(key, project); this.setId(id); this.uiName = uiName; this.keyName = keyName; - this.key = key; this.replace = replace; this.subTitle = subTitle; this.dataEntities = dataEntities; - this.project = project; } /** @@ -123,34 +117,6 @@ public String getKeyName() { return keyName; } - /** - * Set the namespaced key associated with this sound model (e.g. {@code minecraft:ambient.cave}). - * - * @param key the namespaced key to set - */ - public void setKey(String key) { - this.key = key; - } - - /** - * Returns the namespaced key associated with this sound model (e.g. {@code minecraft:ambient.cave}). - * - * @return the namespaced key - */ - public String getKey() { - return key; - } - - /** - * Derives the variable name of the sound model from its namespaced key, e.g. {@code minecraft:ambient.cave} - * becomes {@code AMBIENT.CAVE}. - * - * @return the derived variable name of the sound model - */ - public String getVariableName() { - int separatorIndex = key.indexOf(':'); - return (separatorIndex >= 0 ? key.substring(separatorIndex + 1) : key).toUpperCase(); - } /** * Sets the subtitle for the sound model. @@ -189,34 +155,16 @@ public void setSoundData(List soundDatumEntities) { this.dataEntities = soundDatumEntities; } - /** - * Returns the project this sound event belongs to. - * - * @return the project of the sound event - */ - public ProjectEntity getProject() { - return project; - } - - /** - * Sets the project this sound event belongs to. - * - * @param project the project to set - */ - public void setProject(ProjectEntity project) { - this.project = project; - } - @Override public boolean equals(Object o) { if (o == null || getClass() != o.getClass()) return false; SoundEventEntity that = (SoundEventEntity) o; - return replace == that.replace && Objects.equals(getId(), that.getId()) && Objects.equals(uiName, that.uiName) && Objects.equals(key, that.key) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(project, that.project); + return replace == that.replace && Objects.equals(getId(), that.getId()) && Objects.equals(uiName, that.uiName) && Objects.equals(getKey(), that.getKey()) && Objects.equals(keyName, that.keyName) && Objects.equals(subTitle, that.subTitle) && Objects.equals(dataEntities, that.dataEntities) && Objects.equals(getProject(), that.getProject()); } @Override public int hashCode() { - return Objects.hash(getId(), uiName, key, keyName, replace, subTitle, dataEntities, project); + return Objects.hash(getId(), uiName, getKey(), keyName, replace, subTitle, dataEntities, getProject()); } @Override @@ -224,12 +172,12 @@ public String toString() { return "SoundEventEntity{" + "id=" + getId() + ", uiName='" + uiName + '\'' + - ", key='" + key + '\'' + + ", key='" + getKey() + '\'' + ", keyName='" + keyName + '\'' + ", replace=" + replace + ", subTitle='" + subTitle + '\'' + ", dataEntities=" + dataEntities + - ", project=" + project + + ", project=" + getProject() + '}'; } } diff --git a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java index dda7edb..09a1459 100644 --- a/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java +++ b/src/main/java/net/onelitefeather/vulpes/api/model/sound/SoundFileSource.java @@ -3,7 +3,7 @@ import jakarta.persistence.Entity; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import net.onelitefeather.vulpes.api.model.AbstractEntity; +import net.onelitefeather.vulpes.api.model.IdentifiableEntity; import org.hibernate.annotations.ColumnDefault; import org.hibernate.annotations.OnDelete; import org.hibernate.annotations.OnDeleteAction; @@ -20,7 +20,7 @@ * @since 0.1.0 */ @Entity(name = "sound_data") -public class SoundFileSource extends AbstractEntity { +public class SoundFileSource extends IdentifiableEntity { private String name; @ColumnDefault("1.0")