From d931a8abd1adcc203e0aa9bdbc52e37d4d1ef99b Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 25 Sep 2023 19:11:57 +0700 Subject: [PATCH] fix kaboom check --- .../chipmunkmod/modules/KaboomCheck.java | 63 +++++++------------ 1 file changed, 24 insertions(+), 39 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java index 8bbdb12..877bcfe 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java @@ -1,28 +1,20 @@ package land.chipmunk.chipmunkmod.modules; +import com.mojang.brigadier.suggestion.Suggestion; +import com.mojang.brigadier.suggestion.Suggestions; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; - import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; -import net.minecraft.network.packet.Packet; -import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket; -import net.minecraft.network.packet.s2c.play.TitleS2CPacket; +import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket; import java.util.Timer; import java.util.TimerTask; +import java.util.concurrent.CompletableFuture; public class KaboomCheck extends Listener { - public static final String TITLE_START_TEXT = "Welcome to "; - public static final String TITLE_END_TEXT = "!"; - - public static final String SUBTITLE_START_TEXT = "Free OP"; - public boolean isKaboom = false; - private boolean hasKaboomTitle = false; - private boolean hasKaboomSubtitle = false; - private Timer timer = null; private final MinecraftClient client; @@ -49,50 +41,43 @@ public class KaboomCheck extends Listener { timer = new Timer(); timer.schedule(task, 50, 50); + + check(); } private void tick () { final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); if (networkHandler == null) cleanup(); + } - if (hasKaboomTitle && hasKaboomSubtitle) isKaboom = true; + private void check () { + final CompletableFuture future = TabComplete.INSTANCE.complete("/ver "); + + future.thenApply((packet) -> { + final Suggestions suggestions = packet.getSuggestions(); + + for (int i = 0; i < suggestions.getList().size(); i++) { + final Suggestion suggestion = suggestions.getList().get(i); + + if (suggestion.getText().equals("Extras")) { + isKaboom = true; + break; + } + } + + return packet; + }); } private void cleanup () { if (timer == null) return; isKaboom = false; - hasKaboomTitle = false; - hasKaboomSubtitle = false; timer.purge(); timer.cancel(); } - @Override - public void packetReceived(Packet packet) { - if (packet instanceof TitleS2CPacket) packetReceived((TitleS2CPacket) packet); - else if (packet instanceof SubtitleS2CPacket) packetReceived((SubtitleS2CPacket) packet); - } - // TODO: move this to a util class - private String stripSectionSigns (String text) { - return text.replaceAll("ยง.", ""); - } - - public void packetReceived(TitleS2CPacket packet) { - final String stripped = stripSectionSigns(packet.getTitle().getString()); - - if ( - stripped.startsWith(TITLE_START_TEXT) && - stripped.endsWith(TITLE_END_TEXT) - ) hasKaboomTitle = true; - } - - public void packetReceived(SubtitleS2CPacket packet) { - final String stripped = stripSectionSigns(packet.getSubtitle().getString()); - - if (stripped.startsWith(SUBTITLE_START_TEXT)) hasKaboomSubtitle = true; - } }