Delete not needed type classes and use existing Types

Closes https://github.com/ViaVersion/VIAaaS/issues/238
This commit is contained in:
FlorianMichael 2024-03-05 16:46:31 +01:00
parent 64ddaf46ae
commit 8bfebc0ce1
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
4 changed files with 13 additions and 65 deletions

View File

@ -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);
}

View File

@ -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);
}
}
}

View File

@ -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());
}
}

View File

@ -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)
}
}
}
}