diff --git a/protocol-new/src/main/java/mc/protocol/State.java b/protocol-new/src/main/java/mc/protocol/State.java new file mode 100644 index 0000000..cdb8c94 --- /dev/null +++ b/protocol-new/src/main/java/mc/protocol/State.java @@ -0,0 +1,68 @@ +package mc.protocol; + +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import mc.protocol.packets.ClientSidePacket; +import mc.protocol.packets.ServerSidePacket; + +import javax.annotation.Nullable; +import java.util.Collections; +import java.util.Map; + +@RequiredArgsConstructor +public enum State { + + HANDSHAKING(0, + // client side + Collections.emptyMap(), + // server side + Collections.emptyMap() + ), + + STATUS(1, + // client side + Collections.emptyMap(), + // server side + Collections.emptyMap() + ), + + LOGIN(2, + // client side + Collections.emptyMap(), + // server side + Collections.emptyMap() + ), + + PLAY(3, + // client side + Collections.emptyMap(), + // server side + Collections.emptyMap() + ); + + public static State getById(int id) { + // а зачем усложнять? + //@formatter:off + if (id == 1) return STATUS; + else if (id == 2) return LOGIN; + else if (id == 3) return PLAY; + else return HANDSHAKING; + //@formatter:on + } + + @Getter + private final int id; + + private final Map> clientSidePackets; + private final Map, Integer> serverSidePackets; + + @Nullable + public Class getClientSidePacketById(int id) { + return clientSidePackets == null ? null : clientSidePackets.get(id); + } + + @Nullable + public Integer getServerSidePacketId(Class clazz) { + return serverSidePackets == null ? null : serverSidePackets.get(clazz); + } +}