11package com .github .kd_gaming1 .scaleme .client .util ;
22
33import net .minecraft .client .MinecraftClient ;
4- import net .minecraft .scoreboard .Scoreboard ;
5- import net .minecraft .scoreboard .ScoreboardObjective ;
6- import net .minecraft .scoreboard .ScoreboardDisplaySlot ;
7- import net .minecraft .text .Text ;
4+ import net .minecraft .scoreboard .*;
5+
6+ import java .util .Collection ;
87
98public class HypixelDetector {
109
1110 /**
12- * Checks if the player is in a safe game mode on Hypixel.
13- * Safe modes are defined as not being in competitive modes like SkyBlock, Lobby, Limbo, Housing, or Prototype.
11+ * Checks if the player is in a " safe" game mode on Hypixel.
12+ * Safe modes exclude competitive/gameplay areas like SkyBlock, Lobby, Limbo, Housing, Prototype, and the Hypixel logo screen .
1413 *
1514 * @return true if in a safe game mode, false otherwise.
1615 */
1716 public static boolean isSafeGameMode () {
1817 MinecraftClient client = MinecraftClient .getInstance ();
1918
20- // Check if on Hypixel using server brand
21- if (client .getNetworkHandler () == null ) return false ; // Not on a server, safe
19+ // Not connected to a server
20+ if (client .getNetworkHandler () == null ) return false ;
21+
22+ // Must be Hypixel
2223 String brand = client .getNetworkHandler ().getBrand ();
23- if (brand == null || !brand .toLowerCase ().contains ("hypixel" )) return false ; // Not Hypixel, safe
24+ if (brand == null || !brand .toLowerCase ().contains ("hypixel" )) return false ;
2425
25- // Get scoreboard title
26- if (client .world == null ) return false ; // Safe default for Hypixel
27- Scoreboard scoreboard = client .world .getScoreboard ();
28- if (scoreboard == null ) return false ; // Safe default for Hypixel
26+ if (client .world == null ) return false ;
2927
28+ Scoreboard scoreboard = client .world .getScoreboard ();
3029 ScoreboardObjective objective = scoreboard .getObjectiveForSlot (ScoreboardDisplaySlot .SIDEBAR );
31- if (objective == null ) return false ; // Safe default for Hypixel
30+ if (objective == null ) return false ;
3231
33- Text scoreboardTitle = objective .getDisplayName ();
34- String title = stripColors (scoreboardTitle .getString ()).toUpperCase ();
32+ String title = stripColors (objective .getDisplayName ().getString ()).toUpperCase ();
3533
36- // Return true if in safe modes
34+ System .out .println (("update" ));
35+ // Return true if NOT in any of these game modes
3736 return !title .startsWith ("SKYBLOCK" ) &&
3837 !title .startsWith ("LOBBY" ) &&
3938 !title .startsWith ("LIMBO" ) &&
4039 !title .startsWith ("HOUSING" ) &&
41- !title .startsWith ("PROTOTYPE" );
40+ !title .startsWith ("PROTOTYPE" ) &&
41+ !title .startsWith ("HYPIXEL" );
42+ }
43+
44+ /**
45+ * Checks if the current mode is safe for NPC scaling.
46+ * This means not being in a safe game mode and being inside a dungeon.
47+ */
48+ public static boolean isSafeForNPCScaling () {
49+ return !isSafeGameMode () && isInDungeon ();
4250 }
4351
52+ /**
53+ * Detects if the player is currently inside a Hypixel dungeon by scanning the scoreboard.
54+ * Looks for a line starting with "CLEARED:".
55+ */
56+ public static boolean isInDungeon () {
57+ MinecraftClient client = MinecraftClient .getInstance ();
58+ if (client .world == null ) return false ;
59+
60+ Scoreboard scoreboard = client .world .getScoreboard ();
61+ ScoreboardObjective objective = scoreboard .getObjectiveForSlot (ScoreboardDisplaySlot .SIDEBAR );
62+ if (objective == null ) return false ;
63+
64+ Collection <ScoreboardEntry > entries = scoreboard .getScoreboardEntries (objective );
65+
66+ for (ScoreboardEntry entry : entries ) {
67+ String owner = entry .owner ();
68+ Team team = scoreboard .getScoreHolderTeam (owner );
69+
70+ // Build the full line with prefix/suffix
71+ StringBuilder sb = new StringBuilder ();
72+ if (team != null ) sb .append (team .getPrefix ().getString ());
73+ sb .append (owner );
74+ if (team != null ) sb .append (team .getSuffix ().getString ());
75+
76+ String rawLine = sb .toString ();
77+
78+ // Strip colors, normalize spaces, uppercase
79+ String noColors ;
80+ try {
81+ noColors = stripColors (rawLine );
82+ } catch (Throwable t ) {
83+ noColors = rawLine .replaceAll ("(?i)\\ u00A7[0-9A-FK-OR]" , "" );
84+ }
85+
86+ String line = noColors
87+ .replace ('\u00A0' , ' ' ) // NBSP -> space
88+ .replaceAll ("\\ s+" , " " ) // collapse whitespace
89+ .trim ()
90+ .toUpperCase ();
91+
92+ // Primary and fallback check
93+ if (line .startsWith ("CLEARED:" ) || line .contains ("CLEARED:" )) {
94+ return true ;
95+ }
96+ }
97+ return false ;
98+ }
99+
100+ /**
101+ * Debug helper for printing character code points.
102+ * Only enable this when diagnosing scoreboard parsing issues.
103+ */
104+ @ SuppressWarnings ("unused" )
105+ private static void printCodePoints (String name , String s ) {
106+ StringBuilder out = new StringBuilder ();
107+ out .append (name ).append (": " );
108+ for (int i = 0 ; i < s .length (); i ++) {
109+ out .append (String .format ("[%c U+%04X] " , s .charAt (i ), (int ) s .charAt (i )));
110+ }
111+ System .out .println (out );
112+ }
113+
114+ /**
115+ * Strips Minecraft formatting codes (§ followed by any character).
116+ */
44117 private static String stripColors (String text ) {
45- // Remove Minecraft color codes (§ followed by any character)
46118 return text .replaceAll ("§." , "" );
47119 }
48- }
120+ }
0 commit comments