| 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 |
|