|
| 1 | +package net.hypixel.modapi.packet; |
| 2 | + |
| 3 | +import net.hypixel.modapi.packet.impl.clientbound.ClientboundLocationPacket; |
| 4 | +import net.hypixel.modapi.packet.impl.clientbound.ClientboundPartyInfoPacket; |
| 5 | +import net.hypixel.modapi.packet.impl.clientbound.ClientboundPingPacket; |
| 6 | +import net.hypixel.modapi.serializer.PacketSerializer; |
| 7 | +import org.jetbrains.annotations.Nullable; |
| 8 | + |
| 9 | +import java.util.Arrays; |
| 10 | +import java.util.HashMap; |
| 11 | +import java.util.Map; |
| 12 | +import java.util.function.Function; |
| 13 | + |
| 14 | +public enum HypixelPacketType { |
| 15 | + PING(ClientboundPingPacket::new), |
| 16 | + LOCATION(ClientboundLocationPacket::new), |
| 17 | + PARTY_INFO(ClientboundPartyInfoPacket::new), |
| 18 | + ; |
| 19 | + private static final String IDENTIFIER_PREFIX = "hypixel:"; |
| 20 | + private static final Map<String, HypixelPacketType> BY_IDENTIFIER = Arrays.stream(values()).collect(HashMap::new, (map, type) -> map.put(type.getIdentifier(), type), HashMap::putAll); |
| 21 | + private final Function<PacketSerializer, HypixelPacket> packetFactory; |
| 22 | + |
| 23 | + @Nullable |
| 24 | + public static HypixelPacketType getByIdentifier(String identifier) { |
| 25 | + return BY_IDENTIFIER.get(identifier); |
| 26 | + } |
| 27 | + |
| 28 | + private final String identifier; |
| 29 | + |
| 30 | + HypixelPacketType(Function<PacketSerializer, HypixelPacket> packetFactory) { |
| 31 | + this.identifier = IDENTIFIER_PREFIX + name().toLowerCase(); |
| 32 | + this.packetFactory = packetFactory; |
| 33 | + } |
| 34 | + |
| 35 | + public String getIdentifier() { |
| 36 | + return identifier; |
| 37 | + } |
| 38 | + |
| 39 | + public Function<PacketSerializer, HypixelPacket> getPacketFactory() { |
| 40 | + return packetFactory; |
| 41 | + } |
| 42 | +} |
0 commit comments