Skip to content

Commit 2938988

Browse files
Merge pull request #54 from OneLiteFeatherNET/rework/databaseEntities
chore(item): rework entity structure
2 parents 6b68a21 + 502fe29 commit 2938988

File tree

15 files changed

+586
-92
lines changed

15 files changed

+586
-92
lines changed

.github/workflows/build-pr.yml

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,8 @@ jobs:
1818
uses: actions/setup-java@v4
1919
with:
2020
distribution: temurin
21-
java-version: 24
21+
java-version: 25
2222
- name: Setup Gradle
2323
uses: gradle/actions/setup-gradle@v4
2424
- name: Build on ${{ matrix.os }}
2525
run: ./gradlew clean build test
26-
- name: Generate JaCoCo Coverage Report
27-
if: matrix.os == 'ubuntu-latest'
28-
run: ./gradlew jacocoRootReport
29-
- name: Upload Coverage Report
30-
if: matrix.os == 'ubuntu-latest'
31-
uses: actions/upload-artifact@v4
32-
with:
33-
name: jacoco-report
34-
path: |
35-
build/reports/jacoco/jacocoRootReport/html/
36-
build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml
37-
- name: Upload Coverage to Codecov
38-
if: matrix.os == 'ubuntu-latest'
39-
uses: codecov/codecov-action@v5
40-
with:
41-
file: build/reports/jacoco/jacocoRootReport/jacocoRootReport.xml
42-
fail_ci_if_error: false
43-
token: ${{ secrets.CODECOV_TOKEN }}
44-
comment: true

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ tasks {
3232
}
3333

