Skip to content

Commit

Permalink
feat: Support 1.19.4!
Browse files Browse the repository at this point in the history
  • Loading branch information
Norbiros committed Jul 2, 2023
1 parent f8e2f2d commit 1fbadab
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

group 'me.creepermaxcz.mc-bots'
version '1.2.6'
version '1.2.7'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand All @@ -16,7 +16,7 @@ repositories {
}

dependencies {
implementation 'com.github.steveice10:mcprotocollib:1.19.2-1'
implementation 'com.github.steveice10:mcprotocollib:1.19.4-1'
implementation 'commons-cli:commons-cli:1.5.0'
implementation 'com.diogonunes:JColor:5.2.0'
implementation 'dnsjava:dnsjava:3.4.3'
Expand Down
2 changes: 1 addition & 1 deletion gradlew
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,4 @@ eval "set -- $(
tr '\n' ' '
)" '"$@"'

exec "$JAVACMD" "$@"
exec "$JAVACMD" "$@"
31 changes: 13 additions & 18 deletions src/main/java/me/creepermaxcz/mcbots/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
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.ClientboundRespawnPacket;
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.serverbound.ServerboundChatCommandPacket;
Expand All @@ -24,9 +23,7 @@

import java.net.InetSocketAddress;
import java.time.Instant;
import java.util.ArrayList;
import java.util.Timer;
import java.util.TimerTask;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -126,11 +123,9 @@ public void disconnected(DisconnectedEvent event) {

// Do not write disconnect reason if disconnected by command
if (!manualDisconnecting) {
//Log.info(" -> " + event.getReason());

//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=\"(.*?)\"");
Matcher matcher = pattern.matcher(event.getReason());
Matcher matcher = pattern.matcher(String.valueOf(event.getReason()));

StringBuilder reason = new StringBuilder();
while (matcher.find()) {
Expand Down Expand Up @@ -169,24 +164,24 @@ public void sendChat(String text) {
client.send(new ServerboundChatCommandPacket(
text.substring(1),
timeStamp,
0L,
Collections.emptyList(),
0,
new ArrayList<>(),
true,
new ArrayList<>(),
null
new BitSet()
));
} else {
// Send chat message
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
// tmpSignature will provide an empty byte array that can pretend it as signature.
// salt is set 0 since this is offline server and no body will check it.
client.send(new ServerboundChatPacket(text,
timeStamp,

client.send(new ServerboundChatPacket(
text,
Instant.now().toEpochMilli(),
0L,
null,
0,
new byte[0],
true,
new ArrayList<>(),
null
new BitSet()
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/me/creepermaxcz/mcbots/MainListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void packetReceived(Session session, Packet packet) {
// 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.
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.
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat));
}
Expand Down

0 comments on commit 1fbadab

Please sign in to comment.