mirror of
https://github.com/GravitLauncher/Launcher
synced 2024-12-23 00:51:01 +03:00
[FEATURE] Использование type вместо requesttype
This commit is contained in:
parent
8726988291
commit
dd4f97313e
10 changed files with 24 additions and 9 deletions
|
@ -9,6 +9,8 @@
|
|||
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
|
||||
import ru.gravit.launcher.hasher.HashedEntry;
|
||||
import ru.gravit.launcher.hasher.HashedEntryAdapter;
|
||||
import ru.gravit.launcher.request.JsonResultSerializeAdapter;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
import ru.gravit.launchserver.LaunchServer;
|
||||
import ru.gravit.launchserver.socket.Client;
|
||||
import ru.gravit.launchserver.socket.websocket.json.EchoResponse;
|
||||
|
@ -33,6 +35,7 @@ public WebSocketService(ChannelGroup channels, LaunchServer server, GsonBuilder
|
|||
this.server = server;
|
||||
this.gsonBuiler = gson;
|
||||
this.gsonBuiler.registerTypeAdapter(JsonResponseInterface.class, new JsonResponseAdapter(this));
|
||||
this.gsonBuiler.registerTypeAdapter(ResultInterface.class,new JsonResultSerializeAdapter());
|
||||
this.gsonBuiler.registerTypeAdapter(HashedEntry.class, new HashedEntryAdapter());
|
||||
this.gson = gsonBuiler.create();
|
||||
}
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
public class BatchProfileByUsernameRequestEvent implements EventInterface, ResultInterface
|
||||
{
|
||||
private static final UUID uuid = UUID.fromString("c1d6729e-be2c-48cc-b5ae-af8c012232c3");
|
||||
public String requesttype = "batchProfileByUsername";
|
||||
public String error;
|
||||
public PlayerProfile[] playerProfiles;
|
||||
@Override
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
public class CheckServerEvent implements EventInterface, ResultInterface {
|
||||
private static final UUID _uuid = UUID.fromString("8801d07c-51ba-4059-b61d-fe1f1510b28a");
|
||||
public String type = "success";
|
||||
public String requesttype = "checkServer";
|
||||
public UUID uuid;
|
||||
public PlayerProfile playerProfile;
|
||||
@Override
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
public class JoinServerRequestEvent implements EventInterface, ResultInterface {
|
||||
private static final UUID uuid = UUID.fromString("2a12e7b5-3f4a-4891-a2f9-ea141c8e1995");
|
||||
public String type = "success";
|
||||
public String requesttype = "joinServer";
|
||||
|
||||
public JoinServerRequestEvent(boolean allow) {
|
||||
this.allow = allow;
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
public class LauncherRequestEvent implements EventInterface, ResultInterface {
|
||||
private static final UUID uuid = UUID.fromString("d54cc12a-4f59-4f23-9b10-f527fdd2e38f");
|
||||
public String type = "success";
|
||||
public String requesttype = "launcher";
|
||||
public String url;
|
||||
|
||||
public LauncherRequestEvent(boolean needUpdate, String url) {
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
public class ProfileByUUIDRequestEvent implements EventInterface, ResultInterface
|
||||
{
|
||||
private static final UUID uuid = UUID.fromString("b9014cf3-4b95-4d38-8c5f-867f190a18a0");
|
||||
String requesttype = "profileByUUID";
|
||||
String error;
|
||||
PlayerProfile playerProfile;
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@
|
|||
public class ProfileByUsernameRequestEvent implements EventInterface, ResultInterface
|
||||
{
|
||||
private static final UUID uuid = UUID.fromString("06204302-ff6b-4779-b97d-541e3bc39aa1");
|
||||
String requesttype = "profileByUsername";
|
||||
String error;
|
||||
PlayerProfile playerProfile;
|
||||
|
||||
|
|
|
@ -16,7 +16,6 @@ public ProfilesRequestEvent(List<ClientProfile> profiles) {
|
|||
this.profiles = profiles;
|
||||
}
|
||||
|
||||
String requesttype = "profiles";
|
||||
String error;
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
|
|
|
@ -9,13 +9,11 @@
|
|||
public class UpdateListRequestEvent implements EventInterface, ResultInterface {
|
||||
private static final UUID uuid = UUID.fromString("5fa836ae-6b61-401c-96ac-d8396f07ec6b");
|
||||
public final String type;
|
||||
public final String requesttype;
|
||||
public final HashedDir dir;
|
||||
|
||||
public UpdateListRequestEvent(HashedDir dir) {
|
||||
this.dir = dir;
|
||||
type = "success";
|
||||
requesttype = "updateList";
|
||||
}
|
||||
@Override
|
||||
public UUID getUUID() {
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
package ru.gravit.launcher.request;
|
||||
|
||||
import com.google.gson.*;
|
||||
import ru.gravit.launcher.request.ResultInterface;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonResultSerializeAdapter implements JsonSerializer<ResultInterface> {
|
||||
private static final String PROP_NAME = "type";
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(ResultInterface src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
// note : won't work, you must delegate this
|
||||
JsonObject jo = context.serialize(src).getAsJsonObject();
|
||||
|
||||
String classPath = src.getType();
|
||||
jo.add(PROP_NAME, new JsonPrimitive(classPath));
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue