Skip to content

Commit 0bc0c51

Browse files
committed
chore(item): rework item entity structure
1 parent 6b68a21 commit 0bc0c51

4 files changed

Lines changed: 102 additions & 14 deletions

File tree

src/main/java/net/onelitefeather/vulpes/api/model/ItemEntity.java

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package net.onelitefeather.vulpes.api.model;
22

3+
import jakarta.persistence.CascadeType;
34
import jakarta.persistence.ElementCollection;
45
import jakarta.persistence.Entity;
56
import jakarta.persistence.GeneratedValue;
67
import jakarta.persistence.GenerationType;
78
import jakarta.persistence.Id;
9+
import jakarta.persistence.OneToMany;
810
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
11+
import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity;
12+
import net.onelitefeather.vulpes.api.model.item.ItemFlagEntity;
13+
import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity;
914

1015
import java.util.List;
1116
import java.util.Map;
@@ -36,12 +41,12 @@ public class ItemEntity implements VulpesModel {
3641
private String groupName;
3742
private int customModelData;
3843
private int amount;
39-
@ElementCollection
40-
private Map<String, Short> enchantments;
41-
@ElementCollection
42-
private List<String> lore;
43-
@ElementCollection
44-
private List<String> flags;
44+
@OneToMany(cascade = CascadeType.ALL)
45+
private List<ItemEnchantmentEntity> enchantments;
46+
@OneToMany(cascade = CascadeType.ALL)
47+
private List<ItemLoreEntity> lore;
48+
@OneToMany(cascade = CascadeType.ALL)
49+
private List<ItemFlagEntity> flags;
4550

4651
/**
4752
* Default constructor for JPA and Micronaut Data.
@@ -69,7 +74,20 @@ public ItemEntity() {
6974
* @param lore the lore associated with the item
7075
* @param flags the flags associated with the item
7176
*/
72-
public ItemEntity(UUID id, String uiName, String variableName, String comment, String displayName, String material, String groupName, int customModelData, int amount, Map<String, Short> enchantments, List<String> lore, List<String> flags) {
77+
public ItemEntity(
78+
UUID id,
79+
String uiName,
80+
String variableName,
81+
String comment,
82+
String displayName,
83+
String material,
84+
String groupName,
85+
int customModelData,
86+
int amount,
87+
List<ItemEnchantmentEntity> enchantments,
88+
List<ItemLoreEntity> lore,
89+
List<ItemFlagEntity> flags
90+
) {
7391
this.id = id;
7492
this.uiName = uiName;
7593
this.variableName = variableName;
@@ -158,7 +176,6 @@ public void setComment(String description) {
158176
this.comment = description;
159177
}
160178

161-
162179
/**
163180
* Returns the display name of the item.
164181
*
@@ -254,7 +271,7 @@ public void setAmount(int amount) {
254271
*
255272
* @return the enchantments of the item
256273
*/
257-
public Map<String, Short> getEnchantments() {
274+
public List<ItemEnchantmentEntity> getEnchantments() {
258275
return enchantments;
259276
}
260277

@@ -263,7 +280,7 @@ public Map<String, Short> getEnchantments() {
263280
*
264281
* @param enchantments the enchantments to set
265282
*/
266-
public void setEnchantments(Map<String, Short> enchantments) {
283+
public void setEnchantments(List<ItemEnchantmentEntity> enchantments) {
267284
this.enchantments = enchantments;
268285
}
269286

@@ -272,7 +289,7 @@ public void setEnchantments(Map<String, Short> enchantments) {
272289
*
273290
* @return the lore of the item
274291
*/
275-
public List<String> getLore() {
292+
public List<ItemLoreEntity> getLore() {
276293
return lore;
277294
}
278295

@@ -281,7 +298,7 @@ public List<String> getLore() {
281298
*
282299
* @param lore the lore to set
283300
*/
284-
public void setLore(List<String> lore) {
301+
public void setLore(List<ItemLoreEntity> lore) {
285302
this.lore = lore;
286303
}
287304

@@ -290,7 +307,7 @@ public void setLore(List<String> lore) {
290307
*
291308
* @return the flags of the item
292309
*/
293-
public List<String> getFlags() {
310+
public List<ItemFlagEntity> getFlags() {
294311
return flags;
295312
}
296313

@@ -299,7 +316,7 @@ public List<String> getFlags() {
299316
*
300317
* @param flags the flags to set
301318
*/
302-
public void setFlags(List<String> flags) {
319+
public void setFlags(List<ItemFlagEntity> flags) {
303320
this.flags = flags;
304321
}
305322

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package net.onelitefeather.vulpes.api.model.item;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
8+
9+
import java.util.UUID;
10+
11+
@Entity(name = "item_enchantments")
12+
public record ItemEnchantmentEntity(
13+
@Id
14+
@GeneratedValue(strategy = GenerationType.UUID)
15+
@VulpesGenerator
16+
UUID id,
17+
String name,
18+
short level
19+
) {
20+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package net.onelitefeather.vulpes.api.model.item;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
8+
9+
import java.util.UUID;
10+
11+
/**
12+
* The {@link ItemFlagEntity} represents a flag or attribute that can be associated with an item in the system.
13+
*
14+
* @param id the unique identifier of the item flag
15+
* @param text the descriptive text of the item flag
16+
*/
17+
@Entity(name = "item_flags")
18+
public record ItemFlagEntity(
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.UUID)
21+
@VulpesGenerator
22+
UUID id,
23+
String text
24+
) {
25+
26+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package net.onelitefeather.vulpes.api.model.item;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
8+
9+
import java.util.UUID;
10+
11+
/**
12+
* The {@link ItemLoreEntity} represents a lore entry associated with an item.
13+
*
14+
* @param id the unique identifier of the lore entry
15+
* @param text the lore text
16+
*/
17+
@Entity(name = "item_lore")
18+
public record ItemLoreEntity(
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.UUID)
21+
@VulpesGenerator
22+
UUID id,
23+
String text
24+
) {
25+
}

0 commit comments

Comments
 (0)