geforkt von Mirrors/Velocity
Support custom mod argument tunneling (#390)
Dieser Commit ist enthalten in:
Ursprung
511165415d
Commit
7ead4add67
@ -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.IntegerArgumentPropertySerializer.INTEGER;
|
||||
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 com.mojang.brigadier.arguments.ArgumentType;
|
||||
@ -76,6 +77,10 @@ public class ArgumentPropertyRegistry {
|
||||
if (property.getResult() != null) {
|
||||
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 {
|
||||
ArgumentPropertySerializer serializer = byClass.get(type.getClass());
|
||||
String id = classToId.get(type.getClass());
|
||||
@ -98,6 +103,9 @@ public class ArgumentPropertyRegistry {
|
||||
GenericArgumentPropertySerializer.create(BoolArgumentType::bool));
|
||||
register("brigadier:long", LongArgumentType.class, LONG);
|
||||
|
||||
// Crossstitch support
|
||||
register("crossstitch:mod_argument", ModArgumentProperty.class, MOD);
|
||||
|
||||
// Minecraft argument types with extra properties
|
||||
empty("minecraft:entity", ByteArgumentPropertySerializer.BYTE);
|
||||
empty("minecraft:score_holder", ByteArgumentPropertySerializer.BYTE);
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren