13
0
geforkt von Mirrors/Velocity

Implement brigadier:long argument type, fixes #295

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-04-23 16:19:49 -04:00
Ursprung 20eb14143d
Commit 1441dec367
5 geänderte Dateien mit 50 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -63,6 +63,7 @@ artifacts {
javadoc {
options.encoding = 'UTF-8'
options.charSet = 'UTF-8'
options.source = '8'
options.links(
'http://www.slf4j.org/apidocs/',
'https://google.github.io/guava/releases/25.1-jre/api/docs/',

Datei anzeigen

@ -65,7 +65,7 @@ dependencies {
compile 'it.unimi.dsi:fastutil:8.2.3'
compile 'net.kyori:event-method-asm:3.0.0'
compile 'com.mojang:brigadier:1.0.15'
compile 'com.mojang:brigadier:1.0.17'
compile 'org.asynchttpclient:async-http-client:2.10.4'

Datei anzeigen

@ -4,6 +4,7 @@ import static com.velocitypowered.proxy.protocol.packet.brigadier.DoubleArgument
import static com.velocitypowered.proxy.protocol.packet.brigadier.DummyVoidArgumentPropertySerializer.DUMMY;
import static com.velocitypowered.proxy.protocol.packet.brigadier.FloatArgumentPropertySerializer.FLOAT;
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.INTEGER;
import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG;
import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING;
import com.mojang.brigadier.arguments.ArgumentType;
@ -11,6 +12,7 @@ import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.DoubleArgumentType;
import com.mojang.brigadier.arguments.FloatArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.LongArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
@ -90,6 +92,7 @@ public class ArgumentPropertyRegistry {
register("brigadier:double", DoubleArgumentType.class, DOUBLE);
register("brigadier:bool", BoolArgumentType.class,
VoidArgumentPropertySerializer.create(BoolArgumentType::bool));
register("brigadier:long", LongArgumentType.class, LONG);
// Minecraft argument types with extra properties
dummy("minecraft:entity", ByteArgumentPropertySerializer.BYTE);

Datei anzeigen

@ -17,11 +17,6 @@ class DummyProperty<T> implements ArgumentType<T> {
this.result = result;
}
@Override
public <S> T parse(StringReader reader) throws CommandSyntaxException {
throw new UnsupportedOperationException();
}
public String getIdentifier() {
return identifier;
}
@ -33,4 +28,9 @@ class DummyProperty<T> implements ArgumentType<T> {
public @Nullable T getResult() {
return result;
}
@Override
public T parse(StringReader reader) {
throw new UnsupportedOperationException();
}
}

Datei anzeigen

@ -0,0 +1,40 @@
package com.velocitypowered.proxy.protocol.packet.brigadier;
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MAXIMUM;
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.HAS_MINIMUM;
import static com.velocitypowered.proxy.protocol.packet.brigadier.IntegerArgumentPropertySerializer.getFlags;
import com.mojang.brigadier.arguments.LongArgumentType;
import io.netty.buffer.ByteBuf;
class LongArgumentPropertySerializer implements ArgumentPropertySerializer<LongArgumentType> {
static final LongArgumentPropertySerializer LONG = new LongArgumentPropertySerializer();
private LongArgumentPropertySerializer() {
}
@Override
public LongArgumentType deserialize(ByteBuf buf) {
byte flags = buf.readByte();
long minimum = (flags & HAS_MINIMUM) != 0 ? buf.readLong() : Long.MIN_VALUE;
long maximum = (flags & HAS_MAXIMUM) != 0 ? buf.readLong() : Long.MAX_VALUE;
return LongArgumentType.longArg(minimum, maximum);
}
@Override
public void serialize(LongArgumentType object, ByteBuf buf) {
boolean hasMinimum = object.getMinimum() != Long.MIN_VALUE;
boolean hasMaximum = object.getMaximum() != Long.MAX_VALUE;
byte flag = getFlags(hasMinimum, hasMaximum);
buf.writeByte(flag);
if (hasMinimum) {
buf.writeLong(object.getMinimum());
}
if (hasMaximum) {
buf.writeLong(object.getMaximum());
}
}
}