forked from chipmunkmc/chipmunkbot
Bump to 1.19..4
This commit is contained in:
parent
3501eafe68
commit
4fb880e092
13 changed files with 96 additions and 51 deletions
4
pom.xml
4
pom.xml
|
@ -15,7 +15,7 @@
|
||||||
<repositories>
|
<repositories>
|
||||||
<repository>
|
<repository>
|
||||||
<id>opencollab</id>
|
<id>opencollab</id>
|
||||||
<url>https://repo.opencollab.dev/maven-releases/</url>
|
<url>https://repo.opencollab.dev/maven-snapshots/</url>
|
||||||
</repository>
|
</repository>
|
||||||
|
|
||||||
<repository>
|
<repository>
|
||||||
|
@ -29,7 +29,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.github.steveice10</groupId>
|
<groupId>com.github.steveice10</groupId>
|
||||||
<artifactId>mcprotocollib</artifactId>
|
<artifactId>mcprotocollib</artifactId>
|
||||||
<version>1.19.2-1</version>
|
<version>1.19.4-math2-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package land.chipmunk.chipmunkbot.data;
|
package land.chipmunk.chipmunkbot.data;
|
||||||
|
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.security.PublicKey;
|
||||||
public class MutablePlayerListEntry {
|
public class MutablePlayerListEntry {
|
||||||
private GameProfile profile;
|
private GameProfile profile;
|
||||||
private GameMode gamemode;
|
private GameMode gamemode;
|
||||||
|
private boolean listed;
|
||||||
private int latency;
|
private int latency;
|
||||||
private Component displayName;
|
private Component displayName;
|
||||||
private long expiresAt;
|
private long expiresAt;
|
||||||
|
@ -21,6 +22,6 @@ public class MutablePlayerListEntry {
|
||||||
private byte[] keySignature;
|
private byte[] keySignature;
|
||||||
|
|
||||||
public MutablePlayerListEntry (PlayerListEntry entry) {
|
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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,12 +5,11 @@ import lombok.Data;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public class PlayerMessage {
|
public class PlayerMessage {
|
||||||
private String type;
|
|
||||||
private MutablePlayerListEntry sender;
|
private MutablePlayerListEntry sender;
|
||||||
private Map<String, Component> parameters;
|
private Component contents;
|
||||||
|
private String chatType;
|
||||||
|
private Component senderName;
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ public class ChatCommandHandler extends ChatPlugin.Listener {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void playerMessageReceived (PlayerMessage message) {
|
public void playerMessageReceived (PlayerMessage message) {
|
||||||
final Component contents = message.parameters().get("contents");
|
final Component contents = message.contents();
|
||||||
if (contents == null) return;
|
if (contents == null) return;
|
||||||
final String contentsString = ComponentUtilities.stringify(contents);
|
final String contentsString = ComponentUtilities.stringify(contents);
|
||||||
if (!contentsString.startsWith(prefix)) return;
|
if (!contentsString.startsWith(prefix)) return;
|
||||||
|
|
|
@ -3,9 +3,11 @@ package land.chipmunk.chipmunkbot.plugins;
|
||||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||||
import land.chipmunk.chipmunkbot.data.chat.PlayerMessage;
|
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.util.UUIDUtilities;
|
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.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.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.packetlib.packet.Packet;
|
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.SessionAdapter;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
|
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;
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
@ -39,19 +43,20 @@ public class ChatPlugin extends SessionAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void message (String message) {
|
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);
|
client.session().send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void command (String command) {
|
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);
|
client.session().send(packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived (Session session, Packet packet) {
|
public void packetReceived (Session session, Packet packet) {
|
||||||
// TODO: Player chat
|
|
||||||
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 ClientboundDisguisedChatPacket) packetReceived(session, (ClientboundDisguisedChatPacket) packet);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void packetReceived (Session session, ClientboundSystemChatPacket 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?
|
// ? Should this be here?
|
||||||
public void tellraw (Component message, String targets) {
|
public void tellraw (Component message, String targets) {
|
||||||
client.core.run("minecraft:tellraw " + targets + " " + GsonComponentSerializer.gson().serialize(message));
|
client.core.run("minecraft:tellraw " + targets + " " + GsonComponentSerializer.gson().serialize(message));
|
||||||
|
|
|
@ -3,7 +3,7 @@ package land.chipmunk.chipmunkbot.plugins;
|
||||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
||||||
import land.chipmunk.chipmunkbot.plugins.PositionManager;
|
import land.chipmunk.chipmunkbot.plugins.PositionManager;
|
||||||
import land.chipmunk.chipmunkbot.data.BlockArea;
|
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.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
|
@ -96,7 +96,7 @@ public class CommandCore extends SessionAdapter {
|
||||||
client.chat().command(command);
|
client.chat().command(command);
|
||||||
|
|
||||||
// final Session session = client.session();
|
// 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 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));
|
// session.send(new ServerboundUseItemOnPacket(temporaryBlockPosition, Direction.NORTH, Hand.OFF_HAND, 0.5f, 0.5f, 0.5f, false, 0));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package land.chipmunk.chipmunkbot.plugins;
|
package land.chipmunk.chipmunkbot.plugins;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkbot.ChipmunkBot;
|
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.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;
|
||||||
|
@ -26,17 +27,26 @@ public class PlayerListPlugin extends SessionAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void packetReceived (Session session, Packet packet) {
|
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) {
|
public void packetReceived (Session session, ClientboundPlayerInfoUpdatePacket packet) {
|
||||||
PlayerListEntryAction action = packet.getAction();
|
for (PlayerListEntryAction action : packet.getActions()) {
|
||||||
for (PlayerListEntry entry : packet.getEntries()) {
|
for (PlayerListEntry entry : packet.getEntries()) {
|
||||||
if (action == PlayerListEntryAction.ADD_PLAYER) addPlayer(entry);
|
if (action == PlayerListEntryAction.ADD_PLAYER) addPlayer(entry);
|
||||||
else if (action == PlayerListEntryAction.UPDATE_GAMEMODE) updateGamemode(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_LATENCY) updateLatency(entry);
|
||||||
else if (action == PlayerListEntryAction.UPDATE_DISPLAY_NAME) updateDisplayName(entry);
|
else if (action == PlayerListEntryAction.UPDATE_DISPLAY_NAME) updateDisplayName(entry);
|
||||||
else if (action == PlayerListEntryAction.REMOVE_PLAYER) removePlayer(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));
|
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) {
|
private void updateGamemode (PlayerListEntry newEntry) {
|
||||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
final MutablePlayerListEntry target = getEntry(newEntry);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
@ -88,11 +105,18 @@ public class PlayerListPlugin extends SessionAdapter {
|
||||||
target.gamemode(newEntry.getGameMode());
|
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) {
|
private void updateLatency (PlayerListEntry newEntry) {
|
||||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
final MutablePlayerListEntry target = getEntry(newEntry);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
target.latency(newEntry.getPing());
|
target.latency(newEntry.getLatency());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateDisplayName (PlayerListEntry newEntry) {
|
private void updateDisplayName (PlayerListEntry newEntry) {
|
||||||
|
@ -102,8 +126,8 @@ public class PlayerListPlugin extends SessionAdapter {
|
||||||
target.displayName(newEntry.getDisplayName());
|
target.displayName(newEntry.getDisplayName());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removePlayer (PlayerListEntry newEntry) {
|
private void removePlayer (UUID uuid) {
|
||||||
final MutablePlayerListEntry target = getEntry(newEntry);
|
final MutablePlayerListEntry target = getEntry(uuid);
|
||||||
if (target == null) return;
|
if (target == null) return;
|
||||||
|
|
||||||
client.tabComplete().complete("/scoreboard players add ").thenApply(packet -> {
|
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++) {
|
for (int i = 0; i < matches.length; i++) {
|
||||||
if (tooltips[i] != null || !matches[i].equals(username)) continue;
|
if (tooltips[i] != null || !matches[i].equals(username)) continue;
|
||||||
|
target.listed(false);
|
||||||
return packet;
|
return packet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
package land.chipmunk.chipmunkbot.plugins;
|
package land.chipmunk.chipmunkbot.plugins;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkbot.Client;
|
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.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionAdapter;
|
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.clientbound.entity.player.ClientboundPlayerPositionPacket;
|
||||||
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
|
||||||
import com.nukkitx.math.vector.Vector3d;
|
import org.cloudburstmc.math.vector.Vector3d;
|
||||||
import com.nukkitx.math.vector.Vector3i;
|
import org.cloudburstmc.math.vector.Vector3i;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package land.chipmunk.chipmunkbot.plugins;
|
package land.chipmunk.chipmunkbot.plugins;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkbot.Client;
|
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.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package land.chipmunk.chipmunkbot.plugins;
|
package land.chipmunk.chipmunkbot.plugins;
|
||||||
|
|
||||||
import land.chipmunk.chipmunkbot.Client;
|
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.packet.Packet;
|
||||||
import com.github.steveice10.packetlib.Session;
|
import com.github.steveice10.packetlib.Session;
|
||||||
import com.github.steveice10.packetlib.event.session.SessionListener;
|
import com.github.steveice10.packetlib.event.session.SessionListener;
|
||||||
|
|
|
@ -11,9 +11,7 @@ import net.kyori.adventure.text.TextComponent;
|
||||||
import net.kyori.adventure.text.TranslatableComponent;
|
import net.kyori.adventure.text.TranslatableComponent;
|
||||||
import net.kyori.adventure.text.format.Style;
|
import net.kyori.adventure.text.format.Style;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
public class KaboomChatParser implements SystemChatParser {
|
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;
|
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);
|
final Component prefix = children.get(0);
|
||||||
Component displayName = Component.empty();
|
Component displayName = Component.empty();
|
||||||
Component contents = 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));
|
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 = 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);
|
return new PlayerMessage(sender, contents, "minecraft:chat", displayName);
|
||||||
parameters.put("prefix", prefix);
|
|
||||||
parameters.put("contents", contents);
|
|
||||||
|
|
||||||
return new PlayerMessage("minecraft:chat", sender, parameters);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSeperatorAt (List<Component> children, int start) {
|
private boolean isSeperatorAt (List<Component> children, int start) {
|
||||||
|
|
|
@ -45,23 +45,18 @@ public class MinecraftChatParser implements SystemChatParser {
|
||||||
|
|
||||||
final String type = typeMap.get(key);
|
final String type = typeMap.get(key);
|
||||||
|
|
||||||
final Map<String, Component> parameters = new HashMap<>();
|
|
||||||
|
|
||||||
final Component senderComponent = args.get(0);
|
final Component senderComponent = args.get(0);
|
||||||
final Component contents = args.get(1);
|
final Component contents = args.get(1);
|
||||||
|
|
||||||
// Find the sender and attempt to map it to a player
|
// 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;
|
if (hoverEvent == null || !hoverEvent.action().equals(HoverEvent.Action.SHOW_ENTITY)) return null;
|
||||||
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
|
HoverEvent.ShowEntity entityInfo = (HoverEvent.ShowEntity) hoverEvent.value();
|
||||||
final UUID senderUUID = entityInfo.id();
|
final UUID senderUUID = entityInfo.id();
|
||||||
|
|
||||||
MutablePlayerListEntry sender = client.playerList().getEntry(senderUUID);
|
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);
|
return new PlayerMessage(sender, contents, "minecraft:chat", senderComponent);
|
||||||
parameters.put("contents", contents);
|
|
||||||
|
|
||||||
return new PlayerMessage(type, sender, parameters);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue