Skip to content

Commit 3bfdc3d

Browse files
Merge pull request #8 from OneLiteFeatherNET/feature/connectionUpdate
Improve useability of the TestConnection
2 parents dfae6bb + be858ba commit 3bfdc3d

4 files changed

Lines changed: 39 additions & 30 deletions

File tree

build.gradle.kts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@ plugins {
22
java
33
`java-library`
44
`maven-publish`
5-
jacoco
65
}
76

87
group = "net.onelitefeather"
9-
version = "0.1.1"
8+
version = "0.2.0"
109

1110
java {
1211
toolchain {
@@ -25,20 +24,6 @@ tasks {
2524
options.encoding = "UTF-8"
2625
options.release.set(21)
2726
}
28-
29-
compileTestJava {
30-
options.encoding = "UTF-8"
31-
options.release.set(21)
32-
}
33-
34-
test {
35-
finalizedBy(jacocoTestReport)
36-
useJUnitPlatform()
37-
jvmArgs("-Dminestom.inside-test=true")
38-
testLogging {
39-
events("passed", "skipped", "failed")
40-
}
41-
}
4227
}
4328

4429
publishing {

src/main/java/net/minestom/testing/EnvImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public EnvImpl(ServerProcess process) {
2222

2323
// Use player provider to disable queued chunk sending.
2424
// Set here to allow an individual test to override if they want.
25-
process.connection().setPlayerProvider(TestConnectionImpl.TestPlayerImpl::new);
25+
process.connection().setPlayerProvider(TestPlayerImpl::new);
2626
}
2727

2828
@Override

src/main/java/net/minestom/testing/TestConnection.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,48 @@
66
import net.minestom.server.network.packet.server.ServerPacket;
77
import org.jetbrains.annotations.NotNull;
88

9+
/**
10+
* The {@link TestConnection} represents a connection from a player to a test server instance.
11+
* It provides methods to connect a player to an instance and track incoming packets.
12+
*
13+
* @version 1.0.0
14+
* @since 0.1.0
15+
*/
916
public interface TestConnection {
17+
18+
/**
19+
* Connects a player to the given instance at the specified position.
20+
*
21+
* @param instance the instance to connect to
22+
* @param pos the position to connect at
23+
* @return the connected player
24+
*/
1025
@NotNull Player connect(@NotNull Instance instance, @NotNull Pos pos);
1126

27+
/**
28+
* Connects a player to the given instance at the default position (0, 0, 0).
29+
*
30+
* @param instance the instance to connect to
31+
* @return the connected player
32+
*/
33+
default @NotNull Player connect(@NotNull Instance instance) {
34+
return connect(instance, Pos.ZERO);
35+
}
36+
37+
/**
38+
* Tracks incoming packets of the specified type.
39+
*
40+
* @param type the class of the packet type to track
41+
* @param <T> the type of the packet
42+
* @return a collector for the specified packet type
43+
*/
1244
<T extends ServerPacket> @NotNull Collector<T> trackIncoming(@NotNull Class<T> type);
1345

46+
/**
47+
* Tracks incoming packets of the default type {@link ServerPacket}.
48+
*
49+
* @return a collector for the default packet type
50+
*/
1451
default @NotNull Collector<ServerPacket> trackIncoming() {
1552
return trackIncoming(ServerPacket.class);
1653
}

src/main/java/net/minestom/testing/TestConnectionImpl.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import net.minestom.server.coordinate.Pos;
77
import net.minestom.server.entity.Player;
88
import net.minestom.server.event.player.AsyncPlayerConfigurationEvent;
9-
import net.minestom.server.instance.Chunk;
109
import net.minestom.server.instance.Instance;
1110
import net.minestom.server.network.ConnectionState;
1211
import net.minestom.server.network.packet.server.SendablePacket;
@@ -130,16 +129,4 @@ public IncomingCollector(Class<T> type) {
130129
return List.copyOf(packets);
131130
}
132131
}
133-
134-
static final class TestPlayerImpl extends Player {
135-
public TestPlayerImpl(@NotNull PlayerConnection playerConnection, @NotNull GameProfile gameProfile) {
136-
super(playerConnection, gameProfile);
137-
}
138-
139-
@Override
140-
public void sendChunk(@NotNull Chunk chunk) {
141-
// Send immediately
142-
sendPacket(chunk.getFullDataPacket());
143-
}
144-
}
145132
}

0 commit comments

Comments
 (0)