35
35
import com .falsepattern .lib .toasts .SimpleToast ;
36
36
import com .falsepattern .lib .toasts .icon .ToastBG ;
37
37
import com .falsepattern .lib .util .FileUtil ;
38
+ import com .google .common .collect .BiMap ;
39
+ import com .google .common .collect .HashBiMap ;
38
40
import lombok .AccessLevel ;
39
41
import lombok .NoArgsConstructor ;
40
42
import lombok .SneakyThrows ;
@@ -81,6 +83,7 @@ public class ConfigurationManagerImpl {
81
83
private static final Map <String , Configuration > configs = new HashMap <>();
82
84
private static final Map <Configuration , Set <Class <?>>> configToClassMap = new HashMap <>();
83
85
private static final Map <Class <?>, ParsedConfiguration > parsedConfigMap = new HashMap <>();
86
+ private static final BiMap <String , Class <?>> serializedNames = HashBiMap .create ();
84
87
private static final ConfigurationManagerImpl instance = new ConfigurationManagerImpl ();
85
88
private static boolean initialized = false ;
86
89
private static Path configDir ;
@@ -91,6 +94,7 @@ public static void register(Class<?> configClass) throws ConfigException {
91
94
val parsedConfig = ParsedConfiguration .parseConfig (configClass );
92
95
configToClassMap .computeIfAbsent (parsedConfig .rawConfig , (ignored ) -> new HashSet <>()).add (configClass );
93
96
parsedConfigMap .put (configClass , ParsedConfiguration .parseConfig (configClass ));
97
+ serializedNames .put (parsedConfig .modid + "$" + parsedConfig .category , configClass );
94
98
}
95
99
}
96
100
@@ -134,27 +138,28 @@ public static void registerLoadSaveConfig(Class<?> configClass) throws ConfigExc
134
138
135
139
public static void sendRequest (DataOutput output ) throws IOException {
136
140
val synced = new ArrayList <Class <?>>();
141
+ val inv = serializedNames .inverse ();
137
142
for (val entry : parsedConfigMap .entrySet ()) {
138
143
if (entry .getValue ().sync ) {
139
144
synced .add (entry .getKey ());
140
145
}
141
146
}
142
147
output .writeInt (synced .size ());
143
148
for (val clazz : synced ) {
144
- output .writeUTF (clazz . getName ( ));
149
+ output .writeUTF (inv . get ( clazz ));
145
150
}
146
151
}
147
152
148
153
public static List <Class <?>> receiveRequest (DataInput input ) throws IOException {
149
154
val result = new ArrayList <Class <?>>();
150
155
val count = input .readInt ();
151
- val classNames = new HashSet <String >();
156
+ val requestedNames = new HashSet <String >();
152
157
for (int i = 0 ; i < count ; i ++) {
153
- classNames .add (input .readUTF ());
158
+ requestedNames .add (input .readUTF ());
154
159
}
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 ) );
158
163
}
159
164
}
160
165
return result ;
@@ -168,8 +173,9 @@ public static void sendReply(DataOutput output, List<Class<?>> requestedClasses)
168
173
}
169
174
}
170
175
output .writeInt (syncEntries .size ());
176
+ val inv = serializedNames .inverse ();
171
177
for (val entry : syncEntries .entrySet ()) {
172
- output .writeUTF (entry .getKey (). getName ( ));
178
+ output .writeUTF (inv . get ( entry .getKey ()));
173
179
val b = new ByteArrayOutputStream ();
174
180
val bo = new DataOutputStream (b );
175
181
entry .getValue ().transmit (bo );
@@ -186,27 +192,26 @@ public static void receiveReply(DataInput input) throws IOException {
186
192
}
187
193
int count = input .readInt ();
188
194
for (int i = 0 ; i < count ; i ++) {
189
- String className = input .readUTF ();
195
+ String serializedName = input .readUTF ();
190
196
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 ();
193
198
if (!opt .isPresent ()) {
194
199
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 );
196
201
continue ;
197
202
}
198
- val clazz = opt .get ();
203
+ val clazz = serializedNames . get ( opt .get () );
199
204
val config = parsedConfigMap .get (clazz );
200
205
if (!config .sync ) {
201
206
input .skipBytes (dataSize );
202
207
FalsePatternLib .getLog ()
203
208
.warn ("Server tried to sync config without @Synchronize annotation on our side: " +
204
- className );
209
+ serializedName );
205
210
continue ;
206
211
}
207
212
if (!ConfigSyncEvent .postStart (clazz )) {
208
213
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 );
210
215
continue ;
211
216
}
212
217
val bytes = new byte [dataSize ];
0 commit comments