3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-12-26 00:00:55 +01:00

Support custom mod argument tunneling (#390)

Dieser Commit ist enthalten in:
Andrew Steinborn 2020-11-16 02:58:00 -05:00 committet von GitHub
Ursprung 511165415d
Commit 7ead4add67
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
3 geänderte Dateien mit 82 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -5,6 +5,7 @@ import static com.velocitypowered.proxy.protocol.packet.brigadier.EmptyArgumentP
import static com.velocitypowered.proxy.protocol.packet.brigadier.FloatArgumentPropertySerializer.FLOAT; 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.IntegerArgumentPropertySerializer.INTEGER;
import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG; import static com.velocitypowered.proxy.protocol.packet.brigadier.LongArgumentPropertySerializer.LONG;
import static com.velocitypowered.proxy.protocol.packet.brigadier.ModArgumentPropertySerializer.MOD;
import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING; import static com.velocitypowered.proxy.protocol.packet.brigadier.StringArgumentPropertySerializer.STRING;
import com.mojang.brigadier.arguments.ArgumentType; import com.mojang.brigadier.arguments.ArgumentType;
@ -76,6 +77,10 @@ public class ArgumentPropertyRegistry {
if (property.getResult() != null) { if (property.getResult() != null) {
property.getSerializer().serialize(property.getResult(), buf); property.getSerializer().serialize(property.getResult(), buf);
} }
} else if (type instanceof ModArgumentProperty) {
ModArgumentProperty property = (ModArgumentProperty) type;
ProtocolUtils.writeString(buf, property.getIdentifier());
buf.writeBytes(property.getData());
} else { } else {
ArgumentPropertySerializer serializer = byClass.get(type.getClass()); ArgumentPropertySerializer serializer = byClass.get(type.getClass());
String id = classToId.get(type.getClass()); String id = classToId.get(type.getClass());
@ -98,6 +103,9 @@ public class ArgumentPropertyRegistry {
GenericArgumentPropertySerializer.create(BoolArgumentType::bool)); GenericArgumentPropertySerializer.create(BoolArgumentType::bool));
register("brigadier:long", LongArgumentType.class, LONG); register("brigadier:long", LongArgumentType.class, LONG);
// Crossstitch support
register("crossstitch:mod_argument", ModArgumentProperty.class, MOD);
// Minecraft argument types with extra properties // Minecraft argument types with extra properties
empty("minecraft:entity", ByteArgumentPropertySerializer.BYTE); empty("minecraft:entity", ByteArgumentPropertySerializer.BYTE);
empty("minecraft:score_holder", ByteArgumentPropertySerializer.BYTE); empty("minecraft:score_holder", ByteArgumentPropertySerializer.BYTE);

Datei anzeigen

@ -0,0 +1,47 @@
package com.velocitypowered.proxy.protocol.packet.brigadier;
import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.context.CommandContext;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.suggestion.Suggestions;
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import java.util.Collection;
import java.util.concurrent.CompletableFuture;
public class ModArgumentProperty implements ArgumentType<ByteBuf> {
private final String identifier;
private final ByteBuf data;
public ModArgumentProperty(String identifier, ByteBuf data) {
this.identifier = identifier;
this.data = Unpooled.unreleasableBuffer(data.asReadOnly());
}
public String getIdentifier() {
return identifier;
}
public ByteBuf getData() {
return data.slice();
}
@Override
public ByteBuf parse(StringReader reader) throws CommandSyntaxException {
throw new UnsupportedOperationException();
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context,
SuggestionsBuilder builder) {
throw new UnsupportedOperationException();
}
@Override
public Collection<String> getExamples() {
throw new UnsupportedOperationException();
}
}

Datei anzeigen

@ -0,0 +1,27 @@
package com.velocitypowered.proxy.protocol.packet.brigadier;
import com.velocitypowered.proxy.protocol.ProtocolUtils;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import org.checkerframework.checker.nullness.qual.Nullable;
class ModArgumentPropertySerializer implements ArgumentPropertySerializer<ModArgumentProperty> {
static final ModArgumentPropertySerializer MOD = new ModArgumentPropertySerializer();
private ModArgumentPropertySerializer() {
}
@Override
public @Nullable ModArgumentProperty deserialize(ByteBuf buf) {
String identifier = ProtocolUtils.readString(buf);
byte[] extraData = ProtocolUtils.readByteArray(buf);
return new ModArgumentProperty(identifier, Unpooled.wrappedBuffer(extraData));
}
@Override
public void serialize(ModArgumentProperty object, ByteBuf buf) {
// This is special-cased by ArgumentPropertyRegistry
throw new UnsupportedOperationException();
}
}