Skip to content

Commit 9695afc

Browse files
committed
improvement: Add methods to expose clientbound and serverbound identifiers
1 parent 7159410 commit 9695afc

File tree

1 file changed

+31
-4
lines changed

1 file changed

+31
-4
lines changed

src/main/java/net/hypixel/modapi/packet/PacketRegistry.java

+31-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Set;
99
import java.util.concurrent.ConcurrentHashMap;
1010
import java.util.function.Function;
11+
import java.util.stream.Collectors;
1112

1213
public 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

Comments
 (0)