@@ -240,53 +240,71 @@ public void run() throws IOException {
240240 }
241241
242242 public CodeBlock generateMappings (ConfigurationNode node ) {
243+ return generateMappings (List .of (node ));
244+ }
245+
246+ public CodeBlock generateMappings (List <ConfigurationNode > nodes ) {
243247 var codeBlock = CodeBlock .builder ()
244248 .add ("mapper -> {\n " )
245249 .indent ();
246250
247- var obfuscatedFallback = node .node ("OBFUSCATED" )
248- .childrenMap ()
249- .entrySet ()
250- .stream ()
251- .flatMap (entry -> Arrays .stream (entry .getKey ().toString ().split ("," )).map (s1 -> Map .entry (s1 , entry .getValue ().getString ("" ))))
252- .filter (stringStringEntry -> {
253- if (
254- (configuration .getMinMinecraftVersion () != null && !configuration .getMinMinecraftVersion ().isEmpty ())
255- || (configuration .getMaxMinecraftVersion () != null && !configuration .getMaxMinecraftVersion ().isEmpty ())
256- ) {
257- var version = new ComparableVersion (stringStringEntry .getKey ());
258- if (configuration .getMinMinecraftVersion () != null && !configuration .getMinMinecraftVersion ().isEmpty ()) {
259- var min = new ComparableVersion (configuration .getMinMinecraftVersion ());
260- if (version .compareTo (min ) < 0 ) {
261- return false ;
262- }
251+ var usedNode = new HashMap <String , ConfigurationNode >();
252+ var rawObfuscatedFallback = new HashMap <String , String >();
253+ nodes .forEach (node -> {
254+ node .node ("OBFUSCATED" )
255+ .childrenMap ()
256+ .entrySet ()
257+ .stream ()
258+ .flatMap (entry -> Arrays .stream (entry .getKey ().toString ().split ("," )).map (s1 -> Map .entry (s1 , entry .getValue ().getString ("" ))))
259+ .filter (stringStringEntry -> {
260+ if (rawObfuscatedFallback .containsKey (stringStringEntry .getKey ())) {
261+ return false ; // don't overwrite it
263262 }
264- if (configuration .getMaxMinecraftVersion () != null && !configuration .getMaxMinecraftVersion ().isEmpty ()) {
265- var max = new ComparableVersion (configuration .getMaxMinecraftVersion ());
266- if (version .compareTo (max ) > 0 ) {
267- return false ;
263+
264+ if (
265+ (configuration .getMinMinecraftVersion () != null && !configuration .getMinMinecraftVersion ().isEmpty ())
266+ || (configuration .getMaxMinecraftVersion () != null && !configuration .getMaxMinecraftVersion ().isEmpty ())
267+ ) {
268+ var version = new ComparableVersion (stringStringEntry .getKey ());
269+ if (configuration .getMinMinecraftVersion () != null && !configuration .getMinMinecraftVersion ().isEmpty ()) {
270+ var min = new ComparableVersion (configuration .getMinMinecraftVersion ());
271+ if (version .compareTo (min ) < 0 ) {
272+ return false ;
273+ }
274+ }
275+ if (configuration .getMaxMinecraftVersion () != null && !configuration .getMaxMinecraftVersion ().isEmpty ()) {
276+ var max = new ComparableVersion (configuration .getMaxMinecraftVersion ());
277+ if (version .compareTo (max ) > 0 ) {
278+ return false ;
279+ }
268280 }
269281 }
270- }
271- return true ;
272- })
282+ return true ;
283+ })
284+ .forEach (e -> {
285+ rawObfuscatedFallback .put (e .getKey (), e .getValue ());
286+ usedNode .put (e .getKey (), node );
287+ });
288+ });
289+ var obfuscatedFallback = rawObfuscatedFallback .entrySet ()
290+ .stream ()
273291 .sorted (Comparator .comparing (o -> new ComparableVersion (o .getKey ())))
274292 .collect (Collectors .toList ());
275293
294+
276295 // currently support spigot and searge. vanilla servers are not supported
277296 var spigotLatest = new AtomicReference <String >();
278297
279- var allSpigotMappings = node .node ("SPIGOT" ).childrenMap ().entrySet ()
280- .stream ()
281- .flatMap (entry -> Arrays .stream (entry .getKey ().toString ().split ("," )).map (s1 -> Map .entry (s1 , entry .getValue ().getString ("" ))))
282- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
283-
284298 obfuscatedFallback .forEach (entry -> {
285- var value = entry .getValue ();
286-
287- if (allSpigotMappings .containsKey (entry .getKey ())) {
288- value = allSpigotMappings .get (entry .getKey ());
289- }
299+ var value = usedNode .get (entry .getKey ())
300+ .node ("SPIGOT" )
301+ .childrenMap ()
302+ .entrySet ()
303+ .stream ()
304+ .filter (e -> Arrays .asList (e .getKey ().toString ().split ("," )).contains (entry .getKey ()))
305+ .findFirst ()
306+ .map (e -> e .getValue ().getString ())
307+ .orElse (entry .getValue ());
290308
291309 if (spigotLatest .get () == null || !spigotLatest .get ().equals (value )) {
292310 codeBlock .add ("$N.$N($S, $S, $S);\n " , "mapper" , "map" , "spigot" , entry .getKey (), value );
@@ -297,16 +315,19 @@ public CodeBlock generateMappings(ConfigurationNode node) {
297315
298316 var seargeLatest = new AtomicReference <String >();
299317
300- var allSeargeMappings = node .node ("SEARGE" ).childrenMap ().entrySet ()
301- .stream ()
302- .flatMap (entry -> Arrays .stream (entry .getKey ().toString ().split ("," )).map (s1 -> Map .entry (s1 , entry .getValue ().getString ("" ))))
303- .collect (Collectors .toMap (Map .Entry ::getKey , Map .Entry ::getValue ));
304-
305318 obfuscatedFallback .forEach (entry -> {
306319 var value = entry .getValue ();
307-
308- if (allSeargeMappings .containsKey (entry .getKey ())) {
309- value = allSeargeMappings .get (entry .getKey ());
320+ var seargeValue = usedNode .get (entry .getKey ())
321+ .node ("SEARGE" )
322+ .childrenMap ()
323+ .entrySet ()
324+ .stream ()
325+ .filter (e -> Arrays .asList (e .getKey ().toString ().split ("," )).contains (entry .getKey ()))
326+ .findFirst ()
327+ .map (e -> e .getValue ().getString ());
328+
329+ if (seargeValue .isPresent ()) {
330+ value = seargeValue .get ();
310331 } else if (seargeLatest .get () != null ) {
311332 // Searge mappings are usually consistent across versions, so skip the mapping if there's no value in mappings but there's value in the seargeLatest variable
312333 return ;
0 commit comments