26
26
import noobanidus .mods .lootr .common .api .registry .LootrRegistry ;
27
27
28
28
import java .util .*;
29
+ import java .util .function .Function ;
29
30
import java .util .stream .Collectors ;
30
31
31
32
@ Config (name = LootrAPI .MODID )
@@ -97,7 +98,7 @@ public static void reset() {
97
98
REFRESH_TABLES = null ;
98
99
}
99
100
100
- private static Set <String > validateStringList (List <String > incomingList , String listKey ) {
101
+ private static Set <String > validateStringList (Collection <String > incomingList , String listKey ) {
101
102
Set <String > validatedList = new HashSet <>();
102
103
for (String entry : incomingList ) {
103
104
if (entry == null || entry .isEmpty ()) {
@@ -109,29 +110,40 @@ private static Set<String> validateStringList(List<String> incomingList, String
109
110
return validatedList ;
110
111
}
111
112
112
- private static Set <ResourceKey <Level >> validateDimensions (List <String > incomingList , String listKey ) {
113
- Set <ResourceKey <Level >> validatedList = new HashSet <>();
113
+ private static Set <ResourceKey <Level >> validateDimensions (Collection <String > incomingList , String listKey ) {
114
+ return validateResourceKeyList (incomingList , listKey , o -> ResourceKey .create (Registries .DIMENSION , o ));
115
+ }
116
+
117
+ private static <T > Set <ResourceKey <T >> validateResourceKeyList (Collection <String > incomingList , String listKey , Function <ResourceLocation , ResourceKey <T >> builder ) {
118
+ Set <ResourceKey <T >> validatedList = new HashSet <>();
114
119
for (String entry : incomingList ) {
115
120
if (entry == null || entry .isEmpty ()) {
116
- throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. One of the entries is null or empty and cannot be converted to a dimension identifier." );
121
+ throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. One of the entries is null or empty and cannot be converted to a ResourceLocation." );
122
+ }
123
+ ResourceLocation location ;
124
+ try {
125
+ location = ResourceLocation .parse (entry );
126
+ } catch (Exception e ) {
127
+ throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. The value found in the list, '" + entry + "', is not a valid ResourceLocation." , e );
117
128
}
129
+
118
130
try {
119
- validatedList .add (ResourceKey . create ( Registries . DIMENSION , ResourceLocation . withDefaultNamespace ( entry ) ));
131
+ validatedList .add (builder . apply ( location ));
120
132
} catch (Exception e ) {
121
- throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. The value found in the list, '" + entry + "', is not a valid dimension identifier ." , e );
133
+ throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. The value found in the list, '" + entry + "', is not valid to create a ResourceKey ." , e );
122
134
}
123
135
}
124
136
return validatedList ;
125
137
}
126
138
127
- private static Set <ResourceLocation > validateResourceLocationList (List <String > incomingList , String listKey ) {
139
+ private static Set <ResourceLocation > validateResourceLocationList (Collection <String > incomingList , String listKey ) {
128
140
Set <ResourceLocation > validatedList = new HashSet <>();
129
141
for (String entry : incomingList ) {
130
142
if (entry == null || entry .isEmpty ()) {
131
143
throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. One of the entries is null or empty and cannot be converted to a ResourceLocation." );
132
144
}
133
145
try {
134
- validatedList .add (ResourceLocation .withDefaultNamespace (entry ));
146
+ validatedList .add (ResourceLocation .parse (entry ));
135
147
} catch (Exception e ) {
136
148
throw new RuntimeException ("Error found when validating a configuration list for '" + listKey + "'. The value found in the list, '" + entry + "', is not a valid ResourceLocation." , e );
137
149
}
@@ -145,49 +157,49 @@ public static ConfigManager get() {
145
157
146
158
public static Set <ResourceKey <Level >> getDimensionWhitelist () {
147
159
if (DIM_WHITELIST == null ) {
148
- DIM_WHITELIST = get ().lists .dimension_whitelist . stream (). map ( o -> ResourceKey . create ( Registries . DIMENSION , ResourceLocation . parse ( o ))). collect ( Collectors . toSet () );
160
+ DIM_WHITELIST = validateDimensions ( get ().lists .dimension_whitelist , "dimension_whitelist" );
149
161
}
150
162
return DIM_WHITELIST ;
151
163
}
152
164
153
165
public static Set <String > getDimensionModidWhitelist () {
154
166
if (MODID_DIM_WHITELIST == null ) {
155
- MODID_DIM_WHITELIST = get ().lists .modid_dimension_whitelist . stream (). map ( o -> o . toLowerCase ( Locale . ROOT )). collect ( Collectors . toSet () );
167
+ MODID_DIM_WHITELIST = validateStringList ( get ().lists .modid_dimension_whitelist , "modid_dimension_whitelist" );
156
168
}
157
169
return MODID_DIM_WHITELIST ;
158
170
}
159
171
160
172
public static Set <ResourceKey <Level >> getDimensionBlacklist () {
161
173
if (DIM_BLACKLIST == null ) {
162
- DIM_BLACKLIST = get ().lists .dimension_blacklist . stream (). map ( o -> ResourceKey . create ( Registries . DIMENSION , ResourceLocation . parse ( o ))). collect ( Collectors . toSet () );
174
+ DIM_BLACKLIST = validateDimensions ( get ().lists .dimension_blacklist , "dimension_blacklist" );
163
175
}
164
176
return DIM_BLACKLIST ;
165
177
}
166
178
167
179
public static Set <String > getDimensionModidBlacklist () {
168
180
if (MODID_DIM_BLACKLIST == null ) {
169
- MODID_DIM_BLACKLIST = get ().lists .modid_dimension_blacklist . stream (). map ( o -> o . toLowerCase ( Locale . ROOT )). collect ( Collectors . toSet () );
181
+ MODID_DIM_BLACKLIST = validateStringList ( get ().lists .modid_dimension_blacklist , "modid_dimension_blacklist" );
170
182
}
171
183
return MODID_DIM_BLACKLIST ;
172
184
}
173
185
174
186
public static Set <ResourceKey <Level >> getDecayDimensions () {
175
187
if (DECAY_DIMS == null ) {
176
- DECAY_DIMS = get ().decay .decay_dimensions . stream (). map ( o -> ResourceKey . create ( Registries . DIMENSION , ResourceLocation . parse ( o ))). collect ( Collectors . toSet () );
188
+ DECAY_DIMS = validateDimensions ( get ().decay .decay_dimensions , "decay_dimensions" );
177
189
}
178
190
return DECAY_DIMS ;
179
191
}
180
192
181
193
public static Set <ResourceKey <Level >> getRefreshDimensions () {
182
194
if (REFRESH_DIMS == null ) {
183
- REFRESH_DIMS = get ().refresh .refresh_dimensions . stream (). map ( o -> ResourceKey . create ( Registries . DIMENSION , ResourceLocation . parse ( o ))). collect ( Collectors . toSet () );
195
+ REFRESH_DIMS = validateDimensions ( get ().refresh .refresh_dimensions , "refresh_dimensions" );
184
196
}
185
197
return REFRESH_DIMS ;
186
198
}
187
199
188
200
public static Set <ResourceKey <LootTable >> getLootBlacklist () {
189
201
if (LOOT_BLACKLIST == null ) {
190
- LOOT_BLACKLIST = get ().lists .loot_table_blacklist . stream (). map ( o -> ResourceKey .create (Registries .LOOT_TABLE , ResourceLocation . parse ( o ))). collect ( Collectors . toSet ( ));
202
+ LOOT_BLACKLIST = validateResourceKeyList ( get ().lists .loot_table_blacklist , "loot_blacklist" , o -> ResourceKey .create (Registries .LOOT_TABLE , o ));
191
203
// Fixes for #79 and #74
192
204
PROBLEMATIC_CHESTS .forEach (o -> LOOT_BLACKLIST .add (ResourceKey .create (Registries .LOOT_TABLE , o )));
193
205
}
@@ -196,7 +208,7 @@ public static Set<ResourceKey<LootTable>> getLootBlacklist() {
196
208
197
209
public static Set <String > getLootModidsBlacklist () {
198
210
if (LOOT_MODIDS == null ) {
199
- LOOT_MODIDS = get ().lists .loot_modid_blacklist . stream (). map ( o -> o . toLowerCase ( Locale . ROOT )). collect ( Collectors . toSet () );
211
+ LOOT_MODIDS = validateStringList ( get ().lists .loot_modid_blacklist , "loot_modid_blacklist" );
200
212
}
201
213
return LOOT_MODIDS ;
202
214
}
@@ -211,28 +223,28 @@ public static boolean isBlacklisted(ResourceKey<LootTable> table) {
211
223
212
224
public static Set <ResourceKey <LootTable >> getDecayingTables () {
213
225
if (DECAY_TABLES == null ) {
214
- DECAY_TABLES = get ().decay .decay_loot_tables . stream (). map ( o -> ResourceKey .create (Registries .LOOT_TABLE , ResourceLocation . parse ( o ))). collect ( Collectors . toSet ( ));
226
+ DECAY_TABLES = validateResourceKeyList ( get ().decay .decay_loot_tables , "decay_loot_tables" , o -> ResourceKey .create (Registries .LOOT_TABLE , o ));
215
227
}
216
228
return DECAY_TABLES ;
217
229
}
218
230
219
231
public static Set <String > getDecayMods () {
220
232
if (DECAY_MODS == null ) {
221
- DECAY_MODS = get ().decay .decay_modids . stream (). map ( o -> o . toLowerCase ( Locale . ROOT )). collect ( Collectors . toSet () );
233
+ DECAY_MODS = validateStringList ( get ().decay .decay_modids , "decay_mods" );
222
234
}
223
235
return DECAY_MODS ;
224
236
}
225
237
226
238
public static Set <ResourceKey <LootTable >> getRefreshingTables () {
227
239
if (REFRESH_TABLES == null ) {
228
- REFRESH_TABLES = get ().refresh .refresh_loot_tables . stream (). map ( o -> ResourceKey .create (Registries .LOOT_TABLE , ResourceLocation . parse ( o ))). collect ( Collectors . toSet ( ));
240
+ REFRESH_TABLES = validateResourceKeyList ( get ().refresh .refresh_loot_tables , "refresh_tables" , o -> ResourceKey .create (Registries .LOOT_TABLE , o ));
229
241
}
230
242
return REFRESH_TABLES ;
231
243
}
232
244
233
245
public static Set <String > getRefreshMods () {
234
246
if (REFRESH_MODS == null ) {
235
- REFRESH_MODS = get ().refresh .refresh_modids . stream (). map ( o -> o . toLowerCase ( Locale . ROOT )). collect ( Collectors . toSet () );
247
+ REFRESH_MODS = validateStringList ( get ().refresh .refresh_modids , "refresh_modids" );
236
248
}
237
249
return REFRESH_MODS ;
238
250
}
0 commit comments