8
8
import java .util .Set ;
9
9
import java .util .concurrent .ConcurrentHashMap ;
10
10
import java .util .function .Function ;
11
+ import java .util .stream .Collectors ;
11
12
12
13
public class PacketRegistry {
13
14
@@ -43,10 +44,6 @@ Collection<Registration> getRegistrations() {
43
44
return registrations .values ();
44
45
}
45
46
46
- public boolean isRegistered (String identifier ) {
47
- return registrations .containsKey (identifier );
48
- }
49
-
50
47
public ClientboundHypixelPacket createClientboundPacket (String identifier , PacketSerializer serializer ) {
51
48
return getRegistration (identifier ).clientPacketFactory .apply (serializer );
52
49
}
@@ -55,14 +52,44 @@ public HypixelPacket createServerboundPacket(String identifier, PacketSerializer
55
52
return getRegistration (identifier ).serverPacketFactory .apply (serializer );
56
53
}
57
54
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
+
58
62
public String getIdentifier (Class <? extends HypixelPacket > clazz ) {
59
63
return classToIdentifier .get (clazz );
60
64
}
61
65
66
+ /**
67
+ * @return all registered packet identifiers, this will include both clientbound and serverbound packets
68
+ */
62
69
public Set <String > getIdentifiers () {
63
70
return Collections .unmodifiableSet (registrations .keySet ());
64
71
}
65
72
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
+
66
93
public static final class RegistrationBuilder {
67
94
private final PacketRegistry registry ;
68
95
private final String identifier ;
0 commit comments