Bump to 1.19..4

This commit is contained in:
Chipmunk 2023-04-11 20:54:37 -04:00
parent 3501eafe68
commit 4fb880e092
13 changed files with 96 additions and 51 deletions

View file

@ -15,7 +15,7 @@
<repositories>
<repository>
<id>opencollab</id>
<url>https://repo.opencollab.dev/maven-releases/</url>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
</repository>
<repository>
@ -29,7 +29,7 @@
<dependency>
<groupId>com.github.steveice10</groupId>
<artifactId>mcprotocollib</artifactId>
<version>1.19.2-1</version>
<version>1.19.4-math2-SNAPSHOT</version>
</dependency>
<dependency>

View file

@ -1,6 +1,6 @@
package land.chipmunk.chipmunkbot.data;
import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector3i;
import lombok.Data;
import lombok.AllArgsConstructor;

View file

@ -14,6 +14,7 @@ import java.security.PublicKey;
public class MutablePlayerListEntry {
private GameProfile profile;
private GameMode gamemode;
private boolean listed;
private int latency;
private Component displayName;
private long expiresAt;
@ -21,6 +22,6 @@ public class MutablePlayerListEntry {
private byte[] keySignature;
public MutablePlayerListEntry (PlayerListEntry entry) {
this(entry.getProfile(), entry.getGameMode(), entry.getPing(), entry.getDisplayName(), entry.getExpiresAt(), entry.getPublicKey(), entry.getKeySignature());
this(entry.getProfile(), entry.getGameMode(), entry.isListed(), entry.getLatency(), entry.getDisplayName(), entry.getExpiresAt(), entry.getPublicKey(), entry.getKeySignature());
}
}

View file

@ -5,12 +5,11 @@ import lombok.Data;
import lombok.AllArgsConstructor;
import net.kyori.adventure.text.Component;
import java.util.Map;
@Data
@AllArgsConstructor
public class PlayerMessage {
private String type;
private MutablePlayerListEntry sender;
private Map<String, Component> parameters;
private Component contents;
private String chatType;
private Component senderName;
}

View file

@ -29,7 +29,7 @@ public class ChatCommandHandler extends ChatPlugin.Listener {
@Override
public void playerMessageReceived (PlayerMessage message) {
final Component contents = message.parameters().get("contents");
final Component contents = message.contents();
if (contents == null) return;
final String contentsString = ComponentUtilities.stringify(contents);
if (!contentsString.startsWith(prefix)) return;

View file

@ -3,9 +3,11 @@ package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.data.chat.PlayerMessage;
import land.chipmunk.chipmunkbot.data.chat.SystemChatParser;
import land.chipmunk.chipmunkbot.data.MutablePlayerListEntry;
import land.chipmunk.chipmunkbot.util.UUIDUtilities;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerChatPacket;
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.ClientboundDisguisedChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
import com.github.steveice10.packetlib.packet.Packet;
@ -13,9 +15,11 @@ import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.event.session.SessionListener;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.HoverEvent;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import lombok.Getter;
import java.util.BitSet;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@ -39,19 +43,20 @@ public class ChatPlugin extends SessionAdapter {
}
public void message (String message) {
final ServerboundChatPacket packet = new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0, new byte[0], false, new ArrayList<>(), null);
final ServerboundChatPacket packet = new ServerboundChatPacket(message, Instant.now().toEpochMilli(), 0, new byte[0], 0, new BitSet());
client.session().send(packet);
}
public void command (String command) {
final ServerboundChatCommandPacket packet = new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0, new ArrayList<>(), false, new ArrayList<>(), null);
final ServerboundChatCommandPacket packet = new ServerboundChatCommandPacket(command, Instant.now().toEpochMilli(), 0, Collections.emptyList(), 0, new BitSet());
client.session().send(packet);
}
@Override
public void packetReceived (Session session, Packet packet) {
// TODO: Player chat
if (packet instanceof ClientboundSystemChatPacket) packetReceived(session, (ClientboundSystemChatPacket) packet);
else if (packet instanceof ClientboundPlayerChatPacket) packetReceived(session, (ClientboundPlayerChatPacket) packet);
else if (packet instanceof ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet);
}
public void packetReceived (Session session, ClientboundSystemChatPacket packet) {
@ -71,6 +76,34 @@ public class ChatPlugin extends SessionAdapter {
}
}
public void packetReceived (Session session, ClientboundPlayerChatPacket packet) {
final MutablePlayerListEntry sender = client.playerList().getEntry(packet.getSender());
if (sender == null) return;
final PlayerMessage playerMessage = new PlayerMessage(sender, Component.text(packet.getContent()), "minecraft:chat", packet.getName()); // TODO: Fix chatType
for (Listener listener : this.listeners) {
listener.playerMessageReceived(playerMessage);
}
}
public void packetReceived (Session session, ClientboundDisguisedChatPacket packet) {
PlayerMessage parsedFromMessage = null;
final Component component = packet.getMessage();
for (SystemChatParser parser : systemChatParsers) {
parsedFromMessage = parser.parse(component);
if (parsedFromMessage != null) break;
}
if (parsedFromMessage == null) return;
final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender(), parsedFromMessage.contents(), "minecraft:chat", packet.getName()); // TODO: Fix chatType
for (Listener listener : this.listeners) {
listener.playerMessageReceived(playerMessage);
}
}
// ? Should this be here?
public void tellraw (Component message, String targets) {
client.core.run("minecraft:tellraw " + targets + " " + GsonComponentSerializer.gson().serialize(message));

View file

@ -3,7 +3,7 @@ package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import land.chipmunk.chipmunkbot.plugins.PositionManager;
import land.chipmunk.chipmunkbot.data.BlockArea;
import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector3i;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionListener;
@ -96,7 +96,7 @@ public class CommandCore extends SessionAdapter {
client.chat().command(command);
// final Session session = client.session();
// session.send(new ServerboundSetCreativeModeSlotPacket(45, new ItemStack(347 /* command_block */, 1, itemTag)));
// session.send(new ServerboundSetCreativeModeSlotPacket(45, new ItemStack(371 /* command_block */, 1, itemTag)));
// session.send(new ServerboundPlayerActionPacket(PlayerAction.START_DIGGING, temporaryBlockPosition, Direction.NORTH, 0));
// session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.NORTH, Hand.OFF_HAND, 0.5f, 0.5f, 0.5f, false, 0));
}

View file

@ -1,7 +1,8 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.ChipmunkBot;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoUpdatePacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoRemovePacket;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
@ -26,17 +27,26 @@ public class PlayerListPlugin extends SessionAdapter {
@Override
public void packetReceived (Session session, Packet packet) {
if (packet instanceof ClientboundPlayerInfoPacket) packetReceived(session, (ClientboundPlayerInfoPacket) packet);
if (packet instanceof ClientboundPlayerInfoUpdatePacket) packetReceived(session, (ClientboundPlayerInfoUpdatePacket) packet);
else if (packet instanceof ClientboundPlayerInfoRemovePacket) packetReceived(session, (ClientboundPlayerInfoRemovePacket) packet);
}
public void packetReceived (Session session, ClientboundPlayerInfoPacket packet) {
PlayerListEntryAction action = packet.getAction();
for (PlayerListEntry entry : packet.getEntries()) {
if (action == PlayerListEntryAction.ADD_PLAYER) addPlayer(entry);
else if (action == PlayerListEntryAction.UPDATE_GAMEMODE) updateGamemode(entry);
else if (action == PlayerListEntryAction.UPDATE_LATENCY) updateLatency(entry);
else if (action == PlayerListEntryAction.UPDATE_DISPLAY_NAME) updateDisplayName(entry);
else if (action == PlayerListEntryAction.REMOVE_PLAYER) removePlayer(entry);
public void packetReceived (Session session, ClientboundPlayerInfoUpdatePacket packet) {
for (PlayerListEntryAction action : packet.getActions()) {
for (PlayerListEntry entry : packet.getEntries()) {
if (action == PlayerListEntryAction.ADD_PLAYER) addPlayer(entry);
else if (action == PlayerListEntryAction.INITIALIZE_CHAT) initializeChat(entry);
else if (action == PlayerListEntryAction.UPDATE_GAME_MODE) updateGamemode(entry);
else if (action == PlayerListEntryAction.UPDATE_LISTED) updateListed(entry);
else if (action == PlayerListEntryAction.UPDATE_LATENCY) updateLatency(entry);
else if (action == PlayerListEntryAction.UPDATE_DISPLAY_NAME) updateDisplayName(entry);
}
}
}
public void packetReceived (Session session, ClientboundPlayerInfoRemovePacket packet) {
for (UUID uuid : packet.getProfileIds()) {
removePlayer(uuid);
}
}
@ -81,6 +91,13 @@ public class PlayerListPlugin extends SessionAdapter {
list.add(new MutablePlayerListEntry(newEntry));
}
private void initializeChat (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
target.publicKey(newEntry.getPublicKey());
}
private void updateGamemode (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
@ -88,11 +105,18 @@ public class PlayerListPlugin extends SessionAdapter {
target.gamemode(newEntry.getGameMode());
}
private void updateListed (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
target.listed(newEntry.isListed());
}
private void updateLatency (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry);
if (target == null) return;
target.latency(newEntry.getPing());
target.latency(newEntry.getLatency());
}
private void updateDisplayName (PlayerListEntry newEntry) {
@ -102,8 +126,8 @@ public class PlayerListPlugin extends SessionAdapter {
target.displayName(newEntry.getDisplayName());
}
private void removePlayer (PlayerListEntry newEntry) {
final MutablePlayerListEntry target = getEntry(newEntry);
private void removePlayer (UUID uuid) {
final MutablePlayerListEntry target = getEntry(uuid);
if (target == null) return;
client.tabComplete().complete("/scoreboard players add ").thenApply(packet -> {
@ -113,6 +137,7 @@ public class PlayerListPlugin extends SessionAdapter {
for (int i = 0; i < matches.length; i++) {
if (tooltips[i] != null || !matches[i].equals(username)) continue;
target.listed(false);
return packet;
}

View file

@ -1,15 +1,15 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.Client;
import com.nukkitx.math.vector.Vector3d;
import org.cloudburstmc.math.vector.Vector3d;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionListener;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
import com.nukkitx.math.vector.Vector3d;
import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector3d;
import org.cloudburstmc.math.vector.Vector3i;
import lombok.Getter;
import lombok.Setter;

View file

@ -1,7 +1,7 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.Client;
import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector3i;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionListener;

View file

@ -1,7 +1,7 @@
package land.chipmunk.chipmunkbot.plugins;
import land.chipmunk.chipmunkbot.Client;
import com.nukkitx.math.vector.Vector3i;
import org.cloudburstmc.math.vector.Vector3i;
import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionListener;

View file

@ -11,9 +11,7 @@ import net.kyori.adventure.text.TextComponent;
import net.kyori.adventure.text.TranslatableComponent;
import net.kyori.adventure.text.format.Style;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
public class KaboomChatParser implements SystemChatParser {
@ -44,8 +42,6 @@ public class KaboomChatParser implements SystemChatParser {
if (!message.content().equals("") || !message.style().equals(empty) || children == null || children.size() < 3) return null;
final Map<String, Component> parameters = new HashMap<>();
final Component prefix = children.get(0);
Component displayName = Component.empty();
Component contents = Component.empty();
@ -61,13 +57,9 @@ public class KaboomChatParser implements SystemChatParser {
MutablePlayerListEntry sender = client.playerList().getEntry(Component.empty().append(prefix).append(displayName));
if (sender == null) sender = client.playerList().getEntry(prefix.append(displayName)); // deprecated
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(new UUID(0l, 0l), null), GameMode.SURVIVAL, 0, displayName, 0L, null, new byte[0]);
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(new UUID(0l, 0l), null), GameMode.SURVIVAL, false, 0, displayName, 0L, null, new byte[0]);
parameters.put("sender", displayName);
parameters.put("prefix", prefix);
parameters.put("contents", contents);
return new PlayerMessage("minecraft:chat", sender, parameters);
return new PlayerMessage(sender, contents, "minecraft:chat", displayName);
}
private boolean isSeperatorAt (List<Component> children, int start) {

View file

@ -45,23 +45,18 @@ public class MinecraftChatParser implements SystemChatParser {
final String type = typeMap.get(key);
final Map<String, Component> parameters = new HashMap<>();
final Component senderComponent = args.get(0);
final Component contents = args.get(1);
// Find the sender and attempt to map it to a player
final HoverEvent hoverEvent = senderComponent.hoverEvent();
final HoverEvent<?> hoverEvent = senderComponent.hoverEvent();
if (hoverEvent == null || !hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) return null;
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
final UUID senderUUID = entityInfo.id();
MutablePlayerListEntry sender = client.playerList().getEntry(senderUUID);
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(senderUUID, null), GameMode.SURVIVAL, 0, entityInfo.name(), 0L, null, new byte[0]);
if (sender == null) sender = new MutablePlayerListEntry(new GameProfile(senderUUID, null), GameMode.SURVIVAL, true, 0, entityInfo.name(), 0L, null, new byte[0]);
parameters.put("sender", senderComponent);
parameters.put("contents", contents);
return new PlayerMessage(type, sender, parameters);
return new PlayerMessage(sender, contents, "minecraft:chat", senderComponent);
}
}