Declarimg some commands to support proxy tab complete

This commit is contained in:
Nanit 2020-12-04 21:17:47 +02:00
parent e49bed47e6
commit e1ebf4f609
4 changed files with 61 additions and 1 deletions

View File

@ -4,7 +4,7 @@ plugins {
} }
group 'ru.nanit' group 'ru.nanit'
version '1.2' version '1.2.1'
repositories { repositories {
mavenCentral() mavenCentral()

View File

@ -28,6 +28,7 @@ import java.net.InetSocketAddress;
import java.net.SocketAddress; import java.net.SocketAddress;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.MessageDigest; import java.security.MessageDigest;
import java.util.Collections;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom; import java.util.concurrent.ThreadLocalRandom;
@ -37,6 +38,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
private static PreRenderedPacket PACKET_JOIN_GAME; private static PreRenderedPacket PACKET_JOIN_GAME;
private static PreRenderedPacket PACKET_PLAYER_ABILITIES; private static PreRenderedPacket PACKET_PLAYER_ABILITIES;
private static PreRenderedPacket PACKET_PLAYER_INFO; private static PreRenderedPacket PACKET_PLAYER_INFO;
private static PreRenderedPacket PACKET_DECLARE_COMMANDS;
private static PreRenderedPacket PACKET_PLAYER_POS; private static PreRenderedPacket PACKET_PLAYER_POS;
private static PreRenderedPacket PACKET_JOIN_MESSAGE; private static PreRenderedPacket PACKET_JOIN_MESSAGE;
private static PreRenderedPacket PACKET_BOSS_BAR; private static PreRenderedPacket PACKET_BOSS_BAR;
@ -191,6 +193,7 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
writePacket(PACKET_PLAYER_ABILITIES); writePacket(PACKET_PLAYER_ABILITIES);
writePacket(PACKET_PLAYER_POS); writePacket(PACKET_PLAYER_POS);
writePacket(PACKET_PLAYER_INFO); writePacket(PACKET_PLAYER_INFO);
writePacket(PACKET_DECLARE_COMMANDS);
if (PACKET_BOSS_BAR != null) if (PACKET_BOSS_BAR != null)
writePacket(PACKET_BOSS_BAR); writePacket(PACKET_BOSS_BAR);
@ -312,11 +315,15 @@ public class ClientConnection extends ChannelInboundHandlerAdapter {
info.setGameMode(server.getConfig().getGameMode()); info.setGameMode(server.getConfig().getGameMode());
info.setUuid(uuid); info.setUuid(uuid);
PacketDeclareCommands declareCommands = new PacketDeclareCommands();
declareCommands.setCommands(Collections.singletonList("limbo"));
PACKET_LOGIN_SUCCESS = PreRenderedPacket.of(loginSuccess); PACKET_LOGIN_SUCCESS = PreRenderedPacket.of(loginSuccess);
PACKET_JOIN_GAME = PreRenderedPacket.of(joinGame); PACKET_JOIN_GAME = PreRenderedPacket.of(joinGame);
PACKET_PLAYER_ABILITIES = PreRenderedPacket.of(playerAbilities); PACKET_PLAYER_ABILITIES = PreRenderedPacket.of(playerAbilities);
PACKET_PLAYER_POS = PreRenderedPacket.of(positionAndLook); PACKET_PLAYER_POS = PreRenderedPacket.of(positionAndLook);
PACKET_PLAYER_INFO = PreRenderedPacket.of(info); PACKET_PLAYER_INFO = PreRenderedPacket.of(info);
PACKET_DECLARE_COMMANDS = PreRenderedPacket.of(declareCommands);
if (server.getConfig().isUseJoinMessage()){ if (server.getConfig().isUseJoinMessage()){
PacketChatMessage joinMessage = new PacketChatMessage(); PacketChatMessage joinMessage = new PacketChatMessage();

View File

@ -0,0 +1,52 @@
package ru.nanit.limbo.protocol.packets.play;
import ru.nanit.limbo.protocol.ByteMessage;
import ru.nanit.limbo.protocol.PacketOut;
import java.util.List;
public class PacketDeclareCommands implements PacketOut {
private List<String> commands;
public void setCommands(List<String> commands) {
this.commands = commands;
}
@Override
public void encode(ByteMessage msg) {
msg.writeVarInt(commands.size() * 2 + 1); // +1 because declaring root node
// Declare root node
msg.writeByte(0);
msg.writeVarInt(commands.size());
for (int i = 1; i <= commands.size() * 2; i++){
msg.writeVarInt(i++);
}
// Declare other commands
int i = 1;
for (String cmd : commands){
msg.writeByte(1 | 0x04);
msg.writeVarInt(1);
msg.writeVarInt(i + 1);
msg.writeString(cmd);
i++;
msg.writeByte(2 | 0x04 | 0x10);
msg.writeVarInt(1);
msg.writeVarInt(i);
msg.writeString("arg");
msg.writeString("brigadier:string");
msg.writeVarInt(0);
msg.writeString("minecraft:ask_server");
i++;
}
msg.writeVarInt(0);
}
}

View File

@ -39,6 +39,7 @@ public enum State {
PLAY(3){ PLAY(3){
{ {
serverBound.register(0x10, PacketKeepAlive::new); serverBound.register(0x10, PacketKeepAlive::new);
clientBound.register(0x10, PacketDeclareCommands::new);
clientBound.register(0x24, PacketJoinGame::new); clientBound.register(0x24, PacketJoinGame::new);
clientBound.register(0x30, PacketPlayerAbilities::new); clientBound.register(0x30, PacketPlayerAbilities::new);
clientBound.register(0x34, PacketPlayerPositionAndLook::new); clientBound.register(0x34, PacketPlayerPositionAndLook::new);