LongRunningTask .java

com.mojang.realmsclient.util.task.LongRunningTask (class): members: NUMBER_OF_RETRIES, abortTask, setScreen, aborted, pause, error, getTitle, init, tick.

com.mojang.realmsclient.util.taskclass69 linescommon1.9 KB

Implements

API Surface (9)

void pause(final long seconds)
void setScreen(final Screen screen)
void error(final Component errorMessage)
void error(final Exception ex)
void error(final RealmsServiceException ex)
boolean aborted()
void tick()
void init()
void abortTask()

Fields & Constants (3)

NUMBER_OF_RETRIES
LOGGER
aborted

Full Source

LongRunningTask.java69 lines · Minecraft 26.3 · verbatim
1
package com.mojang.realmsclient.util.task;
2
3
import com.mojang.logging.LogUtils;
4
import com.mojang.realmsclient.RealmsMainScreen;
5
import com.mojang.realmsclient.exception.RealmsServiceException;
6
import com.mojang.realmsclient.gui.screens.RealmsGenericErrorScreen;
7
import net.fabricmc.api.EnvType;
8
import net.fabricmc.api.Environment;
9
import net.minecraft.client.Minecraft;
10
import net.minecraft.client.gui.screens.Screen;
11
import net.minecraft.client.gui.screens.TitleScreen;
12
import net.minecraft.network.chat.Component;
13
import org.slf4j.Logger;
14
15
@Environment(EnvType.CLIENT)
16
public abstract class LongRunningTask implements Runnable {
17
	protected static final int NUMBER_OF_RETRIES = 25;
18
	private static final Logger LOGGER = LogUtils.getLogger();
19
	private boolean aborted = false;
20
21
	protected static void pause(final long seconds) {
22
		try {
23
			Thread.sleep(seconds * 1000L);
24
		} catch (InterruptedException e) {
25
			Thread.currentThread().interrupt();
26
			LOGGER.error("", e);
27
		}
28
	}
29
30
	public static void setScreen(final Screen screen) {
31
		Minecraft minecraft = Minecraft.getInstance();
32
		minecraft.execute(() -> minecraft.gui.setScreen(screen));
33
	}
34
35
	protected void error(final Component errorMessage) {
36
		this.abortTask();
37
		Minecraft minecraft = Minecraft.getInstance();
38
		minecraft.execute(() -> minecraft.gui.setScreen(new RealmsGenericErrorScreen(errorMessage, new RealmsMainScreen(new TitleScreen()))));
39
	}
40
41
	protected void error(final Exception ex) {
42
		if (ex instanceof RealmsServiceException rsx) {
43
			this.error(rsx.realmsError.errorMessage());
44
		} else {
45
			this.error(Component.literal(ex.getMessage()));
46
		}
47
	}
48
49
	protected void error(final RealmsServiceException ex) {
50
		this.error(ex.realmsError.errorMessage());
51
	}
52
53
	public abstract Component getTitle();
54
55
	public boolean aborted() {
56
		return this.aborted;
57
	}
58
59
	public void tick() {
60
	}
61
62
	public void init() {
63
	}
64
65
	public void abortTask() {
66
		this.aborted = true;
67
	}
68
}
69

Decompiled Minecraft 26.3 source of LongRunningTask (com/mojang/realmsclient/util/task/LongRunningTask.java) with Mojang official mappings, stored verbatim on the site.