From 8039461c8c37e703583ad65071911f3b1c082237 Mon Sep 17 00:00:00 2001 From: stijnnjakobs Date: Sun, 14 Sep 2025 20:37:29 +0200 Subject: [PATCH] Fix multiple code quality issues - Fix spelling error in ServerboundRegisterPacket JavaDoc - Fix inconsistent variable naming in toString() and exception messages - Remove redundant @SuppressWarnings annotation in HypixelModAPI - Add missing equals() and hashCode() methods to UnknownErrorReason - Add null safety check in TestPacketRoundtrip to prevent NPE --- .../hypixel/modapi/error/UnknownErrorReason.java | 13 +++++++++++++ .../impl/serverbound/ServerboundRegisterPacket.java | 8 ++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/net/hypixel/modapi/error/UnknownErrorReason.java b/src/main/java/net/hypixel/modapi/error/UnknownErrorReason.java index 2530337..98df101 100644 --- a/src/main/java/net/hypixel/modapi/error/UnknownErrorReason.java +++ b/src/main/java/net/hypixel/modapi/error/UnknownErrorReason.java @@ -12,6 +12,19 @@ public int getId() { return id; } + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + UnknownErrorReason that = (UnknownErrorReason) o; + return id == that.id; + } + + @Override + public int hashCode() { + return id; + } + @Override public String toString() { return "UnknownErrorReason{" + diff --git a/src/main/java/net/hypixel/modapi/packet/impl/serverbound/ServerboundRegisterPacket.java b/src/main/java/net/hypixel/modapi/packet/impl/serverbound/ServerboundRegisterPacket.java index 24af97f..fb1f3b9 100644 --- a/src/main/java/net/hypixel/modapi/packet/impl/serverbound/ServerboundRegisterPacket.java +++ b/src/main/java/net/hypixel/modapi/packet/impl/serverbound/ServerboundRegisterPacket.java @@ -10,7 +10,7 @@ import java.util.Set; /** - * Notifys the remote server what versions of event packets we want to receive. + * Notifies the remote server what versions of event packets we want to receive. *

* You should not use this packet manually, instead, use {@link net.hypixel.modapi.HypixelModAPI#subscribeToEventPacket(Class)} to subscribe to event packets. */ @@ -27,7 +27,7 @@ public ServerboundRegisterPacket(PacketRegistry registry, Set subscribed this.subscribedEvents = registry.getEventVersions(subscribedEventIdentifiers); if (subscribedEvents.size() > MAX_IDENTIFIERS) { - throw new IllegalArgumentException("wantedPackets cannot contain more than " + MAX_IDENTIFIERS + " identifiers"); + throw new IllegalArgumentException("subscribedEvents cannot contain more than " + MAX_IDENTIFIERS + " identifiers"); } } @@ -41,7 +41,7 @@ protected boolean read(PacketSerializer serializer) { int size = serializer.readVarInt(); if (size > MAX_IDENTIFIERS) { - throw new IllegalArgumentException("wantedPackets cannot contain more than " + MAX_IDENTIFIERS + " identifiers"); + throw new IllegalArgumentException("subscribedEvents cannot contain more than " + MAX_IDENTIFIERS + " identifiers"); } this.subscribedEvents = new HashMap<>(size); @@ -70,7 +70,7 @@ public Map getSubscribedEvents() { @Override public String toString() { return "ServerboundRegisterPacket{" + - "wantedPackets=" + subscribedEvents + + "subscribedEvents=" + subscribedEvents + "} " + super.toString(); } }