diff --git a/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java b/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java
index a9b6d774..98f1f119 100644
--- a/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java
+++ b/example/com/github/steveice10/mc/protocol/test/MinecraftProtocolTest.java
@@ -26,7 +26,6 @@ import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.LongTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
import com.github.steveice10.opennbt.tag.builtin.Tag;
-import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.ProxyInfo;
import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
@@ -37,7 +36,8 @@ import com.github.steveice10.packetlib.event.server.SessionRemovedEvent;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
-import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
+import com.github.steveice10.packetlib.tcp.TcpClientSession;
+import com.github.steveice10.packetlib.tcp.TcpServer;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -61,24 +61,19 @@ public class MinecraftProtocolTest {
SessionService sessionService = new SessionService();
sessionService.setProxy(AUTH_PROXY);
- Server server = new Server(HOST, PORT, MinecraftProtocol.class, new TcpSessionFactory());
+ Server server = new TcpServer(HOST, PORT, MinecraftProtocol.class);
server.setGlobalFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
server.setGlobalFlag(MinecraftConstants.VERIFY_USERS_KEY, VERIFY_USERS);
- server.setGlobalFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY, new ServerInfoBuilder() {
- @Override
- public ServerStatusInfo buildInfo(Session session) {
- return new ServerStatusInfo(
+ server.setGlobalFlag(MinecraftConstants.SERVER_INFO_BUILDER_KEY, (ServerInfoBuilder) session ->
+ new ServerStatusInfo(
new VersionInfo(MinecraftConstants.GAME_VERSION, MinecraftConstants.PROTOCOL_VERSION),
new PlayerInfo(100, 0, new GameProfile[0]),
Component.text("Hello world!"),
null
- );
- }
- });
+ )
+ );
- server.setGlobalFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY, new ServerLoginHandler() {
- @Override
- public void loggedIn(Session session) {
+ server.setGlobalFlag(MinecraftConstants.SERVER_LOGIN_HANDLER_KEY, (ServerLoginHandler) session ->
session.send(new ServerJoinGamePacket(
0,
false,
@@ -96,9 +91,8 @@ public class MinecraftProtocolTest {
false,
false,
false
- ));
- }
- });
+ ))
+ );
server.setGlobalFlag(MinecraftConstants.SERVER_COMPRESSION_THRESHOLD, 100);
server.addListener(new ServerAdapter() {
@@ -153,28 +147,23 @@ public class MinecraftProtocolTest {
sessionService.setProxy(AUTH_PROXY);
MinecraftProtocol protocol = new MinecraftProtocol();
- Client client = new Client(HOST, PORT, protocol, new TcpSessionFactory(PROXY));
- client.getSession().setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
- client.getSession().setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, new ServerInfoHandler() {
- @Override
- public void handle(Session session, ServerStatusInfo info) {
- System.out.println("Version: " + info.getVersionInfo().getVersionName() + ", " + info.getVersionInfo().getProtocolVersion());
- System.out.println("Player Count: " + info.getPlayerInfo().getOnlinePlayers() + " / " + info.getPlayerInfo().getMaxPlayers());
- System.out.println("Players: " + Arrays.toString(info.getPlayerInfo().getPlayers()));
- System.out.println("Description: " + info.getDescription());
- System.out.println("Icon: " + info.getIconPng());
- }
+ Session client = new TcpClientSession(HOST, PORT, protocol, PROXY);
+ client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
+ client.setFlag(MinecraftConstants.SERVER_INFO_HANDLER_KEY, (ServerInfoHandler) (session, info) -> {
+ System.out.println("Version: " + info.getVersionInfo().getVersionName()
+ + ", " + info.getVersionInfo().getProtocolVersion());
+ System.out.println("Player Count: " + info.getPlayerInfo().getOnlinePlayers()
+ + " / " + info.getPlayerInfo().getMaxPlayers());
+ System.out.println("Players: " + Arrays.toString(info.getPlayerInfo().getPlayers()));
+ System.out.println("Description: " + info.getDescription());
+ System.out.println("Icon: " + info.getIconPng());
});
- client.getSession().setFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY, new ServerPingTimeHandler() {
- @Override
- public void handle(Session session, long pingTime) {
- System.out.println("Server ping took " + pingTime + "ms");
- }
- });
+ client.setFlag(MinecraftConstants.SERVER_PING_TIME_HANDLER_KEY, (ServerPingTimeHandler) (session, pingTime) ->
+ System.out.println("Server ping took " + pingTime + "ms"));
- client.getSession().connect();
- while(client.getSession().isConnected()) {
+ client.connect();
+ while(client.isConnected()) {
try {
Thread.sleep(5);
} catch(InterruptedException e) {
@@ -206,9 +195,9 @@ public class MinecraftProtocolTest {
SessionService sessionService = new SessionService();
sessionService.setProxy(AUTH_PROXY);
- Client client = new Client(HOST, PORT, protocol, new TcpSessionFactory(PROXY));
- client.getSession().setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
- client.getSession().addListener(new SessionAdapter() {
+ Session client = new TcpClientSession(HOST, PORT, protocol, PROXY);
+ client.setFlag(MinecraftConstants.SESSION_SERVICE_KEY, sessionService);
+ client.addListener(new SessionAdapter() {
@Override
public void packetReceived(PacketReceivedEvent event) {
if(event.getPacket() instanceof ServerJoinGamePacket) {
@@ -229,7 +218,7 @@ public class MinecraftProtocolTest {
}
});
- client.getSession().connect();
+ client.connect();
}
private static CompoundTag getDimensionTag() {
diff --git a/pom.xml b/pom.xml
index f5e2b621..b890c6b8 100644
--- a/pom.xml
+++ b/pom.xml
@@ -62,7 +62,7 @@
com.github.steveice10
packetlib
- 1.8
+ ac5600734e
compile
diff --git a/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java b/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java
index 3c76bb98..edd25b0b 100644
--- a/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java
+++ b/src/main/java/com/github/steveice10/mc/protocol/MinecraftProtocol.java
@@ -157,7 +157,6 @@ import com.github.steveice10.mc.protocol.packet.status.client.StatusPingPacket;
import com.github.steveice10.mc.protocol.packet.status.client.StatusQueryPacket;
import com.github.steveice10.mc.protocol.packet.status.server.StatusPongPacket;
import com.github.steveice10.mc.protocol.packet.status.server.StatusResponsePacket;
-import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.crypt.AESEncryption;
@@ -165,9 +164,7 @@ import com.github.steveice10.packetlib.crypt.PacketEncryption;
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
import com.github.steveice10.packetlib.packet.PacketHeader;
import com.github.steveice10.packetlib.packet.PacketProtocol;
-import lombok.AccessLevel;
import lombok.Getter;
-import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
@@ -327,7 +324,7 @@ public class MinecraftProtocol extends PacketProtocol {
}
@Override
- public void newClientSession(Client client, Session session) {
+ public void newClientSession(Session session) {
session.setFlag(MinecraftConstants.PROFILE_KEY, this.profile);
session.setFlag(MinecraftConstants.ACCESS_TOKEN_KEY, this.accessToken);
diff --git a/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java b/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java
index 512447b1..7110e9e0 100644
--- a/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java
+++ b/src/test/java/com/github/steveice10/mc/protocol/MinecraftProtocolTest.java
@@ -14,14 +14,14 @@ import com.github.steveice10.opennbt.tag.builtin.FloatTag;
import com.github.steveice10.opennbt.tag.builtin.IntTag;
import com.github.steveice10.opennbt.tag.builtin.ListTag;
import com.github.steveice10.opennbt.tag.builtin.StringTag;
-import com.github.steveice10.packetlib.Client;
import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.DisconnectedEvent;
import com.github.steveice10.packetlib.event.session.PacketReceivedEvent;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
-import com.github.steveice10.packetlib.tcp.TcpSessionFactory;
+import com.github.steveice10.packetlib.tcp.TcpClientSession;
+import com.github.steveice10.packetlib.tcp.TcpServer;
import net.kyori.adventure.text.Component;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@@ -34,7 +34,6 @@ import static com.github.steveice10.mc.protocol.MinecraftConstants.SERVER_INFO_B
import static com.github.steveice10.mc.protocol.MinecraftConstants.SERVER_INFO_HANDLER_KEY;
import static com.github.steveice10.mc.protocol.MinecraftConstants.SERVER_LOGIN_HANDLER_KEY;
import static com.github.steveice10.mc.protocol.MinecraftConstants.VERIFY_USERS_KEY;
-import static com.github.steveice10.mc.protocol.data.SubProtocol.STATUS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -56,7 +55,7 @@ public class MinecraftProtocolTest {
@BeforeClass
public static void setupServer() {
- server = new Server(HOST, PORT, MinecraftProtocol.class, new TcpSessionFactory());
+ server = new TcpServer(HOST, PORT, MinecraftProtocol.class);
server.setGlobalFlag(VERIFY_USERS_KEY, false);
server.setGlobalFlag(SERVER_COMPRESSION_THRESHOLD, 100);
server.setGlobalFlag(SERVER_INFO_BUILDER_KEY, (ServerInfoBuilder) session -> SERVER_INFO);
@@ -75,10 +74,8 @@ public class MinecraftProtocolTest {
@Test
public void testStatus() throws InterruptedException {
- Client client = new Client(HOST, PORT, new MinecraftProtocol(STATUS), new TcpSessionFactory());
+ Session session = new TcpClientSession(HOST, PORT, new MinecraftProtocol());
try {
- Session session = client.getSession();
-
ServerInfoHandlerTest handler = new ServerInfoHandlerTest();
session.setFlag(SERVER_INFO_HANDLER_KEY, handler);
session.addListener(new DisconnectListener());
@@ -88,16 +85,14 @@ public class MinecraftProtocolTest {
assertNotNull("Failed to get server info.", handler.info);
assertEquals("Received incorrect server info.", SERVER_INFO, handler.info);
} finally {
- client.getSession().disconnect("Status test complete.");
+ session.disconnect("Status test complete.");
}
}
@Test
public void testLogin() throws InterruptedException {
- Client client = new Client(HOST, PORT, new MinecraftProtocol("Username"), new TcpSessionFactory());
+ Session session = new TcpClientSession(HOST, PORT, new MinecraftProtocol("Username"));
try {
- Session session = client.getSession();
-
LoginListenerTest listener = new LoginListenerTest();
session.addListener(listener);
session.addListener(new DisconnectListener());
@@ -107,7 +102,7 @@ public class MinecraftProtocolTest {
assertNotNull("Failed to log in.", listener.packet);
assertEquals("Received incorrect join packet.", JOIN_GAME_PACKET, listener.packet);
} finally {
- client.getSession().disconnect("Login test complete.");
+ session.disconnect("Login test complete.");
}
}