Skip to content

Commit aac42d9

Browse files
Annotate internal methods as so, remove custom Experimental annotation (#35)
1 parent f90de4c commit aac42d9

18 files changed

+70
-26
lines changed

src/main/java/net/hypixel/modapi/HypixelModAPI.java

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPlayerInfoPacket;
1515
import net.hypixel.modapi.packet.impl.serverbound.ServerboundRegisterPacket;
1616
import net.hypixel.modapi.serializer.PacketSerializer;
17+
import org.jetbrains.annotations.ApiStatus;
1718

1819
import java.util.*;
1920
import java.util.concurrent.ConcurrentHashMap;
@@ -74,21 +75,6 @@ private void registerDefaultHandler() {
7475
registerHandler(ClientboundHelloPacket.class, p -> sendRegisterPacket(true));
7576
}
7677

77-
public PacketRegistry getRegistry() {
78-
return registry;
79-
}
80-
81-
public <T extends ClientboundHypixelPacket> void registerHandler(Class<T> packetClass, ClientboundPacketHandler<T> handler) {
82-
if (packetClass == null || handler == null) return;
83-
handlers.computeIfAbsent(packetClass, cls -> new CopyOnWriteArrayList<>()).add(handler);
84-
}
85-
86-
public void subscribeToEventPacket(Class<? extends EventPacket> packet) {
87-
if (subscribedEvents.add(getRegistry().getIdentifier(packet))) {
88-
sendRegisterPacket(false);
89-
}
90-
}
91-
9278
private void sendRegisterPacket(boolean alwaysSendIfNotEmpty) {
9379
if (packetSender == null) {
9480
// Allow registering events before the mod has fully initialized
@@ -100,12 +86,17 @@ private void sendRegisterPacket(boolean alwaysSendIfNotEmpty) {
10086
}
10187

10288
Set<String> lastSubscribedEvents = new HashSet<>(subscribedEvents);
103-
Map<String, Integer> versionsMap = getRegistry().getEventVersions(lastSubscribedEvents);
104-
if (sendPacket(new ServerboundRegisterPacket(versionsMap))) {
89+
if (sendPacket(new ServerboundRegisterPacket(registry, lastSubscribedEvents))) {
10590
this.lastSubscribedEvents = lastSubscribedEvents;
10691
}
10792
}
10893

94+
@ApiStatus.Internal
95+
public PacketRegistry getRegistry() {
96+
return registry;
97+
}
98+
99+
@ApiStatus.Internal
109100
public void handle(String identifier, PacketSerializer serializer) {
110101
if (handlers.isEmpty()) {
111102
return;
@@ -130,6 +121,7 @@ public void handle(String identifier, PacketSerializer serializer) {
130121
handle(packet);
131122
}
132123

124+
@ApiStatus.Internal
133125
@SuppressWarnings("unchecked")
134126
public void handle(ClientboundHypixelPacket packet) {
135127
Collection<ClientboundPacketHandler<?>> typedHandlers = handlers.get(packet.getClass());
@@ -141,13 +133,25 @@ public void handle(ClientboundHypixelPacket packet) {
141133
}
142134
}
143135

136+
@ApiStatus.Internal
144137
public void setPacketSender(Predicate<HypixelPacket> packetSender) {
145138
if (this.packetSender != null) {
146139
throw new IllegalArgumentException("Packet sender already set");
147140
}
148141
this.packetSender = packetSender;
149142
}
150143

144+
public <T extends ClientboundHypixelPacket> void registerHandler(Class<T> packetClass, ClientboundPacketHandler<T> handler) {
145+
if (packetClass == null || handler == null) return;
146+
handlers.computeIfAbsent(packetClass, cls -> new CopyOnWriteArrayList<>()).add(handler);
147+
}
148+
149+
public void subscribeToEventPacket(Class<? extends EventPacket> packet) {
150+
if (subscribedEvents.add(getRegistry().getIdentifier(packet))) {
151+
sendRegisterPacket(false);
152+
}
153+
}
154+
151155
/**
152156
* @return whether the packet was sent successfully
153157
*/

src/main/java/net/hypixel/modapi/annotation/Experimental.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

src/main/java/net/hypixel/modapi/error/ModAPIException.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package net.hypixel.modapi.error;
22

3+
import org.jetbrains.annotations.ApiStatus;
4+
35
public class ModAPIException extends RuntimeException {
46
private final String identifier;
57
private final ErrorReason reason;
68

9+
@ApiStatus.Internal
710
public ModAPIException(String identifier, ErrorReason reason) {
811
super(String.format("Received error response '%s' from packet '%s'", reason, identifier));
912
this.identifier = identifier;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22

33
import net.hypixel.modapi.HypixelModAPI;
44
import net.hypixel.modapi.serializer.PacketSerializer;
5+
import org.jetbrains.annotations.ApiStatus;
56

67
public interface HypixelPacket {
78

9+
@ApiStatus.Internal
810
void write(PacketSerializer serializer);
911

12+
@ApiStatus.Internal
1013
default String getIdentifier() {
1114
return HypixelModAPI.getInstance().getRegistry().getIdentifier(getClass());
1215
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.hypixel.modapi.packet;
22

33
import net.hypixel.modapi.serializer.PacketSerializer;
4+
import org.jetbrains.annotations.ApiStatus;
45

56
import java.util.Collection;
67
import java.util.Collections;
@@ -10,6 +11,7 @@
1011
import java.util.function.Function;
1112
import java.util.stream.Collectors;
1213

14+
@ApiStatus.Internal
1315
public class PacketRegistry {
1416

1517
private final Map<String, Registration> registrations = new ConcurrentHashMap<>();

src/main/java/net/hypixel/modapi/packet/impl/VersionedPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
import net.hypixel.modapi.packet.HypixelPacket;
44
import net.hypixel.modapi.serializer.PacketSerializer;
5+
import org.jetbrains.annotations.ApiStatus;
56

67
/**
78
* Represents a packet that is backed by a version. Versioned packets will only be handled if the incoming packet matches the version of the packet known.
89
*/
910
public abstract class VersionedPacket implements HypixelPacket {
1011
protected int version;
1112

13+
@ApiStatus.Internal
1214
public VersionedPacket(int version) {
1315
this.version = version;
1416
}
1517

18+
@ApiStatus.Internal
1619
public VersionedPacket(PacketSerializer serializer) {
1720
read(serializer);
1821
}

src/main/java/net/hypixel/modapi/packet/impl/clientbound/ClientboundHelloPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.hypixel.data.region.Environment;
44
import net.hypixel.modapi.packet.ClientboundHypixelPacket;
55
import net.hypixel.modapi.serializer.PacketSerializer;
6+
import org.jetbrains.annotations.ApiStatus;
67

78
/**
89
* This packet is automatically sent on every join to Hypixel to indicate that the client has connected to a Hypixel server.
@@ -11,10 +12,12 @@
1112
public class ClientboundHelloPacket implements ClientboundHypixelPacket {
1213
private final Environment environment;
1314

15+
@ApiStatus.Internal
1416
public ClientboundHelloPacket(Environment environment) {
1517
this.environment = environment;
1618
}
1719

20+
@ApiStatus.Internal
1821
public ClientboundHelloPacket(PacketSerializer serializer) {
1922
this.environment = Environment.getById(serializer.readVarInt()).orElseThrow(() -> new IllegalArgumentException("Invalid environment ID"));
2023

src/main/java/net/hypixel/modapi/packet/impl/clientbound/ClientboundPartyInfoPacket.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package net.hypixel.modapi.packet.impl.clientbound;
22

33
import net.hypixel.modapi.serializer.PacketSerializer;
4+
import org.jetbrains.annotations.ApiStatus;
45

56
import java.util.*;
67

@@ -10,6 +11,7 @@ public class ClientboundPartyInfoPacket extends ClientboundVersionedPacket {
1011
private boolean inParty;
1112
private Map<UUID, PartyMember> memberMap;
1213

14+
@ApiStatus.Internal
1315
public ClientboundPartyInfoPacket(int version, boolean inParty, Map<UUID, PartyMember> memberMap) {
1416
super(version);
1517
if (version > CURRENT_VERSION) {
@@ -20,6 +22,7 @@ public ClientboundPartyInfoPacket(int version, boolean inParty, Map<UUID, PartyM
2022
this.memberMap = memberMap;
2123
}
2224

25+
@ApiStatus.Internal
2326
public ClientboundPartyInfoPacket(PacketSerializer serializer) {
2427
super(serializer);
2528
}
@@ -117,11 +120,13 @@ public static class PartyMember {
117120
private final UUID uuid;
118121
private final PartyRole role;
119122

123+
@ApiStatus.Internal
120124
public PartyMember(UUID uuid, PartyRole role) {
121125
this.uuid = uuid;
122126
this.role = role;
123127
}
124128

129+
@ApiStatus.Internal
125130
PartyMember(PacketSerializer serializer) {
126131
this.uuid = serializer.readUuid();
127132
this.role = PartyRole.VALUES[serializer.readVarInt()];

src/main/java/net/hypixel/modapi/packet/impl/clientbound/ClientboundPingPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package net.hypixel.modapi.packet.impl.clientbound;
22

33
import net.hypixel.modapi.serializer.PacketSerializer;
4+
import org.jetbrains.annotations.ApiStatus;
45

56
public class ClientboundPingPacket extends ClientboundVersionedPacket {
67
private static final int CURRENT_VERSION = 1;
78

89
private String response;
910

11+
@ApiStatus.Internal
1012
public ClientboundPingPacket(String response) {
1113
super(CURRENT_VERSION);
1214
this.response = response;
1315
}
1416

17+
@ApiStatus.Internal
1518
public ClientboundPingPacket(PacketSerializer serializer) {
1619
super(serializer);
1720
}

src/main/java/net/hypixel/modapi/packet/impl/clientbound/ClientboundPlayerInfoPacket.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import net.hypixel.data.rank.PackageRank;
55
import net.hypixel.data.rank.PlayerRank;
66
import net.hypixel.modapi.serializer.PacketSerializer;
7+
import org.jetbrains.annotations.ApiStatus;
78
import org.jetbrains.annotations.Nullable;
89

910
import java.util.Optional;
@@ -17,6 +18,7 @@ public class ClientboundPlayerInfoPacket extends ClientboundVersionedPacket {
1718
@Nullable
1819
private String prefix;
1920

21+
@ApiStatus.Internal
2022
public ClientboundPlayerInfoPacket(PlayerRank playerRank, PackageRank packageRank, MonthlyPackageRank monthlyPackageRank, @Nullable String prefix) {
2123
super(CURRENT_VERSION);
2224
this.playerRank = playerRank;
@@ -25,6 +27,7 @@ public ClientboundPlayerInfoPacket(PlayerRank playerRank, PackageRank packageRan
2527
this.prefix = prefix;
2628
}
2729

30+
@ApiStatus.Internal
2831
public ClientboundPlayerInfoPacket(PacketSerializer serializer) {
2932
super(serializer);
3033
}

0 commit comments

Comments
 (0)