开源软件名称(OpenSource Name):CloudburstMC/Protocol开源软件地址(OpenSource Url):https://github.com/CloudburstMC/Protocol开源编程语言(OpenSource Language):Java 100.0%开源软件介绍(OpenSource Introduction):ProtocolIntroductionA protocol library for Minecraft that supports multiple versions. (Currently Bedrock Edition only) LinksUsageClientCreating a client// This is the local address to bind to, not the remote one.
// If bound to 127.0.0.1 any incoming packets from outside your computer will not be received.
InetSocketAddress bindAddress = new InetSocketAddress("0.0.0.0", 12345);
BedrockClient client = new BedrockClient(bindAddress);
// Bind the port
client.bind().join(); Pinging a Remote ServerThis can be done whilst the client is connected to a server however it cannot be to the connected server. InetSocketAddress addressToPing = new InetSocketAddress("play.nukkitx.com", 19132);
client.ping(addressToPing).whenComplete((pong, throwable) -> {
if (throwable != null) {
// Error occurred or timeout
return;
}
// Pong received.
}).join(); // Join if you do not want this to be handled asynchronously. Connecting to a Remote ServerA InetSocketAddress addressToConnect = new InetSocketAddress("play.nukkitx.com", 19132);
client.connect(addressToConnect).whenComplete((session, throwable) -> {
if (throwable != null) {
// Unable to establish connection
return;
}
// Connection established
// Make sure to set the packet codec version you wish to use before sending out packets
session.setPacketCodec(Bedrock_v389.V389_CODEC);
// Add disconnect handler
session.addDisconnectHandler((reason) -> System.out.println("Disconnected"));
// Remember to set a packet handler so you receive incoming packets
session.setPacketHandler(new FooBarPacketHandler());
// Now send packets...
}).join(); // Join if you do not want this to be handled asynchronously. ServerCreating a ServerInetSocketAddress bindAddress = new InetSocketAddress("0.0.0.0", 19132);
BedrockServer server = new BedrockServer(bindAddress);
BedrockPong pong = new BedrockPong();
pong.setEdition("MCPE");
pong.setMotd("My Server");
pong.setPlayerCount(0);
pong.setMaximumPlayerCount(20);
pong.setGameType("Survival");
pong.setProtocolVersion(Bedrock_v389.V389_CODEC.getProtocolVersion());
server.setHandler(new BedrockServerEventHandler() {
@Override
public boolean onConnectionRequest(InetSocketAddress address) {
return true; // Connection will be accepted
}
@Override
public BedrockPong onQuery(InetSocketAddress address) {
return pong;
}
@Override
public void onSessionCreation(BedrockServerSession serverSession) {
// Connection established
// Add disconnect handler
session.addDisconnectHandler((reason) -> System.out.println("Disconnected"));
// Remember to set a packet handler so you receive incoming packets
session.setPacketHandler(new FooBarPacketHandler());
// By default, the server will use a compatible codec that will read any LoginPacket.
// After receiving the LoginPacket, you need to set the correct packet codec for the client and continue.
}
});
// Start server up
server.bind().join(); MavenProtocol Versions:
Repository: <repositories>
<repository>
<id>nukkitx-repo-release</id>
<url>https://repo.nukkitx.com/maven-releases/</url>
</repository>
<repository>
<id>nukkitx-repo-snapshot</id>
<url>https://repo.nukkitx.com/maven-snapshots/</url>
</repository>
</repositories> Dependencies: <dependencies>
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v(VERSION)</artifactId>
<version>2.9.11-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies> Projects Using This Library
If you would like to add your project here, please create a pull request. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论