Skip to content

Commit e511e8d

Browse files
committed
Added Random to AltManager
1 parent 66bcab6 commit e511e8d

File tree

2 files changed

+111
-3
lines changed

2 files changed

+111
-3
lines changed

build.gradle

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ dependencies {
6464
minecraft "com.mojang:minecraft:${project.minecraft_version}"
6565
mappings loom.officialMojangMappings()
6666
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
67-
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
67+
// Use Fabric Loader JUnit only for gametests, not for plain unit tests
68+
// Standard JUnit for unit tests
69+
testImplementation "org.junit.jupiter:junit-jupiter:5.10.2"
70+
testRuntimeOnly "org.junit.platform:junit-platform-launcher:1.10.2"
6871

6972
// Fabric API. This is technically optional, but you probably want it anyway.
7073
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api_version}"
@@ -81,7 +84,7 @@ dependencies {
8184
fabricApi.configureTests {
8285
createSourceSet = true
8386
enableGameTests = false
84-
enableClientGameTests = true
87+
enableClientGameTests = false
8588
modId = "wurst_testmod"
8689
username = "Wurst-Bot"
8790
}
@@ -118,6 +121,8 @@ configurations {
118121

119122
dependencies {
120123
testMods "maven.modrinth:sodium:${project.sodium_version}"
124+
// Ensure gametest source set has Fabric JUnit engine
125+
gametestImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
121126
}
122127

123128
def cleanClientWithMods = tasks.register("cleanClientWithMods", Delete) {
@@ -275,6 +280,9 @@ spotless {
275280

276281
test {
277282
useJUnitPlatform()
283+
// Ensure Fabric Loader JUnit can see the test classes as a classpath group
284+
// to avoid "hasn't been exposed to the game" errors in-dev.
285+
systemProperty "fabric.classPathGroups", "default,test"
278286
}
279287

280288
def getGhVersion() {

src/main/java/net/wurstclient/altmanager/screens/AltManagerScreen.java

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)