mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-30 20:11:26 +01:00
Cleanup
This commit is contained in:
parent
c6c8f6b9d6
commit
68bb479f4a
@ -70,7 +70,7 @@ import java.util.Collection;
|
||||
* The server needs to be initialized with {@link #init()} and started with {@link #start(String, int)}.
|
||||
* You should register all of your dimensions, biomes, commands, events, etc... in-between.
|
||||
*/
|
||||
public class MinecraftServer {
|
||||
public final class MinecraftServer {
|
||||
|
||||
@Getter
|
||||
private final static Logger LOGGER = LoggerFactory.getLogger(MinecraftServer.class);
|
||||
@ -289,7 +289,7 @@ public class MinecraftServer {
|
||||
// The difficulty packet
|
||||
ServerDifficultyPacket serverDifficultyPacket = new ServerDifficultyPacket();
|
||||
serverDifficultyPacket.difficulty = difficulty;
|
||||
serverDifficultyPacket.locked = true; // Can only be modified on singleplayer
|
||||
serverDifficultyPacket.locked = true; // Can only be modified on single-player
|
||||
// Send the packet to all online players
|
||||
PacketWriterUtils.writeAndSend(connectionManager.getOnlinePlayers(), serverDifficultyPacket);
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package net.minestom.server.extras;
|
||||
import lombok.Getter;
|
||||
import net.minestom.server.MinecraftServer;
|
||||
|
||||
public class MojangAuth {
|
||||
public final class MojangAuth {
|
||||
|
||||
@Getter
|
||||
private static boolean usingMojangAuth = false;
|
||||
|
@ -7,7 +7,7 @@ import net.minestom.server.instance.block.rule.vanilla.AxisPlacementRule;
|
||||
import net.minestom.server.instance.block.rule.vanilla.RedstonePlacementRule;
|
||||
import net.minestom.server.instance.block.rule.vanilla.WallPlacementRule;
|
||||
|
||||
public class PlacementRules {
|
||||
public final class PlacementRules {
|
||||
|
||||
public static void init() {
|
||||
BlockManager blockManager = MinecraftServer.getBlockManager();
|
||||
|
@ -10,7 +10,7 @@ import javax.crypto.spec.SecretKeySpec;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.*;
|
||||
|
||||
public class MojangCrypt {
|
||||
public final class MojangCrypt {
|
||||
private static final Logger LOGGER = LogManager.getLogger();
|
||||
|
||||
@Nullable
|
||||
|
@ -14,31 +14,28 @@ import net.minestom.server.network.packet.client.handshake.HandshakePacket;
|
||||
import net.minestom.server.network.player.NettyPlayerConnection;
|
||||
import net.minestom.server.network.player.PlayerConnection;
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
public class PacketProcessor {
|
||||
public final class PacketProcessor {
|
||||
|
||||
private final Map<ChannelHandlerContext, PlayerConnection> connectionPlayerConnectionMap = new ConcurrentHashMap<>();
|
||||
|
||||
// Protocols
|
||||
// Protocols state
|
||||
private final ClientStatusPacketsHandler statusPacketsHandler;
|
||||
private final ClientLoginPacketsHandler loginPacketsHandler;
|
||||
private final ClientPlayPacketsHandler playPacketsHandler;
|
||||
|
||||
public PacketProcessor() {
|
||||
|
||||
this.statusPacketsHandler = new ClientStatusPacketsHandler();
|
||||
this.loginPacketsHandler = new ClientLoginPacketsHandler();
|
||||
this.playPacketsHandler = new ClientPlayPacketsHandler();
|
||||
}
|
||||
|
||||
private List<Integer> printBlackList = Arrays.asList(17, 18, 19);
|
||||
|
||||
public void process(ChannelHandlerContext channel, InboundPacket packet) {
|
||||
// Create the netty player connection object if not existing
|
||||
PlayerConnection playerConnection = connectionPlayerConnectionMap.computeIfAbsent(
|
||||
channel, c -> new NettyPlayerConnection((SocketChannel) channel.channel())
|
||||
);
|
||||
@ -48,10 +45,6 @@ public class PacketProcessor {
|
||||
|
||||
final ConnectionState connectionState = playerConnection.getConnectionState();
|
||||
|
||||
//if (!printBlackList.contains(id)) {
|
||||
//System.out.println("RECEIVED ID: 0x" + Integer.toHexString(id) + " State: " + connectionState);
|
||||
//}
|
||||
|
||||
BinaryReader binaryReader = new BinaryReader(packet.body);
|
||||
|
||||
if (connectionState == ConnectionState.UNKNOWN) {
|
||||
@ -84,6 +77,13 @@ public class PacketProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a player connection from its channel.
|
||||
*
|
||||
* @param channel the connection channel
|
||||
* @return the connection of this channel, null if not found
|
||||
*/
|
||||
@Nullable
|
||||
public PlayerConnection getPlayerConnection(ChannelHandlerContext channel) {
|
||||
return connectionPlayerConnectionMap.get(channel);
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package net.minestom.server.network.packet.client;
|
||||
|
||||
import net.minestom.server.utils.binary.BinaryReader;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import net.minestom.server.utils.binary.Readable;
|
||||
|
||||
public interface ClientPacket {
|
||||
|
||||
void read(@NotNull BinaryReader reader);
|
||||
/**
|
||||
* Represents a packet received from a client.
|
||||
*/
|
||||
public interface ClientPacket extends Readable {
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,7 @@
|
||||
package net.minestom.server.network.packet.client.handler;
|
||||
|
||||
import net.minestom.server.network.packet.client.ClientPacket;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@ -9,17 +10,30 @@ public class ClientPacketsHandler {
|
||||
// Max packet id
|
||||
private static final int SIZE = 0x30;
|
||||
|
||||
private final Supplier<ClientPacket>[] supplierAccesses = new Supplier[SIZE];
|
||||
private final ClientPacketSupplier[] supplierAccesses = new ClientPacketSupplier[SIZE];
|
||||
|
||||
public void register(int id, Supplier<ClientPacket> packetSupplier) {
|
||||
supplierAccesses[id] = packetSupplier;
|
||||
/**
|
||||
* Registers a client packet which can be retrieved later using {@link #getPacketInstance(int)}.
|
||||
*
|
||||
* @param id the packet id
|
||||
* @param packetSupplier the supplier of the packet
|
||||
*/
|
||||
public void register(int id, @NotNull ClientPacketSupplier packetSupplier) {
|
||||
this.supplierAccesses[id] = packetSupplier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves a {@link net.minestom.server.network.packet.client.ClientPlayPacket} from its id.
|
||||
*
|
||||
* @param id the packet id
|
||||
* @return the associated client packet
|
||||
* @throws IllegalStateException if {@code id} is not a valid packet id, or unregistered
|
||||
*/
|
||||
public ClientPacket getPacketInstance(int id) {
|
||||
if (id > SIZE)
|
||||
throw new IllegalStateException("Packet ID 0x" + Integer.toHexString(id) + " has been tried to be parsed, debug needed");
|
||||
|
||||
Supplier<ClientPacket> supplier = supplierAccesses[id];
|
||||
ClientPacketSupplier supplier = supplierAccesses[id];
|
||||
if (supplierAccesses[id] == null)
|
||||
throw new IllegalStateException("Packet id 0x" + Integer.toHexString(id) + " isn't registered!");
|
||||
|
||||
@ -28,4 +42,10 @@ public class ClientPacketsHandler {
|
||||
return supplier.get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenient interface to supply a {@link ClientPacket}.
|
||||
*/
|
||||
protected interface ClientPacketSupplier extends Supplier<ClientPacket> {
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ public class LoginStartPacket implements ClientPreplayPacket {
|
||||
final int messageId = ThreadLocalRandom.current().nextInt();
|
||||
final String channel = VelocityProxy.PLAYER_INFO_CHANNEL;
|
||||
|
||||
// Important to retrieve the channel in the response packet
|
||||
// Important in order to retrieve the channel in the response packet
|
||||
nettyPlayerConnection.addPluginRequestEntry(messageId, channel);
|
||||
|
||||
LoginPluginRequestPacket loginPluginRequestPacket = new LoginPluginRequestPacket();
|
||||
|
@ -43,7 +43,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
private String serverAddress;
|
||||
private int serverPort;
|
||||
|
||||
// Used for the login plugin request packet, to retrive the channel from a message id,
|
||||
// Used for the login plugin request packet, to retrieve the channel from a message id,
|
||||
// cleared once the player enters the play state
|
||||
private Map<Integer, String> pluginRequestMap = new ConcurrentHashMap<>();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user