Eula .java

net.minecraft.server.Eula (class, 51 lines): members: hasAgreedToEULA, agreed, file, LOGGER. imports: CommonLinks, SharedConstants, LogUtils.

net.minecraft.serverclass51 linesserver1.4 KB

API Surface (1)

boolean hasAgreedToEULA()

Fields & Constants (3)

LOGGER
file
agreed

Code Graph: Dependencies (3)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

Eula.java51 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.server;
2
3
import com.mojang.logging.LogUtils;
4
import java.io.InputStream;
5
import java.io.OutputStream;
6
import java.nio.file.Files;
7
import java.nio.file.Path;
8
import java.util.Properties;
9
import net.minecraft.SharedConstants;
10
import net.minecraft.util.CommonLinks;
11
import org.slf4j.Logger;
12
13
public class Eula {
14
	private static final Logger LOGGER = LogUtils.getLogger();
15
	private final Path file;
16
	private final boolean agreed;
17
18
	public Eula(final Path file) {
19
		this.file = file;
20
		this.agreed = SharedConstants.IS_RUNNING_IN_IDE || this.readFile();
21
	}
22
23
	private boolean readFile() {
24
		try (InputStream input = Files.newInputStream(this.file)) {
25
			Properties properties = new Properties();
26
			properties.load(input);
27
			return Boolean.parseBoolean(properties.getProperty("eula", "false"));
28
		} catch (Exception ignored) {
29
			LOGGER.warn("Failed to load {}", this.file);
30
			this.saveDefaults();
31
			return false;
32
		}
33
	}
34
35
	public boolean hasAgreedToEULA() {
36
		return this.agreed;
37
	}
38
39
	private void saveDefaults() {
40
		if (!SharedConstants.IS_RUNNING_IN_IDE) {
41
			try (OutputStream output = Files.newOutputStream(this.file)) {
42
				Properties properties = new Properties();
43
				properties.setProperty("eula", "false");
44
				properties.store(output, "By changing the setting below to TRUE you are indicating your agreement to our EULA (" + CommonLinks.EULA + ").");
45
			} catch (Exception e) {
46
				LOGGER.warn("Failed to save {}", this.file, e);
47
			}
48
		}
49
	}
50
}
51

Decompiled Minecraft 26.3 source of Eula (net/minecraft/server/Eula.java) with Mojang official mappings, stored verbatim on the site.