diff --git a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java index 5672b10b3..a6b756a6a 100644 --- a/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java +++ b/api/src/main/java/com/velocitypowered/api/network/ProtocolVersion.java @@ -56,7 +56,8 @@ public enum ProtocolVersion { MINECRAFT_1_16_4(754, "1.16.4", "1.16.5"), MINECRAFT_1_17(755, "1.17"), MINECRAFT_1_17_1(756, "1.17.1"), - MINECRAFT_1_18(757, "1.18", "1.18.1"); + MINECRAFT_1_18(757, "1.18", "1.18.1"), + MINECRAFT_1_18_2(758, "1.18.2"); private static final int SNAPSHOT_BIT = 30; diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java index 8f0b035a0..1f5aa3678 100644 --- a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/ArgumentPropertyRegistry.java @@ -130,6 +130,8 @@ public class ArgumentPropertyRegistry { } }); register("brigadier:long", LongArgumentType.class, LONG); + register("minecraft:resource", RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY); + register("minecraft:resource_or_tag", RegistryKeyArgument.class, RegistryKeyArgumentSerializer.REGISTRY); // Crossstitch support register("crossstitch:mod_argument", ModArgumentProperty.class, MOD); diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgument.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgument.java new file mode 100644 index 000000000..6c6c9f209 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgument.java @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +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 java.util.Arrays; +import java.util.Collection; +import java.util.List; +import java.util.concurrent.CompletableFuture; + +public class RegistryKeyArgument implements ArgumentType { + private static final List EXAMPLES = Arrays.asList("foo", "foo:bar", "012"); + private String identifier; + + public RegistryKeyArgument(String identifier) { + this.identifier = identifier; + } + + public String getIdentifier() { + return identifier; + } + + @Override + public String parse(StringReader stringReader) throws CommandSyntaxException { + return stringReader.readString(); + } + + @Override + public CompletableFuture listSuggestions(CommandContext context, SuggestionsBuilder builder) { + return Suggestions.empty(); + } + + @Override + public Collection getExamples() { + return EXAMPLES; + } +} diff --git a/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgumentSerializer.java b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgumentSerializer.java new file mode 100644 index 000000000..e8ea99215 --- /dev/null +++ b/proxy/src/main/java/com/velocitypowered/proxy/protocol/packet/brigadier/RegistryKeyArgumentSerializer.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2018 Velocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package com.velocitypowered.proxy.protocol.packet.brigadier; + +import com.velocitypowered.proxy.protocol.ProtocolUtils; + +import io.netty.buffer.ByteBuf; + +public class RegistryKeyArgumentSerializer implements ArgumentPropertySerializer { + static final RegistryKeyArgumentSerializer REGISTRY = new RegistryKeyArgumentSerializer(); + + @Override + public RegistryKeyArgument deserialize(ByteBuf buf) { + return new RegistryKeyArgument(ProtocolUtils.readString(buf)); + } + + @Override + public void serialize(RegistryKeyArgument object, ByteBuf buf) { + ProtocolUtils.writeString(buf, object.getIdentifier()); + } +}