feat: support for 1.19.4 #68

Closed
Vortezz wants to merge 1 commits from main into main
pull from: main
3 changed files with 18 additions and 24 deletions
Showing only changes of commit ed7e41678a - Show all commits

No files matched your search

+2 -1
View File
@@ -1,5 +1,6 @@
plugins { plugins {
id 'java' id 'java'
id 'com.github.johnrengelman.shadow' version '7.0.0'
} }
group 'me.creepermaxcz.mc-bots' group 'me.creepermaxcz.mc-bots'
@@ -16,7 +17,7 @@ repositories {
} }
dependencies { dependencies {
implementation 'com.github.steveice10:mcprotocollib:1.19.1-SNAPSHOT' implementation 'com.github.steveice10:mcprotocollib:1.19.4-SNAPSHOT'
implementation 'commons-cli:commons-cli:1.5.0' implementation 'commons-cli:commons-cli:1.5.0'
implementation 'com.diogonunes:JColor:5.2.0' implementation 'com.diogonunes:JColor:5.2.0'
implementation 'dnsjava:dnsjava:3.4.3' implementation 'dnsjava:dnsjava:3.4.3'
+15 -22
View File
@@ -7,24 +7,25 @@ import com.github.steveice10.mc.protocol.MinecraftProtocol;
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException; import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
import com.github.steveice10.mc.protocol.data.game.ClientCommand; import com.github.steveice10.mc.protocol.data.game.ClientCommand;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket; import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket;
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.ServerboundChatCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
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.ServerboundClientCommandPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundClientCommandPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.level.ServerboundAcceptTeleportationPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.*; import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.ServerboundMovePlayerPosPacket;
import com.github.steveice10.packetlib.ProxyInfo; import com.github.steveice10.packetlib.ProxyInfo;
import com.github.steveice10.packetlib.Session; import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent; import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter; import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.packet.Packet;
import com.github.steveice10.packetlib.tcp.TcpClientSession; import com.github.steveice10.packetlib.tcp.TcpClientSession;
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.time.Instant; import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.BitSet;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@@ -84,8 +85,7 @@ public class Bot extends Thread {
if (Main.joinMessage != null) { if (Main.joinMessage != null) {
sendChat(Main.joinMessage); sendChat(Main.joinMessage);
} }
} } else if (packet instanceof ClientboundPlayerPositionPacket) {
else if (packet instanceof ClientboundPlayerPositionPacket) {
ClientboundPlayerPositionPacket p = (ClientboundPlayerPositionPacket) packet; ClientboundPlayerPositionPacket p = (ClientboundPlayerPositionPacket) packet;
lastX = p.getX(); lastX = p.getX();
@@ -93,8 +93,7 @@ public class Bot extends Thread {
lastZ = p.getZ(); lastZ = p.getZ();
client.send(new ServerboundAcceptTeleportationPacket(p.getTeleportId())); client.send(new ServerboundAcceptTeleportationPacket(p.getTeleportId()));
} } else if (packet instanceof ClientboundPlayerCombatKillPacket) {
else if (packet instanceof ClientboundPlayerCombatKillPacket){
if (Main.autoRespawnDelay >= 0) { if (Main.autoRespawnDelay >= 0) {
Log.info("Bot " + nickname + " died. Respawning in " + Main.autoRespawnDelay + " ms."); Log.info("Bot " + nickname + " died. Respawning in " + Main.autoRespawnDelay + " ms.");
new Timer().schedule( new Timer().schedule(
@@ -123,7 +122,7 @@ public class Bot extends Thread {
//fix broken reason string by finding the content with regex //fix broken reason string by finding the content with regex
Pattern pattern = Pattern.compile("content=\"(.*?)\""); Pattern pattern = Pattern.compile("content=\"(.*?)\"");
Matcher matcher = pattern.matcher(event.getReason()); Matcher matcher = pattern.matcher(GsonComponentSerializer.gson().serialize(event.getReason()));
StringBuilder reason = new StringBuilder(); StringBuilder reason = new StringBuilder();
while (matcher.find()) { while (matcher.find()) {
@@ -132,7 +131,7 @@ public class Bot extends Thread {
Log.info(" -> " + reason.toString()); Log.info(" -> " + reason.toString());
if(event.getCause() != null) { if (event.getCause() != null) {
event.getCause().printStackTrace(); event.getCause().printStackTrace();
if (event.getCause() instanceof UnexpectedEncryptionException) { if (event.getCause() instanceof UnexpectedEncryptionException) {
@@ -162,9 +161,8 @@ public class Bot extends Thread {
timeStamp, timeStamp,
0, 0,
new ArrayList<>(), new ArrayList<>(),
true, 0,
new ArrayList<>(), new BitSet()
null
)); ));
} else { } else {
// Send chat message // Send chat message
@@ -175,9 +173,8 @@ public class Bot extends Thread {
timeStamp, timeStamp,
0, 0,
new byte[0], new byte[0],
true, 0,
new ArrayList<>(), new BitSet()
null
)); ));
} }
} }
@@ -196,23 +193,20 @@ public class Bot extends Thread {
return hasMainListener; return hasMainListener;
} }
public void fallDown() public void fallDown() {
{
if (connected && lastY > 0) { if (connected && lastY > 0) {
move(0, -0.5, 0); move(0, -0.5, 0);
} }
} }
public void move(double x, double y, double z) public void move(double x, double y, double z) {
{
lastX += x; lastX += x;
lastY += y; lastY += y;
lastZ += z; lastZ += z;
moveTo(lastX, lastY, lastZ); moveTo(lastX, lastY, lastZ);
} }
public void moveTo(double x, double y, double z) public void moveTo(double x, double y, double z) {
{
client.send(new ServerboundMovePlayerPosPacket(true, x, y, z)); client.send(new ServerboundMovePlayerPosPacket(true, x, y, z));
} }
@@ -220,8 +214,7 @@ public class Bot extends Thread {
return connected; return connected;
} }
public void disconnect() public void disconnect() {
{
manualDisconnecting = true; manualDisconnecting = true;
client.disconnect("Leaving"); client.disconnect("Leaving");
} }
@@ -32,7 +32,7 @@ public class MainListener implements SessionListener {
// For example, some commands like /say makes the message content as null. // For example, some commands like /say makes the message content as null.
// However, the message exists as in getMessagePlain(), thus can retrieve message using the method. // However, the message exists as in getMessagePlain(), thus can retrieve message using the method.
if (message == null) { // When this message was null. if (message == null) { // When this message was null.
Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getMessagePlain(), Main.coloredChat)); Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getContent(), Main.coloredChat));
} else { // When message exists. } else { // When message exists.
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat)); Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat));
} }