diff --git a/pom.xml b/pom.xml
index 4367b637c..c6c8a972f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -77,5 +77,10 @@
jcl-core
2.8
+
+ commons-cli
+ commons-cli
+ 1.4
+
diff --git a/src/main/java/de/bixilon/minosoft/Minosoft.java b/src/main/java/de/bixilon/minosoft/Minosoft.java
index 86ddcc469..111762d10 100644
--- a/src/main/java/de/bixilon/minosoft/Minosoft.java
+++ b/src/main/java/de/bixilon/minosoft/Minosoft.java
@@ -29,6 +29,7 @@ import de.bixilon.minosoft.modding.loading.ModLoader;
import de.bixilon.minosoft.modding.loading.Priorities;
import de.bixilon.minosoft.protocol.protocol.LANServerListener;
import de.bixilon.minosoft.util.CountUpAndDownLatch;
+import de.bixilon.minosoft.util.MinosoftCommandLineArguments;
import de.bixilon.minosoft.util.Util;
import de.bixilon.minosoft.util.mojang.api.MojangAccount;
import de.bixilon.minosoft.util.task.AsyncTaskWorker;
@@ -53,6 +54,7 @@ public final class Minosoft {
public static Configuration config;
public static void main(String[] args) {
+ MinosoftCommandLineArguments.parseCommandLineArguments(args);
Log.info("Starting...");
AsyncTaskWorker taskWorker = new AsyncTaskWorker("StartUp");
diff --git a/src/main/java/de/bixilon/minosoft/config/Configuration.java b/src/main/java/de/bixilon/minosoft/config/Configuration.java
index 55fff4b43..70da34774 100644
--- a/src/main/java/de/bixilon/minosoft/config/Configuration.java
+++ b/src/main/java/de/bixilon/minosoft/config/Configuration.java
@@ -33,19 +33,19 @@ public class Configuration {
private final Object lock = new Object();
public Configuration() throws IOException, ConfigMigrationException {
- File file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME);
+ File file = new File(StaticConfiguration.HOME_DIRECTORY + "config/" + StaticConfiguration.CONFIG_FILENAME);
if (!file.exists()) {
// no configuration file
InputStream input = getClass().getResourceAsStream("/config/" + StaticConfiguration.CONFIG_FILENAME);
if (input == null) {
throw new FileNotFoundException(String.format("[Config] Missing default config: %s!", StaticConfiguration.CONFIG_FILENAME));
}
- File folder = new File(StaticConfiguration.HOME_DIR + "config/");
+ File folder = new File(StaticConfiguration.HOME_DIRECTORY + "config/");
if (!folder.exists() && !folder.mkdirs()) {
throw new IOException("[Config] Could not create config folder!");
}
Files.copy(input, Paths.get(file.getAbsolutePath()));
- file = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME);
+ file = new File(StaticConfiguration.HOME_DIRECTORY + "config/" + StaticConfiguration.CONFIG_FILENAME);
}
config = Util.readJsonFromFile(file.getAbsolutePath());
int configVersion = getInt(ConfigurationPaths.IntegerPaths.GENERAL_CONFIG_VERSION);
@@ -67,7 +67,7 @@ public class Configuration {
}
}
// write config to temp file, delete original config, rename temp file to original file to avoid conflicts if minosoft gets closed while saving the config
- File tempFile = new File(StaticConfiguration.HOME_DIR + "config/" + StaticConfiguration.CONFIG_FILENAME + ".tmp");
+ File tempFile = new File(StaticConfiguration.HOME_DIRECTORY + "config/" + StaticConfiguration.CONFIG_FILENAME + ".tmp");
Gson gson = new GsonBuilder().setPrettyPrinting().create();
FileWriter writer;
try {
diff --git a/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java b/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java
index 8c8843e4b..2264c6e0f 100644
--- a/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java
+++ b/src/main/java/de/bixilon/minosoft/config/StaticConfiguration.java
@@ -18,13 +18,13 @@ import de.bixilon.minosoft.util.OSUtil;
import java.io.File;
public class StaticConfiguration {
- public static final String CONFIG_FILENAME = "config.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
- public static final boolean SKIP_MOJANG_AUTHENTICATION = false; // disables all connections to mojang
- public static final boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
- public static final boolean LOG_RELATIVE_TIME = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
- public static final boolean VERBOSE_ENTITY_META_DATA_LOGGING = true; // if true, the entity meta data is getting serial
+ public static String CONFIG_FILENAME = "config.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
+ public static boolean SKIP_MOJANG_AUTHENTICATION = false; // disables all connections to mojang
+ public static boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
+ public static boolean LOG_RELATIVE_TIME = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
+ public static boolean VERBOSE_ENTITY_META_DATA_LOGGING = false; // if true, the entity meta data is getting serial
- public static final String HOME_DIR;
+ public static String HOME_DIRECTORY;
static {
// Sets Config.homeDir to the correct folder per OS
@@ -44,6 +44,6 @@ public class StaticConfiguration {
// failed creating folder
throw new RuntimeException(String.format("Could not create home folder (%s)!", homeDir));
}
- HOME_DIR = folder.getAbsolutePath() + "/";
+ HOME_DIRECTORY = folder.getAbsolutePath() + "/";
}
}
diff --git a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java
index db6aee9cc..9f5babcdb 100644
--- a/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java
+++ b/src/main/java/de/bixilon/minosoft/data/assets/AssetsManager.java
@@ -302,6 +302,6 @@ public class AssetsManager {
if (hash == null) {
throw new FileNotFoundException("Could not find asset with hash: null");
}
- return StaticConfiguration.HOME_DIR + String.format("assets/objects/%s/%s.gz", hash.substring(0, 2), hash);
+ return StaticConfiguration.HOME_DIRECTORY + String.format("assets/objects/%s/%s.gz", hash.substring(0, 2), hash);
}
}
diff --git a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/FishingHook.java b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/FishingHook.java
index bb61f1717..a66c82c29 100644
--- a/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/FishingHook.java
+++ b/src/main/java/de/bixilon/minosoft/data/entities/entities/projectile/FishingHook.java
@@ -23,9 +23,9 @@ import java.util.UUID;
public class FishingHook extends Projectile {
- public FishingHook(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
- super(connection, entityId, uuid, location, rotation);
- }
+ public FishingHook(Connection connection, int entityId, UUID uuid, Location location, EntityRotation rotation) {
+ super(connection, entityId, uuid, location, rotation);
+ }
@EntityMetaDataFunction(identifier = "hookedEntityId")
public int getHookedEntityId() {
diff --git a/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java b/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java
index 42ac4afa0..eb12dd05f 100644
--- a/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java
+++ b/src/main/java/de/bixilon/minosoft/modding/loading/ModLoader.java
@@ -41,7 +41,7 @@ public class ModLoader {
// load all jars, parse the mod.json
// sort the list and prioritize
// load all lists and dependencies async
- File[] files = new File(StaticConfiguration.HOME_DIR + "mods").listFiles();
+ File[] files = new File(StaticConfiguration.HOME_DIRECTORY + "mods").listFiles();
if (files == null) {
// no mods to load
return;
diff --git a/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java b/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java
new file mode 100644
index 000000000..8f3f58ada
--- /dev/null
+++ b/src/main/java/de/bixilon/minosoft/util/MinosoftCommandLineArguments.java
@@ -0,0 +1,72 @@
+/*
+ * Minosoft
+ * Copyright (C) 2020 Moritz Zwerger
+ *
+ * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with this program.If not, see .
+ *
+ * This software is not affiliated with Mojang AB, the original developer of Minecraft.
+ */
+
+package de.bixilon.minosoft.util;
+
+import de.bixilon.minosoft.config.StaticConfiguration;
+import org.apache.commons.cli.*;
+
+public class MinosoftCommandLineArguments {
+
+ public static void parseCommandLineArguments(String[] args) {
+ Options options = new Options();
+
+ Option help = new Option("?", "help", false, "Displays this help");
+ options.addOption(help);
+
+ Option homeFolder = new Option("home_folder", true, "Home of Minosoft");
+ options.addOption(homeFolder);
+
+ Option coloredLog = new Option("colored_log", true, "Should the log be colored");
+ options.addOption(coloredLog);
+
+ Option verboseEntityLogLevel = new Option("verbose_entity_logging", true, "Should entity meta data be printed");
+ options.addOption(verboseEntityLogLevel);
+
+ Option relativeTimeLogging = new Option("log_time_relativ", true, "Should time in log timestamp be relative");
+ options.addOption(relativeTimeLogging);
+
+ HelpFormatter formatter = new HelpFormatter();
+ CommandLine commandLine;
+
+
+ try {
+ commandLine = new DefaultParser().parse(options, args);
+ } catch (ParseException e) {
+ System.out.println(e.getMessage());
+ formatter.printHelp("java -jar Minosoft.jar", options);
+
+ System.exit(1);
+ return;
+ }
+ if (commandLine.hasOption(help.getOpt())) {
+ formatter.printHelp("java -jar Minosoft.jar", options);
+ System.exit(1);
+ return;
+ }
+ if (commandLine.hasOption(homeFolder.getOpt())) {
+ StaticConfiguration.HOME_DIRECTORY = commandLine.getOptionValue(homeFolder.getOpt());
+ }
+ if (commandLine.hasOption(coloredLog.getOpt())) {
+ StaticConfiguration.COLORED_LOG = Boolean.parseBoolean(commandLine.getOptionValue(coloredLog.getOpt()));
+ }
+ if (commandLine.hasOption(verboseEntityLogLevel.getOpt())) {
+ StaticConfiguration.VERBOSE_ENTITY_META_DATA_LOGGING = Boolean.parseBoolean(commandLine.getOptionValue(verboseEntityLogLevel.getOpt()));
+ }
+ if (commandLine.hasOption(relativeTimeLogging.getOpt())) {
+ StaticConfiguration.LOG_RELATIVE_TIME = Boolean.parseBoolean(commandLine.getOptionValue(relativeTimeLogging.getOpt()));
+ }
+
+
+ }
+}