@@ -69,6 +69,7 @@ public final class AltManagerScreen extends Screen
6969 private static final HashSet <Alt > failedLogins = new HashSet <>();
7070 private static final LinkedHashMap <Alt , String > failedLoginReasons =
7171 new LinkedHashMap <>();
72+ private static net .wurstclient .clickgui .widgets .MultiSelectEntryListWidget .SelectionState lastListState ;
7273
7374 private final Screen prevScreen ;
7475 private final AltManager altManager ;
@@ -78,6 +79,7 @@ public final class AltManagerScreen extends Screen
7879 private int errorTimer ;
7980
8081 private Button useButton ;
82+ private Button randomButton ;
8183 private Button starButton ;
8284 private Button editButton ;
8385 private Button deleteButton ;
@@ -99,6 +101,7 @@ public final class AltManagerScreen extends Screen
99101 private volatile boolean importHasCounts ;
100102 private volatile boolean editValidationInProgress ;
101103 private volatile String editValidationStatus = "" ;
104+ private volatile boolean randomLoginInProgress ;
102105
103106 public AltManagerScreen (Screen prevScreen , AltManager altManager )
104107 {
@@ -113,6 +116,10 @@ public void init()
113116 autoCheckCancelled = false ;
114117 listGui = new ListGui (minecraft , this , altManager .getList ());
115118 addWidget (listGui );
119+ if (lastListState != null )
120+ listGui .restoreState (lastListState );
121+ else
122+ listGui .ensureSelection ();
116123
117124 WurstClient wurst = WurstClient .INSTANCE ;
118125
@@ -148,6 +155,10 @@ public void init()
148155 Button .builder (Component .literal ("Login" ), b -> pressLogin ())
149156 .bounds (width / 2 - 154 , height - 52 , 100 , 20 ).build ());
150157
158+ addRenderableWidget (randomButton = Button
159+ .builder (Component .literal ("Login Random" ), b -> pressLoginRandom ())
160+ .bounds (width / 2 + 158 , height - 52 , 100 , 20 ).build ());
161+
151162 addRenderableWidget (Button
152163 .builder (Component .literal ("Direct Login" ),
153164 b -> minecraft .setScreen (new DirectLoginScreen (this )))
@@ -193,7 +204,6 @@ public void init()
193204 Button .builder (Component .literal ("Logout" ), b -> pressLogout ())
194205 .bounds (width - 50 - 8 , 8 , 50 , 20 ).build ());
195206
196- listGui .ensureSelection ();
197207 updateAltButtons ();
198208 boolean windowMode = !minecraft .options .fullscreen ().get ();
199209 importButton .active = windowMode ;
@@ -210,6 +220,8 @@ private void updateAltButtons()
210220 if (importInProgress )
211221 {
212222 useButton .active = false ;
223+ if (randomButton != null )
224+ randomButton .active = false ;
213225 starButton .active = false ;
214226 editButton .active = false ;
215227 deleteButton .active = false ;
@@ -225,6 +237,8 @@ private void updateAltButtons()
225237 if (editValidationInProgress )
226238 {
227239 useButton .active = false ;
240+ if (randomButton != null )
241+ randomButton .active = false ;
228242 starButton .active = false ;
229243 editButton .active = false ;
230244 deleteButton .active = false ;
@@ -241,6 +255,9 @@ private void updateAltButtons()
241255 boolean hasSingleSelection = selectionCount == 1 ;
242256
243257 useButton .active = hasSingleSelection ;
258+ if (randomButton != null )
259+ randomButton .active =
260+ !randomLoginInProgress && !altManager .getList ().isEmpty ();
244261 starButton .active = hasSingleSelection ;
245262 editButton .active = hasSingleSelection ;
246263 deleteButton .active = selectionCount > 0 ;
@@ -321,6 +338,87 @@ private void confirmLogin(boolean confirmed)
321338 }
322339 }
323340
341+ private void pressLoginRandom ()
342+ {
343+ if (randomLoginInProgress )
344+ return ;
345+
346+ randomLoginInProgress = true ;
347+ updateAltButtons ();
348+
349+ Thread thread =
350+ new Thread (this ::runRandomLogin , "Wurst Alt Random Login" );
351+ thread .setDaemon (true );
352+ thread .start ();
353+ }
354+
355+ private void runRandomLogin ()
356+ {
357+ IMinecraftClient imc = (IMinecraftClient )minecraft ;
358+ User previousSession = imc .getWurstSession ();
359+
360+ try
361+ {
362+ List <Alt > list = new ArrayList <>(altManager .getList ());
363+ if (list .isEmpty ())
364+ {
365+ minecraft .execute (() -> {
366+ randomLoginInProgress = false ;
367+ updateAltButtons ();
368+ });
369+ return ;
370+ }
371+
372+ Collections .shuffle (list );
373+
374+ for (Alt alt : list )
375+ {
376+ if (!isOpenScreen ())
377+ return ;
378+
379+ setChecking (alt , true );
380+ try
381+ {
382+ altManager .login (alt );
383+ clearLoginFailure (alt );
384+ String name = minecraft .getUser ().getName ();
385+ minecraft .execute (() -> {
386+ randomLoginInProgress = false ;
387+ updateAltButtons ();
388+ if (minecraft .screen == this )
389+ minecraft .setScreen (
390+ new AltLoginSuccessScreen (prevScreen , name ));
391+ });
392+ return ;
393+
394+ }catch (LoginException e )
395+ {
396+ recordLoginFailure (alt , e );
397+
398+ }finally
399+ {
400+ setChecking (alt , false );
401+ }
402+ }
403+
404+ if (!isOpenScreen ())
405+ return ;
406+
407+ errorTimer = 8 ;
408+ minecraft .execute (() -> {
409+ randomLoginInProgress = false ;
410+ updateAltButtons ();
411+ if (minecraft .screen == this )
412+ minecraft .setScreen (new AltLoginFailedScreen (this ,
413+ "Random login failed for all accounts." ));
414+ });
415+
416+ }finally
417+ {
418+ imc .setWurstSession (previousSession );
419+ }
420+ }
421+
324422 private void pressLogout ()
325423 {
326424 IMinecraftClient imc = (IMinecraftClient )minecraft ;
@@ -1305,6 +1403,8 @@ public void onClose()
13051403 public void removed ()
13061404 {
13071405 autoCheckCancelled = true ;
1406+ if (listGui != null )
1407+ lastListState = listGui .captureState ();
13081408 super .removed ();
13091409 }
13101410
0 commit comments