1717 */
1818package com .viaversion .viabackwards .api .rewriters ;
1919
20- import com .viaversion .viabackwards .ViaBackwards ;
2120import com .viaversion .viabackwards .api .BackwardsProtocol ;
2221import com .viaversion .viabackwards .api .data .BackwardsMappingDataLoader ;
2322import com .viaversion .viaversion .api .connection .UserConnection ;
@@ -37,10 +36,16 @@ public class TranslatableRewriter<C extends ClientboundPacketType> extends Compo
3736 private final Map <String , String > translatables ;
3837
3938 public static void loadTranslatables () {
40- final JsonObject jsonObject = BackwardsMappingDataLoader .INSTANCE .loadFromDataDir ("translation-mappings.json" );
39+ if (!TRANSLATABLES .isEmpty ()) {
40+ throw new IllegalStateException ("Translatables already loaded!" );
41+ }
42+ fillTranslatables (BackwardsMappingDataLoader .INSTANCE .loadFromDataDir ("translation-mappings.json" ), TRANSLATABLES );
43+ }
44+
45+ public static void fillTranslatables (final JsonObject jsonObject , final Map <String , Map <String , String >> translatables ) {
4146 for (final Map .Entry <String , JsonElement > entry : jsonObject .entrySet ()) {
4247 final Map <String , String > versionMappings = new HashMap <>();
43- TRANSLATABLES .put (entry .getKey (), versionMappings );
48+ translatables .put (entry .getKey (), versionMappings );
4449 for (final Map .Entry <String , JsonElement > translationEntry : entry .getValue ().getAsJsonObject ().entrySet ()) {
4550 versionMappings .put (translationEntry .getKey (), translationEntry .getValue ().getAsString ());
4651 }
@@ -53,7 +58,7 @@ public TranslatableRewriter(final BackwardsProtocol<C, ?, ?, ?> protocol, final
5358
5459 public TranslatableRewriter (final BackwardsProtocol <C , ?, ?, ?> protocol , final ReadType type , final String sectionIdentifier ) {
5560 super (protocol , type );
56- final Map <String , String > translatableMappings = TRANSLATABLES . get (sectionIdentifier );
61+ final Map <String , String > translatableMappings = getTranslatableMappings (sectionIdentifier );
5762 if (translatableMappings == null ) {
5863 protocol .getLogger ().warning ("Missing " + sectionIdentifier + " translatables!" );
5964 this .translatables = new HashMap <>();
@@ -81,4 +86,8 @@ protected void handleTranslate(final UserConnection connection, final CompoundTa
8186 public @ Nullable String mappedTranslationKey (final String translationKey ) {
8287 return translatables .get (translationKey );
8388 }
89+
90+ public Map <String , String > getTranslatableMappings (final String sectionIdentifier ) {
91+ return TRANSLATABLES .get (sectionIdentifier );
92+ }
8493}
0 commit comments