Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
package net.hypixel.modapi.handler;

import net.hypixel.modapi.packet.HypixelPacket;
import net.hypixel.modapi.packet.impl.clientbound.ClientboundLocationPacket;
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPartyInfoPacket;
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPingPacket;
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPlayerInfoPacket;

public interface ClientboundPacketHandler extends PacketHandler {

default void handle(HypixelPacket packet) {
if (packet instanceof ClientboundPingPacket) {
onPingPacket((ClientboundPingPacket) packet);
}

if (packet instanceof ClientboundLocationPacket) {
onLocationPacket((ClientboundLocationPacket) packet);
}

if (packet instanceof ClientboundPartyInfoPacket) {
onPartyInfoPacket((ClientboundPartyInfoPacket) packet);
}

if (packet instanceof ClientboundPlayerInfoPacket) {
onPlayerInfoPacket((ClientboundPlayerInfoPacket) packet);
}
}

default void onPingPacket(ClientboundPingPacket packet) {
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.hypixel.modapi.packet;

import net.hypixel.modapi.handler.ClientboundPacketHandler;

public interface ClientboundHypixelPacket extends HypixelPacket {

void handle(ClientboundPacketHandler handler);

}
10 changes: 5 additions & 5 deletions src/main/java/net/hypixel/modapi/packet/PacketRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class PacketRegistry {
private final Map<Class<? extends HypixelPacket>, String> classToIdentifier = new ConcurrentHashMap<>();

public void registerPacketType(String identifier,
Class<? extends HypixelPacket> clientboundClazz, Function<PacketSerializer, HypixelPacket> clientPacketFactory,
Class<? extends ClientboundHypixelPacket> clientboundClazz, Function<PacketSerializer, ClientboundHypixelPacket> clientPacketFactory,
Class<? extends HypixelPacket> serverboundClazz, Function<PacketSerializer, HypixelPacket> serverPacketFactory) {
registrations.put(identifier, new RegisteredType(clientboundClazz, clientPacketFactory, serverboundClazz, serverPacketFactory));
classToIdentifier.put(clientboundClazz, identifier);
Expand All @@ -33,7 +33,7 @@ public boolean isRegistered(String identifier) {
return registrations.containsKey(identifier);
}

public HypixelPacket createClientboundPacket(String identifier, PacketSerializer serializer) {
public ClientboundHypixelPacket createClientboundPacket(String identifier, PacketSerializer serializer) {
return getRegisteredType(identifier).clientPacketFactory.apply(serializer);
}

Expand All @@ -51,12 +51,12 @@ public Set<String> getIdentifiers() {

private static final class RegisteredType {

private final Class<? extends HypixelPacket> clientboundClazz;
private final Function<PacketSerializer, HypixelPacket> clientPacketFactory;
private final Class<? extends ClientboundHypixelPacket> clientboundClazz;
private final Function<PacketSerializer, ClientboundHypixelPacket> clientPacketFactory;
private final Class<? extends HypixelPacket> serverboundClazz;
private final Function<PacketSerializer, HypixelPacket> serverPacketFactory;

public RegisteredType(Class<? extends HypixelPacket> clientboundClazz, Function<PacketSerializer, HypixelPacket> clientPacketFactory,
public RegisteredType(Class<? extends ClientboundHypixelPacket> clientboundClazz, Function<PacketSerializer, ClientboundHypixelPacket> clientPacketFactory,
Class<? extends HypixelPacket> serverboundClazz, Function<PacketSerializer, HypixelPacket> serverPacketFactory) {
this.clientboundClazz = clientboundClazz;
this.clientPacketFactory = clientPacketFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

import net.hypixel.data.region.Environment;
import net.hypixel.data.type.ServerType;
import net.hypixel.modapi.handler.ClientboundPacketHandler;
import net.hypixel.modapi.packet.ClientboundHypixelPacket;
import net.hypixel.modapi.packet.impl.VersionedPacket;
import net.hypixel.modapi.serializer.PacketSerializer;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ClientboundLocationPacket extends VersionedPacket {
public class ClientboundLocationPacket extends VersionedPacket implements ClientboundHypixelPacket {
private static final int CURRENT_VERSION = 1;

private final Environment environment;
Expand Down Expand Up @@ -73,6 +75,11 @@ public void write(PacketSerializer serializer) {
}
}

@Override
public void handle(ClientboundPacketHandler handler) {
handler.handle(this);
}

public Environment getEnvironment() {
return environment;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package net.hypixel.modapi.packet.impl.clientbound;

import net.hypixel.modapi.handler.ClientboundPacketHandler;
import net.hypixel.modapi.packet.ClientboundHypixelPacket;
import net.hypixel.modapi.packet.impl.VersionedPacket;
import net.hypixel.modapi.serializer.PacketSerializer;
import org.jetbrains.annotations.Nullable;

import java.util.*;

public class ClientboundPartyInfoPacket extends VersionedPacket {
public class ClientboundPartyInfoPacket extends VersionedPacket implements ClientboundHypixelPacket {
private static final int CURRENT_VERSION = 1;

private final boolean inParty;
Expand Down Expand Up @@ -54,6 +56,11 @@ public void write(PacketSerializer serializer) {
}
}

@Override
public void handle(ClientboundPacketHandler handler) {
handler.handle(this);
}

public boolean isInParty() {
return inParty;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package net.hypixel.modapi.packet.impl.clientbound;

import net.hypixel.modapi.handler.ClientboundPacketHandler;
import net.hypixel.modapi.packet.ClientboundHypixelPacket;
import net.hypixel.modapi.packet.impl.VersionedPacket;
import net.hypixel.modapi.serializer.PacketSerializer;

public class ClientboundPingPacket extends VersionedPacket {
public class ClientboundPingPacket extends VersionedPacket implements ClientboundHypixelPacket {
private static final int CURRENT_VERSION = 1;

private final String response;
Expand All @@ -24,6 +26,11 @@ public void write(PacketSerializer serializer) {
serializer.writeString(response);
}

@Override
public void handle(ClientboundPacketHandler handler) {
handler.handle(this);
}

public String getResponse() {
return response;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import net.hypixel.data.rank.MonthlyPackageRank;
import net.hypixel.data.rank.PackageRank;
import net.hypixel.data.rank.PlayerRank;
import net.hypixel.modapi.handler.ClientboundPacketHandler;
import net.hypixel.modapi.packet.ClientboundHypixelPacket;
import net.hypixel.modapi.packet.impl.VersionedPacket;
import net.hypixel.modapi.serializer.PacketSerializer;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;

public class ClientboundPlayerInfoPacket extends VersionedPacket {
public class ClientboundPlayerInfoPacket extends VersionedPacket implements ClientboundHypixelPacket {
private static final int CURRENT_VERSION = 1;

private final PlayerRank playerRank;
Expand Down Expand Up @@ -46,6 +48,11 @@ public void write(PacketSerializer serializer) {
}
}

@Override
public void handle(ClientboundPacketHandler handler) {
handler.handle(this);
}

public PlayerRank getPlayerRank() {
return playerRank;
}
Expand Down