mirror of
https://github.com/GeyserMC/MCProtocolLib.git
synced 2024-11-14 19:34:58 -05:00
ClientboundCommands: SuggestionType is flexible on a protocol level
This commit is contained in:
parent
ed9d799316
commit
67df108f28
7 changed files with 42 additions and 24 deletions
|
@ -9,13 +9,11 @@ import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
|
|||
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.properties.StringProperties;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.object.MinecartType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
||||
|
@ -529,11 +527,6 @@ public class MagicValues {
|
|||
register(CommandParser.TEMPLATE_ROTATION, 46);
|
||||
register(CommandParser.UUID, 47);
|
||||
|
||||
register(SuggestionType.ASK_SERVER, "minecraft:ask_server");
|
||||
register(SuggestionType.ALL_RECIPES, "minecraft:all_recipes");
|
||||
register(SuggestionType.AVAILABLE_SOUNDS, "minecraft:available_sounds");
|
||||
register(SuggestionType.SUMMONABLE_ENTITIES, "minecraft:summonable_entities");
|
||||
|
||||
register(StringProperties.SINGLE_WORD, 0);
|
||||
register(StringProperties.QUOTABLE_PHRASE, 1);
|
||||
register(StringProperties.GREEDY_PHRASE, 2);
|
||||
|
|
|
@ -45,6 +45,7 @@ public class CommandNode {
|
|||
|
||||
/**
|
||||
* Suggestions type, if present.
|
||||
* See {@link SuggestionType} for vanilla defaults.
|
||||
*/
|
||||
private final SuggestionType suggestionType;
|
||||
private final String suggestionType;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,40 @@
|
|||
package com.github.steveice10.mc.protocol.data.game.command;
|
||||
|
||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
public enum SuggestionType {
|
||||
ASK_SERVER,
|
||||
ALL_RECIPES,
|
||||
AVAILABLE_SOUNDS,
|
||||
SUMMONABLE_ENTITIES;
|
||||
|
||||
private final String resourceLocation;
|
||||
|
||||
SuggestionType() {
|
||||
this.resourceLocation = Identifier.formalize(name().toLowerCase(Locale.ROOT));
|
||||
}
|
||||
|
||||
public String getResourceLocation() {
|
||||
return resourceLocation;
|
||||
}
|
||||
|
||||
private static final Map<String, SuggestionType> VALUES = new HashMap<>();
|
||||
|
||||
@NotNull
|
||||
public static SuggestionType byResourceLocation(String resourceLocation) {
|
||||
// Vanilla behavior as of 1.19.3
|
||||
// 1.16.5 still has AVAILABLE_BIOMES and vanilla doesn't care
|
||||
return VALUES.getOrDefault(resourceLocation, ASK_SERVER);
|
||||
}
|
||||
|
||||
static {
|
||||
for (SuggestionType suggestionType : values()) {
|
||||
VALUES.put(suggestionType.resourceLocation, suggestionType);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,11 +3,9 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound;
|
|||
import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper;
|
||||
import com.github.steveice10.mc.protocol.codec.MinecraftPacket;
|
||||
import com.github.steveice10.mc.protocol.data.MagicValues;
|
||||
import com.github.steveice10.mc.protocol.data.game.Identifier;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandNode;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.properties.*;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import lombok.AllArgsConstructor;
|
||||
|
@ -15,8 +13,6 @@ import lombok.Data;
|
|||
import lombok.NonNull;
|
||||
import lombok.With;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@Data
|
||||
@With
|
||||
@AllArgsConstructor
|
||||
|
@ -35,7 +31,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
|
|||
private final @NonNull CommandNode[] nodes;
|
||||
private final int firstNodeIndex;
|
||||
|
||||
public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException {
|
||||
public ClientboundCommandsPacket(ByteBuf in, MinecraftCodecHelper helper) {
|
||||
this.nodes = new CommandNode[helper.readVarInt(in)];
|
||||
for (int i = 0; i < this.nodes.length; i++) {
|
||||
byte flags = in.readByte();
|
||||
|
@ -145,9 +141,9 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
|
|||
}
|
||||
}
|
||||
|
||||
SuggestionType suggestionType = null;
|
||||
String suggestionType = null;
|
||||
if ((flags & FLAG_SUGGESTION_TYPE) != 0) {
|
||||
suggestionType = MagicValues.key(SuggestionType.class, Identifier.formalize(helper.readString(in)));
|
||||
suggestionType = helper.readResourceLocation(in);
|
||||
}
|
||||
|
||||
this.nodes[i] = new CommandNode(type, executable, children, redirectIndex, name, parser, properties, suggestionType);
|
||||
|
@ -157,7 +153,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException {
|
||||
public void serialize(ByteBuf out, MinecraftCodecHelper helper) {
|
||||
helper.writeVarInt(out, this.nodes.length);
|
||||
for (CommandNode node : this.nodes) {
|
||||
int flags = MagicValues.value(Integer.class, node.getType()) & FLAG_TYPE_MASK;
|
||||
|
@ -313,7 +309,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket {
|
|||
}
|
||||
|
||||
if (node.getSuggestionType() != null) {
|
||||
helper.writeString(out, MagicValues.value(String.class, node.getSuggestionType()));
|
||||
helper.writeResourceLocation(out, node.getSuggestionType());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
|||
byte[] keyBytes = helper.readByteArray(in);
|
||||
entry.setKeySignature(helper.readByteArray(in));
|
||||
|
||||
PublicKey publicKey = null;
|
||||
PublicKey publicKey;
|
||||
try {
|
||||
publicKey = KeyFactory.getInstance("RSA").generatePublic(new X509EncodedKeySpec(keyBytes));
|
||||
} catch (GeneralSecurityException e) {
|
||||
|
@ -69,8 +69,7 @@ public class ClientboundPlayerInfoUpdatePacket implements MinecraftPacket {
|
|||
break;
|
||||
}
|
||||
case UPDATE_GAME_MODE: {
|
||||
int rawGameMode = helper.readVarInt(in);
|
||||
GameMode gameMode = GameMode.byId(Math.max(rawGameMode, 0));
|
||||
GameMode gameMode = GameMode.byId(helper.readVarInt(in));
|
||||
|
||||
entry.setGameMode(gameMode);
|
||||
break;
|
||||
|
|
|
@ -9,13 +9,11 @@ import com.github.steveice10.mc.protocol.data.game.UnlockRecipesAction;
|
|||
import com.github.steveice10.mc.protocol.data.game.advancement.Advancement;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandParser;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.CommandType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.SuggestionType;
|
||||
import com.github.steveice10.mc.protocol.data.game.command.properties.StringProperties;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.EquipmentSlot;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.RotationOrigin;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.object.MinecartType;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.Hand;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.HandPreference;
|
||||
import com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction;
|
||||
|
@ -152,7 +150,6 @@ public class MagicValuesTest {
|
|||
this.register(RecipeType.class, String.class);
|
||||
this.register(CommandType.class, Integer.class);
|
||||
this.register(CommandParser.class, Integer.class);
|
||||
this.register(SuggestionType.class, String.class);
|
||||
this.register(StringProperties.class, Integer.class);
|
||||
this.register(PositionSourceType.class, String.class);
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ public class ClientboundCommandsPacketTest extends PacketTest {
|
|||
"Argument4",
|
||||
CommandParser.STRING,
|
||||
StringProperties.SINGLE_WORD,
|
||||
SuggestionType.ALL_RECIPES
|
||||
SuggestionType.ALL_RECIPES.getResourceLocation()
|
||||
)
|
||||
},
|
||||
0
|
||||
|
|
Loading…
Reference in a new issue