Skip to content

Commit 785bf9b

Browse files
committed
fix: getting packet by class
1 parent 90ab96e commit 785bf9b

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

bridge-common/src/main/java/com/luminiadev/bridge/network/codec/BridgeCodec.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public static Builder builder() {
6161
public <T extends BridgePacket> void registerPacket(BridgePacketDefinition<T> definition) {
6262
if (!packetsById.containsKey(definition.getId())) {
6363
packetsById.put(definition.getId(), definition);
64-
packetsByClass.put(definition.getFactory().getClass(), definition);
64+
packetsByClass.put(definition.getFactory().getPacketClass(), definition);
6565
} else {
6666
throw new BridgeCodecException("Packet with id " + definition.getId() + " is already registered");
6767
}

bridge-common/src/main/java/com/luminiadev/bridge/network/codec/packet/BridgePacketFactory.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,14 @@ public interface BridgePacketFactory<T extends BridgePacket> {
1414
* @return A new bridge packet instance
1515
*/
1616
T create();
17+
18+
/**
19+
* Gets the class of the packet.
20+
*
21+
* @return Class<T>
22+
*/
23+
@SuppressWarnings("unchecked")
24+
default Class<T> getPacketClass() {
25+
return (Class<T>) this.create().getClass();
26+
}
1727
}

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ java {
1111

1212
allprojects {
1313
group = "com.luminia"
14-
version = "1.0.5-SNAPSHOT"
14+
version = "1.0.6-SNAPSHOT"
1515
}
1616

1717
subprojects {

0 commit comments

Comments
 (0)