3535import com .falsepattern .lib .toasts .SimpleToast ;
3636import com .falsepattern .lib .toasts .icon .ToastBG ;
3737import com .falsepattern .lib .util .FileUtil ;
38+ import com .google .common .collect .BiMap ;
39+ import com .google .common .collect .HashBiMap ;
3840import lombok .AccessLevel ;
3941import lombok .NoArgsConstructor ;
4042import lombok .SneakyThrows ;
@@ -81,6 +83,7 @@ public class ConfigurationManagerImpl {
8183 private static final Map <String , Configuration > configs = new HashMap <>();
8284 private static final Map <Configuration , Set <Class <?>>> configToClassMap = new HashMap <>();
8385 private static final Map <Class <?>, ParsedConfiguration > parsedConfigMap = new HashMap <>();
86+ private static final BiMap <String , Class <?>> serializedNames = HashBiMap .create ();
8487 private static final ConfigurationManagerImpl instance = new ConfigurationManagerImpl ();
8588 private static boolean initialized = false ;
8689 private static Path configDir ;
@@ -91,6 +94,7 @@ public static void register(Class<?> configClass) throws ConfigException {
9194 val parsedConfig = ParsedConfiguration .parseConfig (configClass );
9295 configToClassMap .computeIfAbsent (parsedConfig .rawConfig , (ignored ) -> new HashSet <>()).add (configClass );
9396 parsedConfigMap .put (configClass , ParsedConfiguration .parseConfig (configClass ));
97+ serializedNames .put (parsedConfig .modid + "$" + parsedConfig .category , configClass );
9498 }
9599 }
96100
@@ -134,27 +138,28 @@ public static void registerLoadSaveConfig(Class<?> configClass) throws ConfigExc
134138
135139 public static void sendRequest (DataOutput output ) throws IOException {
136140 val synced = new ArrayList <Class <?>>();
141+ val inv = serializedNames .inverse ();
137142 for (val entry : parsedConfigMap .entrySet ()) {
138143 if (entry .getValue ().sync ) {
139144 synced .add (entry .getKey ());
140145 }
141146 }
142147 output .writeInt (synced .size ());
143148 for (val clazz : synced ) {
144- output .writeUTF (clazz . getName ( ));
149+ output .writeUTF (inv . get ( clazz ));
145150 }
146151 }
147152
148153 public static List <Class <?>> receiveRequest (DataInput input ) throws IOException {
149154 val result = new ArrayList <Class <?>>();
150155 val count = input .readInt ();
151- val classNames = new HashSet <String >();
156+ val requestedNames = new HashSet <String >();
152157 for (int i = 0 ; i < count ; i ++) {
153- classNames .add (input .readUTF ());
158+ requestedNames .add (input .readUTF ());
154159 }
155- for (val entry : parsedConfigMap .keySet ()) {
156- if (classNames .contains (entry . getName () )) {
157- result .add (entry );
160+ for (val entry : serializedNames .keySet ()) {
161+ if (requestedNames .contains (entry )) {
162+ result .add (serializedNames . get ( entry ) );
158163 }
159164 }
160165 return result ;
@@ -168,8 +173,9 @@ public static void sendReply(DataOutput output, List<Class<?>> requestedClasses)
168173 }
169174 }
170175 output .writeInt (syncEntries .size ());
176+ val inv = serializedNames .inverse ();
171177 for (val entry : syncEntries .entrySet ()) {
172- output .writeUTF (entry .getKey (). getName ( ));
178+ output .writeUTF (inv . get ( entry .getKey ()));
173179 val b = new ByteArrayOutputStream ();
174180 val bo = new DataOutputStream (b );
175181 entry .getValue ().transmit (bo );
@@ -186,27 +192,26 @@ public static void receiveReply(DataInput input) throws IOException {
186192 }
187193 int count = input .readInt ();
188194 for (int i = 0 ; i < count ; i ++) {
189- String className = input .readUTF ();
195+ String serializedName = input .readUTF ();
190196 int dataSize = input .readInt ();
191- val opt =
192- parsedConfigMap .keySet ().stream ().filter ((clazz ) -> clazz .getName ().equals (className )).findFirst ();
197+ val opt = serializedNames .keySet ().stream ().filter ((key ) -> key .equals (serializedName )).findFirst ();
193198 if (!opt .isPresent ()) {
194199 input .skipBytes (dataSize );
195- FalsePatternLib .getLog ().warn ("Server tried to sync config not registered on our side: " + className );
200+ FalsePatternLib .getLog ().warn ("Server tried to sync config not registered on our side: " + serializedName );
196201 continue ;
197202 }
198- val clazz = opt .get ();
203+ val clazz = serializedNames . get ( opt .get () );
199204 val config = parsedConfigMap .get (clazz );
200205 if (!config .sync ) {
201206 input .skipBytes (dataSize );
202207 FalsePatternLib .getLog ()
203208 .warn ("Server tried to sync config without @Synchronize annotation on our side: " +
204- className );
209+ serializedName );
205210 continue ;
206211 }
207212 if (!ConfigSyncEvent .postStart (clazz )) {
208213 input .skipBytes (dataSize );
209- FalsePatternLib .getLog ().warn ("Config synchronization was cancelled by event for: " + className );
214+ FalsePatternLib .getLog ().warn ("Config synchronization was cancelled by event for: " + serializedName );
210215 continue ;
211216 }
212217 val bytes = new byte [dataSize ];
0 commit comments