88import java .util .Set ;
99import java .util .concurrent .ConcurrentHashMap ;
1010import java .util .function .Function ;
11+ import java .util .stream .Collectors ;
1112
1213public class PacketRegistry {
1314
@@ -43,10 +44,6 @@ Collection<Registration> getRegistrations() {
4344 return registrations .values ();
4445 }
4546
46- public boolean isRegistered (String identifier ) {
47- return registrations .containsKey (identifier );
48- }
49-
5047 public ClientboundHypixelPacket createClientboundPacket (String identifier , PacketSerializer serializer ) {
5148 return getRegistration (identifier ).clientPacketFactory .apply (serializer );
5249 }
@@ -55,14 +52,44 @@ public HypixelPacket createServerboundPacket(String identifier, PacketSerializer
5552 return getRegistration (identifier ).serverPacketFactory .apply (serializer );
5653 }
5754
55+ /**
56+ * @return whether a packet with the given identifier is registered, either for clientbound or serverbound
57+ */
58+ public boolean isRegistered (String identifier ) {
59+ return registrations .containsKey (identifier );
60+ }
61+
5862 public String getIdentifier (Class <? extends HypixelPacket > clazz ) {
5963 return classToIdentifier .get (clazz );
6064 }
6165
66+ /**
67+ * @return all registered packet identifiers, this will include both clientbound and serverbound packets
68+ */
6269 public Set <String > getIdentifiers () {
6370 return Collections .unmodifiableSet (registrations .keySet ());
6471 }
6572
73+ /**
74+ * @return all registered clientbound packet identifiers
75+ */
76+ public Set <String > getClientboundIdentifiers () {
77+ return Collections .unmodifiableSet (registrations .values ().stream ()
78+ .filter (registration -> registration .getClientboundClazz () != null )
79+ .map (registration -> classToIdentifier .get (registration .getClientboundClazz ()))
80+ .collect (Collectors .toSet ()));
81+ }
82+
83+ /**
84+ * @return all registered serverbound packet identifiers
85+ */
86+ public Set <String > getServerboundIdentifiers () {
87+ return Collections .unmodifiableSet (registrations .values ().stream ()
88+ .filter (registration -> registration .getServerboundClazz () != null )
89+ .map (registration -> classToIdentifier .get (registration .getServerboundClazz ()))
90+ .collect (Collectors .toSet ()));
91+ }
92+
6693 public static final class RegistrationBuilder {
6794 private final PacketRegistry registry ;
6895 private final String identifier ;
0 commit comments