Skip to content

Commit 030aba9

Browse files
committed
feat: Allow overriding stream codec registrations without throwing, to avoid conflicts with older versions of Shogi and because it's counterproductive to be overly protective here
1 parent 06ec636 commit 030aba9

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

shogi-api/src/main/java/net/blay09/mods/shogi/network/ShogiStreamCodecs.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,18 @@ private static Identifier id(String path) {
8585
* @param type runtime class handled by the codec
8686
* @param codec codec used for encoding/decoding payload values
8787
* @param <T> payload type
88-
* @throws IllegalArgumentException if the class or identifier was already registered
8988
*/
9089
public static synchronized <T> void register(Identifier typeId, Class<? super T> type, StreamCodec<RegistryFriendlyByteBuf, T> codec) {
91-
if (byClass.containsKey(type)) {
92-
throw new IllegalArgumentException("A synced payload codec is already registered for class " + type.getName());
90+
final var existingByClass = byClass.remove(type);
91+
if (existingByClass != null) {
92+
logger.warn("Overriding synced payload codec registration for class {}", type.getName());
93+
byIdentifier.remove(existingByClass.id());
9394
}
94-
if (byIdentifier.containsKey(typeId)) {
95-
throw new IllegalArgumentException("A synced payload codec is already registered for identifier " + typeId);
95+
96+
final var existingByIdentifier = byIdentifier.remove(typeId);
97+
if (existingByIdentifier != null) {
98+
logger.warn("Overriding synced payload codec registration for identifier '{}'", typeId);
99+
byClass.remove(existingByIdentifier.type());
96100
}
97101

98102
@SuppressWarnings("unchecked")

0 commit comments

Comments
 (0)