3434
test {
35-
finalizedBy(rootProject.tasks.jacocoTestReport)
35+
finalizedBy(jacocoTestReport)
3636
testLogging {
3737
events("passed", "skipped", "failed")
3838
}

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

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

3-
import jakarta.persistence.ElementCollection;
3+
import jakarta.persistence.CascadeType;
44
import jakarta.persistence.Entity;
55
import jakarta.persistence.GeneratedValue;
66
import jakarta.persistence.GenerationType;
77
import jakarta.persistence.Id;
8+
import jakarta.persistence.OneToMany;
89
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
10+
import net.onelitefeather.vulpes.api.model.font.FontLoreEntity;
911

1012
import java.util.List;
1113
import java.util.UUID;
@@ -34,8 +36,8 @@ public class FontEntity implements VulpesModel {
3436
private String comment;
3537
private int height;
3638
private int ascent;
37-
@ElementCollection
38-
private List<String> chars;
39+
@OneToMany(mappedBy = "font", cascade = CascadeType.ALL)
40+
private List<FontLoreEntity> chars;
3941

4042
/**
4143
* Default constructor for JPA and Micronaut Data.
@@ -60,7 +62,17 @@ public FontEntity() {
6062
* @param ascent the ascent of the font
6163
* @param chars the list of characters included in the font
6264
*/
63-
public FontEntity(UUID id, String uiName, String variableName, String provider, String texturePath, String comment, int height, int ascent, List<String> chars) {
65+
public FontEntity(
66+
UUID id,
67+
String uiName,
68+
String variableName,
69+
String provider,
70+
String texturePath,
71+
String comment,
72+
int height,
73+
int ascent,
74+
List<FontLoreEntity> chars
75+
) {
6476
this.id = id;
6577
this.uiName = uiName;
6678
this.variableName = variableName;
@@ -181,7 +193,7 @@ public void setHeight(int height) {
181193
*
182194
* @return the list of characters in the font
183195
*/
184-
public List<String> getChars() {
196+
public List<FontLoreEntity> getChars() {
185197
return chars;
186198
}
187199

@@ -190,7 +202,7 @@ public List<String> getChars() {
190202
*
191203
* @param chars the list of characters to set
192204
*/
193-
public void setChars(List<String> chars) {
205+
public void setChars(List<FontLoreEntity> chars) {
194206
this.chars = chars;
195207
}
196208

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

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

3-
import jakarta.persistence.ElementCollection;
3+
import jakarta.persistence.CascadeType;
44
import jakarta.persistence.Entity;
55
import jakarta.persistence.GeneratedValue;
66
import jakarta.persistence.GenerationType;
77
import jakarta.persistence.Id;
8+
import jakarta.persistence.OneToMany;
89
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
10+
import net.onelitefeather.vulpes.api.model.item.ItemEnchantmentEntity;
11+
import net.onelitefeather.vulpes.api.model.item.ItemFlagEntity;
12+
import net.onelitefeather.vulpes.api.model.item.ItemLoreEntity;
913

1014
import java.util.List;
11-
import java.util.Map;
1215
import java.util.UUID;
1316

1417
/**
@@ -36,12 +39,12 @@ public class ItemEntity implements VulpesModel {
3639
private String groupName;
3740
private int customModelData;
3841
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;
42+
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL)
43+
private List<ItemEnchantmentEntity> enchantments;
44+
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL)
45+
private List<ItemLoreEntity> lore;
46+
@OneToMany(mappedBy = "item", cascade = CascadeType.ALL)
47+
private List<ItemFlagEntity> flags;
4548

4649
/**
4750
* Default constructor for JPA and Micronaut Data.
@@ -69,7 +72,20 @@ public ItemEntity() {
6972
* @param lore the lore associated with the item
7073
* @param flags the flags associated with the item
7174
*/
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) {
75+
public ItemEntity(
76+
UUID id,
77+
String uiName,
78+
String variableName,
79+
String comment,
80+
String displayName,
81+
String material,
82+
String groupName,
83+
int customModelData,
84+
int amount,
85+
List<ItemEnchantmentEntity> enchantments,
86+
List<ItemLoreEntity> lore,
87+
List<ItemFlagEntity> flags
88+
) {
7389
this.id = id;
7490
this.uiName = uiName;
7591
this.variableName = variableName;
@@ -158,7 +174,6 @@ public void setComment(String description) {
158174
this.comment = description;
159175
}
160176

161-
162177
/**
163178
* Returns the display name of the item.
164179
*
@@ -254,7 +269,7 @@ public void setAmount(int amount) {
254269
*
255270
* @return the enchantments of the item
256271
*/
257-
public Map<String, Short> getEnchantments() {
272+
public List<ItemEnchantmentEntity> getEnchantments() {
258273
return enchantments;
259274
}
260275

@@ -263,7 +278,7 @@ public Map<String, Short> getEnchantments() {
263278
*
264279
* @param enchantments the enchantments to set
265280
*/
266-
public void setEnchantments(Map<String, Short> enchantments) {
281+
public void setEnchantments(List<ItemEnchantmentEntity> enchantments) {
267282
this.enchantments = enchantments;
268283
}
269284

@@ -272,7 +287,7 @@ public void setEnchantments(Map<String, Short> enchantments) {
272287
*
273288
* @return the lore of the item
274289
*/
275-
public List<String> getLore() {
290+
public List<ItemLoreEntity> getLore() {
276291
return lore;
277292
}
278293

@@ -281,7 +296,7 @@ public List<String> getLore() {
281296
*
282297
* @param lore the lore to set
283298
*/
284-
public void setLore(List<String> lore) {
299+
public void setLore(List<ItemLoreEntity> lore) {
285300
this.lore = lore;
286301
}
287302

@@ -290,7 +305,7 @@ public void setLore(List<String> lore) {
290305
*
291306
* @return the flags of the item
292307
*/
293-
public List<String> getFlags() {
308+
public List<ItemFlagEntity> getFlags() {
294309
return flags;
295310
}
296311

@@ -299,7 +314,7 @@ public List<String> getFlags() {
299314
*
300315
* @param flags the flags to set
301316
*/
302-
public void setFlags(List<String> flags) {
317+
public void setFlags(List<ItemFlagEntity> flags) {
303318
this.flags = flags;
304319
}
305320

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package net.onelitefeather.vulpes.api.model.font;
2+
3+
import jakarta.persistence.Entity;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import jakarta.persistence.JoinColumn;
8+
import jakarta.persistence.ManyToOne;
9+
import net.onelitefeather.vulpes.api.generator.VulpesGenerator;
10+
import net.onelitefeather.vulpes.api.model.FontEntity;
11+
12+
import java.util.Objects;
13+
import java.util.UUID;
14+
15+
@Entity(name = "font_lore")
16+
public final class FontLoreEntity implements Comparable<FontLoreEntity> {
17+
@Id
18+
@GeneratedValue(strategy = GenerationType.UUID)
19+
@VulpesGenerator
20+
private UUID id;
21+
private String line;
22+
@ManyToOne
23+
@JoinColumn(name = "font_id", nullable = false)
24+
private FontEntity font;
25+
private int orderIndex;
26+
27+
public FontLoreEntity() {
28+
}
29+
30+
public FontLoreEntity(
31+
UUID id,
32+
String line,
33+
FontEntity font,
34+
int orderIndex
35+
) {
36+
this.id = id;
37+
this.line = line;
38+
this.font = font;
39+
this.orderIndex = orderIndex;
40+
}
41+
42+
public void setId(UUID id) {
43+
this.id = id;
44+
}
45+
46+
public UUID getId() {
47+
return id;
48+
}
49+
50+
public void setLine(String line) {
51+
this.line = line;
52+
}
53+
54+
public String getLine() {
55+
return line;
56+
}
57+
58+
public void setFont(FontEntity font) {
59+
this.font = font;
60+
}
61+
62+
public FontEntity getFont() {
63+
return font;
64+
}
65+
66+
public void setOrderIndex(int orderIndex) {
67+
this.orderIndex = orderIndex;
68+
}
69+
70+
public int getOrderIndex() {
71+
return orderIndex;
72+
}
73+
74+
@Override
75+
public boolean equals(Object obj) {
76+
if (obj == this) return true;
77+
if (obj == null || obj.getClass() != this.getClass()) return false;
78+
var that = (FontLoreEntity) obj;
79+
return Objects.equals(this.id, that.id) &&
80+
Objects.equals(this.line, that.line) &&
81+
Objects.equals(this.font, that.font);
82+
}
83+
84+
@Override
85+
public int hashCode() {
86+
return Objects.hash(id, line, font);
87+
}
88+
89+
@Override
90+
public String toString() {
91+
return "FontLoreEntity[" +
92+
"id=" + id + ", " +
93+
"line=" + line + ", " +
94+
"font=" + font + ']';
95+
}
96+
97+
@Override
98+
public int compareTo(FontLoreEntity o) {
99+
return Integer.compare(this.orderIndex, o.orderIndex);
100+
}
101+
}

0 commit comments

Comments
 (0)