Skip to content

Commit 793d7d8

Browse files
committed
Now I see that connor just straight up removed location packets without adding the events :)
1 parent 2ae5015 commit 793d7d8

File tree

7 files changed

+116
-87
lines changed

7 files changed

+116
-87
lines changed

src/main/java/llc/redstone/hysentials/Hysentials.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ private void registerHandlers() {
403403
final llc.redstone.hysentials.event.EventBus hyBus = llc.redstone.hysentials.event.EventBus.INSTANCE;
404404
try {
405405
SBBoxesEditor.initGUI();
406-
LocrawUtil.INSTANCE.init();
407406
// general stuff
408407
eventBus.register(languageHandler);
409408
// try {
@@ -463,8 +462,11 @@ private void registerHandlers() {
463462

464463
EventManager.INSTANCE.register(new BwRanks());
465464

465+
System.out.println("Handlers registered!");
466+
HypixelModAPI.getInstance().setPacketSender(ModAPIHandler::sendPacket);
466467
HypixelModAPI.getInstance().subscribeToEventPacket(ClientboundLocationPacket.class);
467-
HypixelModAPI.getInstance().registerHandler(hypixelModAPI = new ModAPIHandler());
468+
HypixelModAPI.getInstance().registerHandler(new ModAPIHandler());
469+
System.out.println("HypixelModAPI initialized!");
468470

469471
// Runtime.getRuntime().addShutdownHook(new Thread(() -> {
470472
// JSONArray array = new JSONArray();

src/main/java/llc/redstone/hysentials/command/HysentialsCommand.java

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@
3030
import net.hypixel.data.type.ServerType;
3131
import net.hypixel.modapi.HypixelModAPI;
3232
import net.hypixel.modapi.handler.ClientboundPacketHandler;
33-
import net.hypixel.modapi.packet.impl.clientbound.ClientboundLocationPacket;
33+
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPingPacket;
3434
import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket;
35+
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPingPacket;
36+
import net.hypixel.modapi.packet.impl.serverbound.ServerboundPlayerInfoPacket;
3537
import net.minecraft.client.Minecraft;
3638
import net.minecraft.command.CommandBase;
3739
import net.minecraft.command.CommandException;
@@ -344,37 +346,19 @@ private static void handleTest(String command, String args) {
344346
break;
345347
}
346348

347-
case "plus": {
348-
UChat.chat("Sending Location Request...");
349-
HypixelModAPI.getInstance().registerHandler(new ClientboundPacketHandler() {
350-
@Override
351-
public void onLocationEvent(ClientboundLocationPacket packet) {
352-
double x = 0;
353-
double y = 0;
354-
double z = 0;
355-
float yaw = 0;
356-
if (!packet.getServerType().isPresent()) return;
357-
ServerType serverType = packet.getServerType().get();
358-
if (!(serverType instanceof GameType)) return;
359-
GameType gameType = (GameType) serverType;
360-
switch (gameType) {
361-
case HOUSING: {
362-
x = -16;
363-
y = 65;
364-
z = 30;
365-
yaw = 320f;
366-
break;
367-
}
368-
}
369-
370-
PlusStandEntity entity = new PlusStandEntity(Minecraft.getMinecraft().theWorld);
371-
entity.setPositionAndRotation(x, y, z, yaw, 0);
372-
Minecraft.getMinecraft().theWorld.spawnEntityInWorld(entity);
373-
}
349+
case "hypixel": {
350+
UChat.chat("Sending hypixel packet...");
351+
ModAPIHandler.sendPacket(new ServerboundPingPacket(), (packet) -> {
352+
ClientboundPingPacket pingPacket = (ClientboundPingPacket) packet;
353+
UChat.chat("§aReceived ping packet: " + pingPacket.getResponse());
374354
});
375355
break;
376356
}
377357

358+
case "plus": {
359+
break;
360+
}
361+
378362
case "house": {
379363
VisitHouseScreen.INSTANCE.open();
380364
break;

src/main/java/llc/redstone/hysentials/handlers/lobby/TabChanger.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@
1919
package llc.redstone.hysentials.handlers.lobby;
2020

2121
import cc.polyfrost.oneconfig.utils.hypixel.HypixelUtils;
22+
import cc.polyfrost.oneconfig.utils.hypixel.LocrawInfo;
23+
import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
2224
import com.google.common.collect.ComparisonChain;
2325
import com.google.common.collect.Ordering;
2426
import llc.redstone.hysentials.forge.HysentialsMixinPlugin;
2527
import llc.redstone.hysentials.handlers.redworks.BwRanksUtils;
2628
import llc.redstone.hysentials.util.BlockWAPIUtils;
27-
import llc.redstone.hysentials.util.LocrawInfo;
28-
import llc.redstone.hysentials.util.LocrawUtil;
2929
import llc.redstone.hysentials.utils.StringUtilsKt;
30-
import net.hypixel.data.type.GameType;
3130
import net.minecraft.client.network.NetworkPlayerInfo;
3231
import net.minecraft.scoreboard.ScorePlayerTeam;
3332
import net.minecraft.world.WorldSettings;
@@ -50,7 +49,7 @@ public static String modifyName(String displayName, NetworkPlayerInfo playerInfo
5049
final String username = playerInfo.getGameProfile().getName();
5150
final LocrawInfo locraw = LocrawUtil.INSTANCE.getLocrawInfo();
5251

53-
if (locraw != null && LocrawUtil.INSTANCE.isInGame() && locraw.getGameType().equals(GameType.SKYBLOCK)) {
52+
if (locraw != null && LocrawUtil.INSTANCE.isInGame() && locraw.getGameType().equals(LocrawInfo.GameType.SKYBLOCK)) {
5453
return displayName;
5554
}
5655

@@ -84,7 +83,7 @@ public int compare(NetworkPlayerInfo networkPlayerInfo, NetworkPlayerInfo networ
8483
BlockWAPIUtils.Rank rank = BlockWAPIUtils.getRank(networkPlayerInfo.getGameProfile().getId());
8584
BlockWAPIUtils.Rank rank2 = BlockWAPIUtils.getRank(networkPlayerInfo2.getGameProfile().getId());
8685

87-
if (locrawInfo != null && Objects.equals(locrawInfo.getGameType(), GameType.HOUSING) && locrawInfo.getLobbyName() == null) {
86+
if (locrawInfo != null && Objects.equals(locrawInfo.getGameType(), LocrawInfo.GameType.HOUSING) && LocrawUtil.INSTANCE.isInGame()) {
8887
//In a house, sort by housing team name before hysentials rank
8988
return ComparisonChain.start().compareTrueFirst(networkPlayerInfo.getGameType() != WorldSettings.GameType.SPECTATOR, networkPlayerInfo2.getGameType() != WorldSettings.GameType.SPECTATOR).compare(scorePlayerTeam != null ? scorePlayerTeam.getRegisteredName() : "", scorePlayerTeam2 != null ? scorePlayerTeam2.getRegisteredName() : "").compare(
9089
rank2 != null ? rank2.index : -1, rank != null ? rank.index : -1

src/main/java/llc/redstone/hysentials/handlers/misc/PacketRecievedHandler.java

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import io.netty.channel.ChannelDuplexHandler;
44
import io.netty.channel.ChannelHandlerContext;
55
import io.netty.channel.ChannelPromise;
6+
import io.netty.channel.SimpleChannelInboundHandler;
67
import llc.redstone.hysentials.event.CancellableEvent;
78
import net.hypixel.modapi.HypixelModAPI;
89
import net.hypixel.modapi.serializer.PacketSerializer;
@@ -14,36 +15,31 @@
1415
public class PacketRecievedHandler {
1516
@SubscribeEvent
1617
public void onNetworkEvent(FMLNetworkEvent.ClientConnectedToServerEvent event) {
17-
event.manager.channel().pipeline()
18-
.addAfter("fml:packet_handler", "HS_packet_handler", new ChannelDuplexHandler() {
19-
@Override
20-
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
21-
CancellableEvent packetReceivedEvent = new CancellableEvent();
22-
23-
if (msg instanceof S3FPacketCustomPayload) {
24-
S3FPacketCustomPayload packet = (S3FPacketCustomPayload) msg;
25-
26-
HypixelModAPI.getInstance().handle(
27-
packet.getChannelName(),
28-
new PacketSerializer(packet.getBufferData())
29-
);
30-
}
31-
32-
if (!packetReceivedEvent.isCancelled())
33-
ctx.fireChannelRead(msg);
34-
}
35-
36-
@Override
37-
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
38-
CancellableEvent packetSentEvent = new CancellableEvent();
39-
40-
if (msg instanceof Packet) {
41-
42-
}
18+
event.manager.channel().pipeline().addBefore("packet_handler", "hysentials_mod_api_packet_handler", HypixelPacketHandler.INSTANCE);
19+
}
4320

44-
if (!packetSentEvent.isCancelled())
45-
ctx.write(msg, promise);
46-
}
47-
});
21+
public static class HypixelPacketHandler extends SimpleChannelInboundHandler<Packet<?>>{
22+
private static final HypixelPacketHandler INSTANCE = new HypixelPacketHandler();
23+
24+
@Override
25+
protected void channelRead0(ChannelHandlerContext ctx, Packet<?> msg) {
26+
ctx.fireChannelRead(msg);
27+
28+
if (!(msg instanceof S3FPacketCustomPayload)) {
29+
return;
30+
}
31+
32+
S3FPacketCustomPayload packet = (S3FPacketCustomPayload) msg;
33+
String identifier = packet.getChannelName();
34+
if (!HypixelModAPI.getInstance().getRegistry().isRegistered(identifier)) {
35+
return;
36+
}
37+
38+
try {
39+
HypixelModAPI.getInstance().handle(identifier, new PacketSerializer(packet.getBufferData()));
40+
} catch (Exception e) {
41+
e.printStackTrace();
42+
}
43+
}
4844
}
4945
}

src/main/java/llc/redstone/hysentials/util/LocrawUtil.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,19 +61,6 @@ public class LocrawUtil {
6161

6262
public void init() {
6363
MinecraftForge.EVENT_BUS.register(this);
64-
HypixelModAPI.getInstance().registerHandler(new ClientboundPacketHandler() {
65-
@Override
66-
public void onLocationEvent(ClientboundLocationPacket packet) {
67-
try {
68-
locrawInfo = new LocrawInfo(packet);
69-
} catch (Exception ignored) {
70-
ignored.printStackTrace();
71-
}
72-
if (locrawInfo != null) {
73-
inGame = locrawInfo.getLobbyName() == null;
74-
}
75-
}
76-
});
7764
}
7865

7966
@SubscribeEvent
@@ -115,4 +102,15 @@ public LocrawInfo getLocrawInfo() {
115102
public LocrawInfo getLastLocrawInfo() {
116103
return lastLocrawInfo;
117104
}
105+
106+
public void update (ClientboundLocationPacket packet) {
107+
try {
108+
locrawInfo = new LocrawInfo(packet);
109+
} catch (Exception ignored) {
110+
ignored.printStackTrace();
111+
}
112+
if (locrawInfo != null) {
113+
inGame = locrawInfo.getLobbyName() == null;
114+
}
115+
}
118116
}

src/main/java/llc/redstone/hysentials/util/ModAPIHandler.java

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,71 @@
33
import io.netty.buffer.Unpooled;
44
import net.hypixel.modapi.handler.ClientboundPacketHandler;
55
import net.hypixel.modapi.packet.HypixelPacket;
6+
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPartyInfoPacket;
7+
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPingPacket;
8+
import net.hypixel.modapi.packet.impl.clientbound.ClientboundPlayerInfoPacket;
9+
import net.hypixel.modapi.packet.impl.clientbound.event.ClientboundLocationPacket;
10+
import net.hypixel.modapi.serializer.PacketSerializer;
611
import net.minecraft.client.Minecraft;
12+
import net.minecraft.client.network.NetHandlerPlayClient;
713
import net.minecraft.network.PacketBuffer;
814
import net.minecraft.network.play.client.C17PacketCustomPayload;
915

1016
import java.util.HashMap;
1117
import java.util.function.Consumer;
1218

1319
public class ModAPIHandler implements ClientboundPacketHandler {
14-
public void sendPacket(HypixelPacketType packet, PacketBuffer buffer) {
15-
Minecraft.getMinecraft().getNetHandler().addToSendQueue(
16-
new C17PacketCustomPayload(
17-
packet.getIdentifier(),
18-
(buffer == null ? new PacketBuffer(
19-
Unpooled.buffer(1).writeByte(1)
20-
) : buffer)
21-
)
22-
);
20+
private static HashMap<String, Consumer<HypixelPacket>> packetAwaiters = new HashMap<>();
21+
22+
public static boolean sendPacket(HypixelPacket packet) {
23+
NetHandlerPlayClient netHandler = Minecraft.getMinecraft().getNetHandler();
24+
if (netHandler == null) {
25+
return false;
26+
}
27+
28+
PacketBuffer buf = new PacketBuffer(Unpooled.buffer());
29+
PacketSerializer serializer = new PacketSerializer(buf);
30+
packet.write(serializer);
31+
netHandler.addToSendQueue(new C17PacketCustomPayload(packet.getIdentifier(), buf));
32+
return true;
33+
}
34+
35+
public static void sendPacket(HypixelPacket serverBound, Consumer<HypixelPacket> consumer) {
36+
packetAwaiters.put(serverBound.getIdentifier(), consumer);
37+
sendPacket(serverBound);
38+
}
39+
40+
@Override
41+
public void onLocationEvent(ClientboundLocationPacket packet) {
42+
LocrawUtil.INSTANCE.update(packet);
43+
44+
if (packetAwaiters.containsKey(packet.getIdentifier())) {
45+
packetAwaiters.get(packet.getIdentifier()).accept(packet);
46+
packetAwaiters.remove(packet.getIdentifier());
47+
}
48+
}
49+
50+
@Override
51+
public void onPartyInfoPacket(ClientboundPartyInfoPacket packet) {
52+
if (packetAwaiters.containsKey(packet.getIdentifier())) {
53+
packetAwaiters.get(packet.getIdentifier()).accept(packet);
54+
packetAwaiters.remove(packet.getIdentifier());
55+
}
56+
}
57+
58+
@Override
59+
public void onPingPacket(ClientboundPingPacket packet) {
60+
if (packetAwaiters.containsKey(packet.getIdentifier())) {
61+
packetAwaiters.get(packet.getIdentifier()).accept(packet);
62+
packetAwaiters.remove(packet.getIdentifier());
63+
}
64+
}
65+
66+
@Override
67+
public void onPlayerInfoPacket(ClientboundPlayerInfoPacket packet) {
68+
if (packetAwaiters.containsKey(packet.getIdentifier())) {
69+
packetAwaiters.get(packet.getIdentifier()).accept(packet);
70+
packetAwaiters.remove(packet.getIdentifier());
71+
}
2372
}
2473
}

src/main/java/llc/redstone/hysentials/util/ScoreboardWrapper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package llc.redstone.hysentials.util;
22

3+
import cc.polyfrost.oneconfig.utils.hypixel.LocrawUtil;
34
import llc.redstone.hysentials.Hysentials;
45
import llc.redstone.hysentials.config.HysentialsConfig;
56
import llc.redstone.hysentials.config.hysentialMods.FormattingConfig;

0 commit comments

Comments
 (0)