Skip to content

Commit ea0efd8

Browse files
authored
Merge pull request #69 from Norbiros/main
Proper support fo 1.19.4!
2 parents 2d78e85 + 1fbadab commit ea0efd8

File tree

4 files changed

+17
-22
lines changed

4 files changed

+17
-22
lines changed

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group 'me.creepermaxcz.mc-bots'
6-
version '1.2.6'
6+
version '1.2.7'
77

88
sourceCompatibility = 1.8
99
targetCompatibility = 1.8
@@ -16,7 +16,7 @@ repositories {
1616
}
1717

1818
dependencies {
19-
implementation 'com.github.steveice10:mcprotocollib:1.19.2-1'
19+
implementation 'com.github.steveice10:mcprotocollib:1.19.4-1'
2020
implementation 'commons-cli:commons-cli:1.5.0'
2121
implementation 'com.diogonunes:JColor:5.2.0'
2222
implementation 'dnsjava:dnsjava:3.4.3'

gradlew

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -231,4 +231,4 @@ eval "set -- $(
231231
tr '\n' ' '
232232
)" '"$@"'
233233

234-
exec "$JAVACMD" "$@"
234+
exec "$JAVACMD" "$@"

src/main/java/me/creepermaxcz/mcbots/Bot.java

+13-18
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.github.steveice10.mc.protocol.data.UnexpectedEncryptionException;
88
import com.github.steveice10.mc.protocol.data.game.ClientCommand;
99
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundLoginPacket;
10-
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundRespawnPacket;
1110
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerCombatKillPacket;
1211
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
1312
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.ServerboundChatCommandPacket;
@@ -24,9 +23,7 @@
2423

2524
import java.net.InetSocketAddress;
2625
import java.time.Instant;
27-
import java.util.ArrayList;
28-
import java.util.Timer;
29-
import java.util.TimerTask;
26+
import java.util.*;
3027
import java.util.regex.Matcher;
3128
import java.util.regex.Pattern;
3229

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

127124
// Do not write disconnect reason if disconnected by command
128125
if (!manualDisconnecting) {
129-
//Log.info(" -> " + event.getReason());
130-
131-
//fix broken reason string by finding the content with regex
126+
// Fix broken reason string by finding the content with regex
132127
Pattern pattern = Pattern.compile("content=\"(.*?)\"");
133-
Matcher matcher = pattern.matcher(event.getReason());
128+
Matcher matcher = pattern.matcher(String.valueOf(event.getReason()));
134129

135130
StringBuilder reason = new StringBuilder();
136131
while (matcher.find()) {
@@ -169,24 +164,24 @@ public void sendChat(String text) {
169164
client.send(new ServerboundChatCommandPacket(
170165
text.substring(1),
171166
timeStamp,
167+
0L,
168+
Collections.emptyList(),
172169
0,
173-
new ArrayList<>(),
174-
true,
175-
new ArrayList<>(),
176-
null
170+
new BitSet()
177171
));
178172
} else {
179173
// Send chat message
180174
// From 1.19.1 or 1.19, the ServerboundChatPacket needs timestamp, salt and signed signature to generate packet.
181175
// tmpSignature will provide an empty byte array that can pretend it as signature.
182176
// salt is set 0 since this is offline server and no body will check it.
183-
client.send(new ServerboundChatPacket(text,
184-
timeStamp,
177+
178+
client.send(new ServerboundChatPacket(
179+
text,
180+
Instant.now().toEpochMilli(),
181+
0L,
182+
null,
185183
0,
186-
new byte[0],
187-
true,
188-
new ArrayList<>(),
189-
null
184+
new BitSet()
190185
));
191186
}
192187
}

src/main/java/me/creepermaxcz/mcbots/MainListener.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void packetReceived(Session session, Packet packet) {
3232
// For example, some commands like /say makes the message content as null.
3333
// However, the message exists as in getMessagePlain(), thus can retrieve message using the method.
3434
if (message == null) { // When this message was null.
35-
Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getMessagePlain(), Main.coloredChat));
35+
Log.chat(Utils.getFullText((TextComponent) sender, clientboundPlayerChatPacket.getContent(), Main.coloredChat));
3636
} else { // When message exists.
3737
Log.chat(Utils.getFullText((TextComponent) sender, (TextComponent) message, Main.coloredChat));
3838
}

0 commit comments

Comments
 (0)