mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-29 19:41:47 +01:00
Added MinecraftServer#getPacketProcessor and allow to override client packet and instantiate packet instance from an id
This commit is contained in:
parent
a1fd711b85
commit
6586ca39bc
@ -114,6 +114,7 @@ public final class MinecraftServer {
|
||||
private static int maxPacketSize = 30_000;
|
||||
// Network
|
||||
private static PacketListenerManager packetListenerManager;
|
||||
private static PacketProcessor packetProcessor;
|
||||
private static NettyServer nettyServer;
|
||||
|
||||
// In-Game Manager
|
||||
@ -181,7 +182,7 @@ public final class MinecraftServer {
|
||||
|
||||
connectionManager = new ConnectionManager();
|
||||
// Networking
|
||||
final PacketProcessor packetProcessor = new PacketProcessor();
|
||||
packetProcessor = new PacketProcessor();
|
||||
packetListenerManager = new PacketListenerManager();
|
||||
|
||||
instanceManager = new InstanceManager();
|
||||
@ -434,6 +435,18 @@ public final class MinecraftServer {
|
||||
return connectionManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the object handling the client packets processing.
|
||||
* <p>
|
||||
* Can be used if you want to convert a buffer to a client packet object.
|
||||
*
|
||||
* @return the packet processor
|
||||
*/
|
||||
public static PacketProcessor getPacketProcessor() {
|
||||
checkInitStatus(packetProcessor);
|
||||
return packetProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if the server is up and running.
|
||||
*
|
||||
|
@ -23,6 +23,16 @@ import org.slf4j.LoggerFactory;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* Responsible for processing client packets.
|
||||
* <p>
|
||||
* You can retrieve the different packet handlers per state (status/login/play)
|
||||
* from the {@link net.minestom.server.network.packet.client.handler.ClientPacketsHandler} class.
|
||||
* <p>
|
||||
* Packet handlers are cached here and can be retrieved with {@link #getStatusPacketsHandler()}, {@link #getLoginPacketsHandler()}
|
||||
* and {@link #getPlayPacketsHandler()}. The one to use depend on the type of packet you need to retrieve (the packet id 0 does not have
|
||||
* the same meaning as it is a login or play packet).
|
||||
*/
|
||||
public final class PacketProcessor {
|
||||
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(PacketProcessor.class);
|
||||
@ -94,10 +104,22 @@ public final class PacketProcessor {
|
||||
return connectionPlayerConnectionMap.get(channel);
|
||||
}
|
||||
|
||||
public void removePlayerConnection(ChannelHandlerContext channel) {
|
||||
public void removePlayerConnection(@NotNull ChannelHandlerContext channel) {
|
||||
connectionPlayerConnectionMap.remove(channel);
|
||||
}
|
||||
|
||||
public ClientStatusPacketsHandler getStatusPacketsHandler() {
|
||||
return statusPacketsHandler;
|
||||
}
|
||||
|
||||
public ClientLoginPacketsHandler getLoginPacketsHandler() {
|
||||
return loginPacketsHandler;
|
||||
}
|
||||
|
||||
public ClientPlayPacketsHandler getPlayPacketsHandler() {
|
||||
return playPacketsHandler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls {@link Readable#read(BinaryReader)} and catch all the exceptions to be printed using the packet processor logger.
|
||||
*
|
||||
|
@ -1,10 +1,19 @@
|
||||
package net.minestom.server.network.packet.client.handler;
|
||||
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Contains registered packets and a way to instantiate them.
|
||||
* <p>
|
||||
* Packets are register using {@link #register(int, ClientPacketSupplier)}
|
||||
* (you can override a packet id even if not recommended and not officially supported) and retrieved with {@link #getPacketInstance(int)}.
|
||||
* <p>
|
||||
* If you want to fill the packet from a buffer, consider using {@link ClientPacket#read(BinaryReader)} after getting the packet instance.
|
||||
*/
|
||||
public class ClientPacketsHandler {
|
||||
|
||||
// Max packet id
|
||||
|
Loading…
Reference in New Issue
Block a user