1
1
package me .creepermaxcz .mcbots ;
2
2
3
3
import com .github .steveice10 .mc .protocol .MinecraftProtocol ;
4
- import com .github .steveice10 .mc .protocol .packet .ingame .client .ClientChatPacket ;
5
- import com .github .steveice10 .mc .protocol .packet .ingame .server .ServerJoinGamePacket ;
6
- import com .github .steveice10 .packetlib .Client ;
4
+ import com .github .steveice10 .mc .protocol .packet .ingame .clientbound .ClientboundLoginPacket ;
5
+ import com .github .steveice10 .mc .protocol .packet .ingame .serverbound .ServerboundChatPacket ;
7
6
import com .github .steveice10 .packetlib .ProxyInfo ;
7
+ import com .github .steveice10 .packetlib .Session ;
8
8
import com .github .steveice10 .packetlib .event .session .DisconnectedEvent ;
9
- import com .github .steveice10 .packetlib .event .session .PacketReceivedEvent ;
10
9
import com .github .steveice10 .packetlib .event .session .SessionAdapter ;
11
- import com .github .steveice10 .packetlib .tcp .TcpSessionFactory ;
10
+ import com .github .steveice10 .packetlib .packet .Packet ;
11
+ import com .github .steveice10 .packetlib .tcp .TcpClientSession ;
12
12
13
13
import java .net .InetSocketAddress ;
14
14
@@ -19,7 +19,7 @@ public class Bot extends Thread {
19
19
private String nickname ;
20
20
private ProxyInfo proxy ;
21
21
private InetSocketAddress address ;
22
- private Client client ;
22
+ private Session client ;
23
23
private boolean hasMainListener ;
24
24
25
25
public Bot (String nickname , InetSocketAddress address , ProxyInfo proxy ) {
@@ -29,18 +29,18 @@ public Bot(String nickname, InetSocketAddress address, ProxyInfo proxy) {
29
29
30
30
Log .info ("Creating bot" , nickname );
31
31
protocol = new MinecraftProtocol (nickname );
32
- client = new Client (address .getHostString (), address .getPort (), protocol , new TcpSessionFactory ( proxy ) );
32
+ client = new TcpClientSession (address .getHostString (), address .getPort (), protocol );
33
33
}
34
34
35
35
@ Override
36
36
public void run () {
37
37
38
38
if (!Main .isMinimal ()) {
39
- client .getSession (). addListener (new SessionAdapter () {
39
+ client .addListener (new SessionAdapter () {
40
40
41
41
@ Override
42
- public void packetReceived (PacketReceivedEvent event ) {
43
- if (event . getPacket () instanceof ServerJoinGamePacket ) {
42
+ public void packetReceived (Session session , Packet packet ) {
43
+ if (packet instanceof ClientboundLoginPacket ) {
44
44
Log .info (nickname + " connected" );
45
45
if (Main .joinMessage != null ) {
46
46
sendChat (Main .joinMessage );
@@ -52,7 +52,7 @@ public void packetReceived(PacketReceivedEvent event) {
52
52
public void disconnected (DisconnectedEvent event ) {
53
53
Log .info ();
54
54
Log .info (nickname + " disconnected" );
55
- Log .info (event .getReason ());
55
+ Log .info (" -> " + event .getReason ());
56
56
if (event .getCause () != null ) {
57
57
event .getCause ().printStackTrace ();
58
58
}
@@ -62,11 +62,11 @@ public void disconnected(DisconnectedEvent event) {
62
62
}
63
63
});
64
64
}
65
- client .getSession (). connect ();
65
+ client .connect ();
66
66
}
67
67
68
68
public void sendChat (String text ) {
69
- client .getSession (). send (new ClientChatPacket (text ));
69
+ client .send (new ServerboundChatPacket (text ));
70
70
}
71
71
72
72
@@ -77,7 +77,7 @@ public String getNickname() {
77
77
public void registerMainListener () {
78
78
hasMainListener = true ;
79
79
if (Main .isMinimal ()) return ;
80
- client .getSession (). addListener (new MainListener (nickname ));
80
+ client .addListener (new MainListener (nickname ));
81
81
}
82
82
83
83
public boolean hasMainListener () {
0 commit comments