length fix hack

This commit is contained in:
Chipmunk 2023-04-30 21:10:14 -04:00
parent eeea72ccfd
commit 5552542461

View file

@ -5,17 +5,23 @@ import land.chipmunk.chipmunkbot.data.chat.PlayerMessage;
import land.chipmunk.chipmunkbot.data.chat.SystemChatParser; import land.chipmunk.chipmunkbot.data.chat.SystemChatParser;
import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry; import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkbot.util.UUIDUtilities; import land.chipmunk.chipmunkbot.util.UUIDUtilities;
import land.chipmunk.chipmunkbot.util.ComponentUtilities; // sus
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundSystemChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisguisedChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundDisguisedChatPacket;
import com.github.steveice10.mc.protocol.packet.login.clientbound.ClientboundGameProfilePacket; // TODO: Move uuid detection elsewhere
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSetCreativeModeSlotPacket;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.event.session.SessionListener; import com.github.steveice10.packetlib.event.session.SessionListener;
import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.mc.protocol.MinecraftProtocol;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.event.HoverEvent; import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import lombok.Getter; import lombok.Getter;
@ -25,12 +31,14 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.time.Instant; import java.time.Instant;
import java.nio.charset.StandardCharsets;
import land.chipmunk.chipmunkbot.systemChat.*; import land.chipmunk.chipmunkbot.systemChat.*;
public class ChatPlugin extends SessionAdapter { public class ChatPlugin extends SessionAdapter {
private final ChipmunkBot client; private final ChipmunkBot client;
@Getter private List<Listener> listeners = new ArrayList<>(); @Getter private List<Listener> listeners = new ArrayList<>();
private UUID uuid; // TODO: Move uuid detection elsewhere
private List<SystemChatParser> systemChatParsers; private List<SystemChatParser> systemChatParsers;
@ -58,6 +66,7 @@ public class ChatPlugin extends SessionAdapter {
if (packet instanceof ClientboundSystemChatPacket) packetReceived(session, (ClientboundSystemChatPacket) packet); if (packet instanceof ClientboundSystemChatPacket) packetReceived(session, (ClientboundSystemChatPacket) packet);
else if (packet instanceof ClientboundPlayerChatPacket) packetReceived(session, (ClientboundPlayerChatPacket) packet); else if (packet instanceof ClientboundPlayerChatPacket) packetReceived(session, (ClientboundPlayerChatPacket) packet);
else if (packet instanceof ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet); else if (packet instanceof ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet);
else if (packet instanceof ClientboundGameProfilePacket) packetReceived(session, (ClientboundGameProfilePacket) packet); // TODO: Move uuid detection elsewhere
} }
public void packetReceived (Session session, ClientboundSystemChatPacket packet) { public void packetReceived (Session session, ClientboundSystemChatPacket packet) {
@ -105,12 +114,41 @@ public class ChatPlugin extends SessionAdapter {
} }
} }
public void packetReceived (Session session, ClientboundGameProfilePacket packet) {
uuid = packet.getProfile().getId();
}
// ? Should this be here? // ? Should this be here?
// TODO: Break up the method to make it less messy
public void tellraw (Component message, String targets) { public void tellraw (Component message, String targets) {
final int maxLength = client.core().maxCommandLength(); final int maxLength = client.core().maxCommandLength();
String command = "minecraft:tellraw " + targets + " " + GsonComponentSerializer.gson().serialize(message);
if (command.length() > maxLength) command = ("minecraft:w " + targets + " " + ComponentUtilities.stringify(message)); final String raw = GsonComponentSerializer.gson().serialize(message);
if (command.length() > maxLength) command = command.substring(0, maxLength); String command = "minecraft:tellraw " + targets + " " + raw;
if (command.length() > maxLength) {
String tagString;
boolean inspect;
CompoundTag itemTag = new CompoundTag("");
if (message instanceof TextComponent && message.style().isEmpty() && (message.children() == null || message.children().size() == 0)) {
tagString = ((TextComponent) message).content();
inspect = false;
} else {
tagString = raw;
inspect = true;
}
if (tagString.getBytes(StandardCharsets.UTF_8).length > 65535) return;
final Session session = client.session();
session.send(new ServerboundSetCreativeModeSlotPacket(26, new ItemStack(1 /* stone */, 1, itemTag)));
client.core().run("minecraft:tellraw " + targets + " {\"nbt\":\"SelectedItem.tag.m\",\"entity\":\"" + uuid.toString() + "\",\"inspect\":" + inspect + "}"); // TODO: Use GSON instead of concatenating strings, and hardcode less of this (it shouldn't matter here but yes)
return;
}
client.core().run(command); client.core().run(command);
} }
public void tellraw (Component message) { tellraw(message, "@a"); } public void tellraw (Component message) { tellraw(message, "@a"); }