11package me .redth .mmcutils ;
22
3+ import cc .polyfrost .oneconfig .libs .universal .ChatColor ;
34import com .google .common .collect .ImmutableList ;
4-
55import net .minecraft .client .Minecraft ;
6+ import net .minecraft .scoreboard .Score ;
7+ import net .minecraft .scoreboard .ScoreObjective ;
8+ import net .minecraft .scoreboard .ScorePlayerTeam ;
9+ import net .minecraft .scoreboard .Scoreboard ;
610import net .minecraftforge .client .event .ClientChatReceivedEvent ;
711import net .minecraftforge .client .event .RenderGameOverlayEvent ;
812import net .minecraftforge .common .MinecraftForge ;
1216import net .minecraftforge .fml .common .network .FMLNetworkEvent ;
1317
1418import java .util .List ;
19+ import java .util .Timer ;
20+ import java .util .TimerTask ;
1521
1622@ Mod (modid = MMCUtils .MODID , name = MMCUtils .NAME , version = MMCUtils .VERSION )
1723public class MMCUtils {
@@ -22,36 +28,34 @@ public class MMCUtils {
2228 public static final List <String > BRIDGING_GAMES = ImmutableList .of ("Bed Fight" , "Fireball Fight" , "Bridges" , "Battle Rush" );
2329
2430 private static final Minecraft mc = Minecraft .getMinecraft ();
25- public static boolean inMMC , inPractice , inPartyChat , inBridgingGame ;
31+ public static boolean checkedScoreboard , inPractice , inPartyChat , inBridgingGame ;
2632
2733 @ Mod .EventHandler
2834 public void init (FMLInitializationEvent e ) {
2935 MinecraftForge .EVENT_BUS .register (this );
3036 new Configuration ();
3137 }
3238
33- @ SubscribeEvent
34- public void onJoin (FMLNetworkEvent .ClientConnectedToServerEvent e ) {
35- if (!e .isLocal && mc .getCurrentServerData ().serverIP .contains ("minemen.club" )) inMMC = true ;
36- }
37-
3839 @ SubscribeEvent
3940 public void onQuit (FMLNetworkEvent .ClientDisconnectionFromServerEvent e ) {
40- inMMC = inPractice = inPartyChat = inBridgingGame = false ;
41+ checkedScoreboard = inPractice = inPartyChat = inBridgingGame = false ;
4142 }
4243
4344 @ SubscribeEvent
4445 public void onChat (ClientChatReceivedEvent e ) {
45- if (!inMMC ) return ;
46-
4746 String clean = e .message .getUnformattedText ();
48- if (!inPractice && "Minemen Club" .equals (clean ) && Configuration .autoQueue ) {
49- String [] split = mc .getCurrentServerData ().serverIP .split (".minemen.club" );
50- String mmcProxy = split [0 ].length () == 2 ? split [0 ] : "na" ;
51- mc .thePlayer .sendChatMessage ("/joinqueue " + mmcProxy + "-practice" );
52- inPractice = true ;
47+
48+ if (!checkedScoreboard && !inPractice && "Minemen Club" .equals (clean ) && Configuration .autoQueue ) {
49+ new Timer ().schedule (new TimerTask () {
50+ @ Override
51+ public void run () {
52+ checkScoreboard ();
53+ }
54+ }, 1000L );
5355 }
5456
57+ if (!inPractice ) return ;
58+
5559 if (!inPartyChat && ALL_PROXY .contains (clean ) && Configuration .autoPartyChat ) {
5660 mc .thePlayer .sendChatMessage ("/p chat" );
5761 inPartyChat = true ;
@@ -68,8 +72,28 @@ public void onChat(ClientChatReceivedEvent e) {
6872 @ SubscribeEvent
6973 public void onRenderGameOverlay (RenderGameOverlayEvent .Pre e ) {
7074 if (e .type != RenderGameOverlayEvent .ElementType .PLAYER_LIST ) return ;
71- if (!inMMC ) return ;
75+ if (!checkedScoreboard ) return ;
7276 if (!Configuration .disablePlayerList ) return ;
7377 e .setCanceled (true );
7478 }
79+
80+ public static void checkScoreboard () {
81+ checkedScoreboard = true ;
82+ Scoreboard scoreboard = mc .theWorld .getScoreboard ();
83+ if (scoreboard == null ) return ;
84+ ScoreObjective objective = scoreboard .getObjectiveInDisplaySlot (1 );
85+ if (objective == null ) return ;
86+ for (Score score : scoreboard .getSortedScores (objective )) {
87+ ScorePlayerTeam team = scoreboard .getPlayersTeam (score .getPlayerName ());
88+ String text = ScorePlayerTeam .formatPlayerName (team , score .getPlayerName ());
89+ text = ChatColor .Companion .stripColorCodes (text );
90+ if (text == null ) continue ;
91+ String [] split = text .split (".minemen.club" );
92+ if (split [0 ].length () != 2 ) continue ;
93+ String mmcProxy = split [0 ];
94+ mc .thePlayer .sendChatMessage ("/joinqueue " + mmcProxy + "-practice" );
95+ inPractice = true ;
96+ break ;
97+ }
98+ }
7599}
0 commit comments