|
22 | 22 |
|
23 | 23 | package me.wolfyscript.customcrafting.configs.recipebook; |
24 | 24 |
|
| 25 | +import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonAlias; |
25 | 26 | import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonGetter; |
26 | 27 | import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonIgnoreProperties; |
27 | 28 | import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonInclude; |
28 | 29 | import me.wolfyscript.lib.com.fasterxml.jackson.annotation.JsonSetter; |
29 | 30 | import me.wolfyscript.customcrafting.CustomCrafting; |
30 | 31 | import me.wolfyscript.customcrafting.recipes.CustomRecipe; |
31 | | -import me.wolfyscript.utilities.api.WolfyUtilities; |
32 | 32 | import me.wolfyscript.utilities.api.nms.network.MCByteBuf; |
33 | 33 | import me.wolfyscript.utilities.util.NamespacedKey; |
34 | 34 | import org.bukkit.Material; |
|
37 | 37 | import java.util.ArrayList; |
38 | 38 | import java.util.HashSet; |
39 | 39 | import java.util.List; |
| 40 | +import java.util.Objects; |
40 | 41 | import java.util.Set; |
41 | 42 |
|
42 | 43 | @JsonInclude(JsonInclude.Include.NON_NULL) |
43 | 44 | @JsonIgnoreProperties(ignoreUnknown = true) |
44 | | -public class CategorySettings { |
| 45 | +public abstract class CategorySettings { |
45 | 46 |
|
46 | 47 | protected Set<String> groups; |
47 | | - protected Set<String> namespaces; |
| 48 | + protected Set<String> folders; |
48 | 49 | protected Set<NamespacedKey> recipes; |
49 | 50 | private String id = ""; |
50 | 51 | private Material icon; |
51 | 52 | private String name; |
52 | 53 | private List<String> description; |
53 | 54 |
|
54 | | - public CategorySettings() { |
| 55 | + protected CategorySettings() { |
55 | 56 | this.name = ""; |
56 | 57 | this.icon = Material.CHEST; |
57 | 58 | this.groups = new HashSet<>(); |
58 | | - this.namespaces = new HashSet<>(); |
| 59 | + this.folders = new HashSet<>(); |
59 | 60 | this.description = new ArrayList<>(); |
60 | 61 | this.recipes = new HashSet<>(); |
61 | 62 | } |
62 | 63 |
|
63 | | - public CategorySettings(CategorySettings category) { |
| 64 | + protected CategorySettings(CategorySettings category) { |
64 | 65 | this.id = category.id; |
65 | 66 | this.name = category.name; |
66 | 67 | this.icon = category.getIcon(); |
67 | 68 | this.groups = new HashSet<>(category.groups); |
68 | | - this.namespaces = new HashSet<>(category.namespaces); |
| 69 | + this.folders = new HashSet<>(category.folders); |
69 | 70 | this.description = new ArrayList<>(category.getDescription()); |
70 | 71 | this.recipes = new HashSet<>(category.getRecipes()); |
71 | 72 | } |
@@ -118,12 +119,16 @@ public void setGroups(Set<String> groups) { |
118 | 119 | this.groups = groups; |
119 | 120 | } |
120 | 121 |
|
121 | | - public Set<String> getNamespaces() { |
122 | | - return namespaces; |
| 122 | + @JsonAlias("namespaces") |
| 123 | + @JsonGetter |
| 124 | + public Set<String> getFolders() { |
| 125 | + return folders; |
123 | 126 | } |
124 | 127 |
|
125 | | - public void setNamespaces(Set<String> namespaces) { |
126 | | - this.namespaces = namespaces; |
| 128 | + @JsonAlias("namespaces") |
| 129 | + @JsonSetter |
| 130 | + public void setFolders(Set<String> folders) { |
| 131 | + this.folders = folders; |
127 | 132 | } |
128 | 133 |
|
129 | 134 | @JsonGetter |
@@ -156,19 +161,32 @@ public String toString() { |
156 | 161 | return "CategorySettings{" + |
157 | 162 | "id='" + id + '\'' + |
158 | 163 | ", groups=" + groups + |
159 | | - ", namespaces=" + namespaces + |
| 164 | + ", namespaces=" + folders + |
160 | 165 | ", recipes=" + recipes + |
161 | 166 | '}'; |
162 | 167 | } |
163 | 168 |
|
| 169 | + @Override |
| 170 | + public boolean equals(Object o) { |
| 171 | + if (this == o) return true; |
| 172 | + if (o == null || getClass() != o.getClass()) return false; |
| 173 | + CategorySettings that = (CategorySettings) o; |
| 174 | + return Objects.equals(id, that.id); |
| 175 | + } |
| 176 | + |
| 177 | + @Override |
| 178 | + public int hashCode() { |
| 179 | + return Objects.hash(id); |
| 180 | + } |
| 181 | + |
164 | 182 | public void writeToByteBuf(MCByteBuf byteBuf) { |
165 | 183 | byteBuf.writeItemStack(new ItemStack(this.icon)); |
166 | 184 | byteBuf.writeUtf(this.name); |
167 | 185 | } |
168 | 186 |
|
169 | 187 | protected void writeData(MCByteBuf byteBuf) { |
170 | 188 | writeStringArray(new ArrayList<>(this.groups), byteBuf); |
171 | | - writeStringArray(new ArrayList<>(this.namespaces), byteBuf); |
| 189 | + writeStringArray(new ArrayList<>(this.folders), byteBuf); |
172 | 190 | writeStringArray(this.recipes.stream().map(NamespacedKey::toString).toList(), byteBuf); |
173 | 191 | } |
174 | 192 |
|
|
0 commit comments