mirror of
https://github.com/ViaVersion/VIAaaS.git
synced 2024-11-24 12:25:39 +01:00
Delete not needed type classes and use existing Types
Closes https://github.com/ViaVersion/VIAaaS/issues/238
This commit is contained in:
parent
64ddaf46ae
commit
8bfebc0ce1
@ -1,11 +0,0 @@
|
||||
package com.viaversion.aas.type;
|
||||
|
||||
import com.viaversion.aas.util.SignableProperty;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.ArrayType;
|
||||
|
||||
public enum AspirinTypes {;
|
||||
public static Type<String> OPTIONAL_STRING = new OptionalStringType();
|
||||
public static Type<SignableProperty> SIGNABLE_PROPERTY = new SignablePropertyType();
|
||||
public static Type<SignableProperty[]> SIGNABLE_PROPERTY_ARRAY = new ArrayType<>(SIGNABLE_PROPERTY);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package com.viaversion.aas.type;
|
||||
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class OptionalStringType extends Type<String> {
|
||||
protected OptionalStringType() {
|
||||
super(String.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(ByteBuf buffer) throws Exception {
|
||||
return buffer.readBoolean() ? Type.STRING.read(buffer) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, String object) throws Exception {
|
||||
if (object == null) {
|
||||
buffer.writeBoolean(false);
|
||||
} else {
|
||||
buffer.writeBoolean(true);
|
||||
Type.STRING.write(buffer, object);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
package com.viaversion.aas.type;
|
||||
|
||||
import com.viaversion.aas.util.SignableProperty;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public class SignablePropertyType extends Type<SignableProperty> {
|
||||
protected SignablePropertyType() {
|
||||
super(SignableProperty.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public SignableProperty read(ByteBuf buffer) throws Exception {
|
||||
String key = Type.STRING.read(buffer);
|
||||
String value = Type.STRING.read(buffer);
|
||||
String signature = AspirinTypes.OPTIONAL_STRING.read(buffer);
|
||||
return new SignableProperty(key, value, signature);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(ByteBuf buffer, SignableProperty object) throws Exception {
|
||||
Type.STRING.write(buffer, object.getKey());
|
||||
Type.STRING.write(buffer, object.getValue());
|
||||
AspirinTypes.OPTIONAL_STRING.write(buffer, object.getSignature());
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@ package com.viaversion.aas.codec.packet.login
|
||||
import com.viaversion.aas.codec.packet.Packet
|
||||
import com.viaversion.aas.parseUndashedId
|
||||
import com.viaversion.aas.protocol.sharewareVersion
|
||||
import com.viaversion.aas.type.AspirinTypes
|
||||
import com.viaversion.aas.util.SignableProperty
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion
|
||||
import com.viaversion.viaversion.api.type.Type
|
||||
@ -27,7 +26,13 @@ class LoginSuccess : Packet {
|
||||
}
|
||||
username = Type.STRING.read(byteBuf)
|
||||
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)) {
|
||||
properties.addAll(AspirinTypes.SIGNABLE_PROPERTY_ARRAY.read(byteBuf).asList())
|
||||
val properties = Type.VAR_INT.readPrimitive(byteBuf)
|
||||
for (i in 0 until properties) {
|
||||
val name = Type.STRING.read(byteBuf)
|
||||
val value = Type.STRING.read(byteBuf)
|
||||
val signature = Type.OPTIONAL_STRING.read(byteBuf)
|
||||
this.properties.add(SignableProperty(name, value, signature))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -43,7 +48,12 @@ class LoginSuccess : Packet {
|
||||
}
|
||||
Type.STRING.write(byteBuf, username)
|
||||
if (protocolVersion.newerThanOrEqualTo(ProtocolVersion.v1_19)) {
|
||||
AspirinTypes.SIGNABLE_PROPERTY_ARRAY.write(byteBuf, properties.toTypedArray())
|
||||
Type.VAR_INT.writePrimitive(byteBuf, properties.size)
|
||||
for (property in properties) {
|
||||
Type.STRING.write(byteBuf, property.key)
|
||||
Type.STRING.write(byteBuf, property.value)
|
||||
Type.OPTIONAL_STRING.write(byteBuf, property.signature)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user