Launcher/LaunchServer/src/main/java/pro/gravit/launchserver/manangers/LaunchServerGsonManager.java

55 lines
3.4 KiB
Java
Raw Normal View History

package pro.gravit.launchserver.manangers;
2019-04-20 01:03:06 +03:00
import com.google.gson.GsonBuilder;
2021-11-09 10:12:31 +03:00
import marcono1234.gson.recordadapter.RecordTypeAdapterFactory;
2021-04-14 13:22:07 +03:00
import pro.gravit.launcher.events.request.GetAvailabilityAuthRequestEvent;
import pro.gravit.launcher.managers.GsonManager;
import pro.gravit.launcher.modules.events.PreGsonPhase;
2023-04-20 15:06:12 +03:00
import pro.gravit.launcher.profiles.ClientProfile;
import pro.gravit.launcher.profiles.optional.actions.OptionalAction;
2021-06-18 07:34:32 +03:00
import pro.gravit.launcher.profiles.optional.triggers.OptionalTrigger;
import pro.gravit.launcher.request.JsonResultSerializeAdapter;
import pro.gravit.launcher.request.WebSocketEvent;
import pro.gravit.launcher.request.auth.AuthRequest;
2021-04-14 13:22:07 +03:00
import pro.gravit.launcher.request.auth.GetAvailabilityAuthRequest;
2021-05-16 16:07:44 +03:00
import pro.gravit.launchserver.auth.core.AuthCoreProvider;
import pro.gravit.launchserver.auth.password.PasswordVerifier;
import pro.gravit.launchserver.auth.protect.ProtectHandler;
import pro.gravit.launchserver.auth.texture.TextureProvider;
import pro.gravit.launchserver.components.Component;
import pro.gravit.launchserver.modules.impl.LaunchServerModulesManager;
import pro.gravit.launchserver.socket.WebSocketService;
import pro.gravit.launchserver.socket.response.UnknownResponse;
import pro.gravit.launchserver.socket.response.WebSocketServerResponse;
import pro.gravit.utils.UniversalJsonAdapter;
2019-04-20 01:03:06 +03:00
public class LaunchServerGsonManager extends GsonManager {
private final LaunchServerModulesManager modulesManager;
public LaunchServerGsonManager(LaunchServerModulesManager modulesManager) {
this.modulesManager = modulesManager;
}
2019-04-20 01:03:06 +03:00
@Override
public void registerAdapters(GsonBuilder builder) {
super.registerAdapters(builder);
2022-01-11 22:15:01 +03:00
builder.registerTypeAdapterFactory(RecordTypeAdapterFactory.builder()
2022-11-18 10:47:03 +03:00
.allowMissingComponentValues()
.create());
2023-04-20 15:06:12 +03:00
builder.registerTypeAdapter(ClientProfile.Version.class, new ClientProfile.Version.GsonSerializer());
builder.registerTypeAdapter(TextureProvider.class, new UniversalJsonAdapter<>(TextureProvider.providers));
2021-05-16 16:07:44 +03:00
builder.registerTypeAdapter(AuthCoreProvider.class, new UniversalJsonAdapter<>(AuthCoreProvider.providers));
builder.registerTypeAdapter(PasswordVerifier.class, new UniversalJsonAdapter<>(PasswordVerifier.providers));
builder.registerTypeAdapter(Component.class, new UniversalJsonAdapter<>(Component.providers));
builder.registerTypeAdapter(ProtectHandler.class, new UniversalJsonAdapter<>(ProtectHandler.providers));
builder.registerTypeAdapter(WebSocketServerResponse.class, new UniversalJsonAdapter<>(WebSocketService.providers, UnknownResponse.class));
builder.registerTypeAdapter(WebSocketEvent.class, new JsonResultSerializeAdapter());
builder.registerTypeAdapter(AuthRequest.AuthPasswordInterface.class, new UniversalJsonAdapter<>(AuthRequest.providers));
2021-04-14 13:22:07 +03:00
builder.registerTypeAdapter(GetAvailabilityAuthRequestEvent.AuthAvailabilityDetails.class, new UniversalJsonAdapter<>(GetAvailabilityAuthRequest.providers));
builder.registerTypeAdapter(OptionalAction.class, new UniversalJsonAdapter<>(OptionalAction.providers));
2021-06-18 07:34:32 +03:00
builder.registerTypeAdapter(OptionalTrigger.class, new UniversalJsonAdapter<>(OptionalTrigger.providers));
modulesManager.invokeEvent(new PreGsonPhase(builder));
//ClientWebSocketService.appendTypeAdapters(builder);
2019-04-20 01:03:06 +03:00
}
}