3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-16 21:10:30 +01:00

Share instances of the custom Gson type serializers

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-09-03 16:04:21 -04:00
Ursprung 5d287306c2
Commit 1dd900194d
3 geänderte Dateien mit 15 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -91,20 +91,20 @@ public class VelocityServer implements ProxyServer, ForwardingAudience {
private static final Logger logger = LogManager.getLogger(VelocityServer.class);
public static final Gson GENERAL_GSON = new GsonBuilder()
.registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer())
.registerTypeHierarchyAdapter(GameProfile.class, new GameProfileSerializer())
.registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE)
.registerTypeHierarchyAdapter(GameProfile.class, GameProfileSerializer.INSTANCE)
.create();
private static final Gson PRE_1_16_PING_SERIALIZER = ProtocolUtils
.getJsonChatSerializer(ProtocolVersion.MINECRAFT_1_15_2)
.serializer()
.newBuilder()
.registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer())
.registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE)
.create();
private static final Gson POST_1_16_PING_SERIALIZER = ProtocolUtils
.getJsonChatSerializer(ProtocolVersion.MINECRAFT_1_16)
.serializer()
.newBuilder()
.registerTypeHierarchyAdapter(Favicon.class, new FaviconSerializer())
.registerTypeHierarchyAdapter(Favicon.class, FaviconSerializer.INSTANCE)
.create();
private final ConnectionManager cm;

Datei anzeigen

@ -11,6 +11,12 @@ import java.lang.reflect.Type;
public final class FaviconSerializer implements JsonSerializer<Favicon>, JsonDeserializer<Favicon> {
public static final FaviconSerializer INSTANCE = new FaviconSerializer();
private FaviconSerializer() {
}
@Override
public Favicon deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) {
return new Favicon(json.getAsString());

Datei anzeigen

@ -16,8 +16,13 @@ import java.util.List;
public final class GameProfileSerializer implements JsonSerializer<GameProfile>,
JsonDeserializer<GameProfile> {
public static final GameProfileSerializer INSTANCE = new GameProfileSerializer();
private static final Type propertyList = new TypeToken<List<Property>>() {}.getType();
private GameProfileSerializer() {
}
@Override
public GameProfile deserialize(JsonElement json, Type typeOfT,
JsonDeserializationContext context) {