convert some classes to kotlin

This commit is contained in:
Bixilon 2021-04-22 19:44:13 +02:00
parent 52046de8ab
commit 22e2f8a4a1
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
3 changed files with 81 additions and 75 deletions

View File

@ -1,56 +0,0 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.config;
import com.google.common.base.StandardSystemProperty;
import de.bixilon.minosoft.util.OSUtil;
import java.io.File;
public class StaticConfiguration {
public static final boolean DEBUG_MODE = true; // if true, additional checks will be made to validate data, ... Decreases performance
public static final boolean BIOME_DEBUG_MODE = false; // colors all biomes according to the biome hashCode
public static final boolean DEBUG_SLOW_LOADING = false; // if true, many Thread.sleep will be executed and the start will be delayed (by a lot)
public static final boolean SHOW_LOG_MESSAGES_IN_CHAT = true; // prints all console messages in the chat box
public static final boolean REPLACE_SYSTEM_OUT_STREAMS = true;
public static String CONFIG_FILENAME = "minosoft.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
public static boolean SKIP_MOJANG_AUTHENTICATION; // 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; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
public static boolean VERBOSE_ENTITY_META_DATA_LOGGING; // if true, the entity meta data is getting serialized
public static boolean HEADLESS_MODE; // if true, no gui, rendering or whatever will be loaded or shown
public static String HOME_DIRECTORY;
public static final String TEMPORARY_FOLDER = System.getProperty("java.io.tmpdir", HOME_DIRECTORY + "/tmp/") + "/";
static {
// Sets Config.homeDir to the correct folder per OS
String homeDir;
homeDir = System.getProperty(StandardSystemProperty.USER_HOME.key());
if (!homeDir.endsWith(File.separator)) {
homeDir += "/";
}
homeDir += switch (OSUtil.OS) {
case LINUX -> ".local/share/minosoft/";
case WINDOWS -> "AppData/Roaming/Minosoft/";
case MAC -> "Library/Application Support/Minosoft/";
case OTHER -> ".minosoft/";
};
File folder = new File(homeDir);
if (!folder.exists() && !folder.mkdirs()) {
// failed creating folder
throw new RuntimeException(String.format("Could not create home folder (%s)!", homeDir));
}
HOME_DIRECTORY = folder.getAbsolutePath() + "/";
}
}

View File

@ -0,0 +1,65 @@
/*
* 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 <https://www.gnu.org/licenses/>.
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.config
import com.google.common.base.StandardSystemProperty
import de.bixilon.minosoft.util.OSUtil
import java.io.File
object StaticConfiguration {
const val DEBUG_MODE = true // if true, additional checks will be made to validate data, ... Decreases performance
const val BIOME_DEBUG_MODE = false // colors all biomes according to the biome hashCode
const val DEBUG_SLOW_LOADING = false // if true, many Thread.sleep will be executed and the start will be delayed (by a lot)
const val SHOW_LOG_MESSAGES_IN_CHAT = true // prints all console messages in the chat box
const val REPLACE_SYSTEM_OUT_STREAMS = true
@JvmField
var CONFIG_FILENAME = "minosoft.json" // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
@JvmField
var SKIP_MOJANG_AUTHENTICATION = false // disables all connections to mojang
@JvmField
var COLORED_LOG = true // the log should be colored with ANSI (does not affect base components)
@JvmField
var LOG_RELATIVE_TIME = false // prefix all log messages with the relative start time in milliseconds instead of the formatted time
@JvmField
var VERBOSE_ENTITY_META_DATA_LOGGING = false // if true, the entity meta data is getting serialized
@JvmField
var HEADLESS_MODE = false // if true, no gui, rendering or whatever will be loaded or shown
@JvmField
var HOME_DIRECTORY: String = let {
// Sets Config.homeDir to the correct folder per OS
var homeDir: String = System.getProperty(StandardSystemProperty.USER_HOME.key())
if (!homeDir.endsWith(File.separator)) {
homeDir += "/"
}
homeDir += when (OSUtil.OS) {
OSUtil.OSs.LINUX -> ".local/share/minosoft/"
OSUtil.OSs.WINDOWS -> "AppData/Roaming/Minosoft/"
OSUtil.OSs.MAC -> "Library/Application Support/Minosoft/"
OSUtil.OSs.OTHER -> ".minosoft/"
}
val folder = File(homeDir)
if (!folder.exists() && !folder.mkdirs()) {
// failed creating folder
throw RuntimeException(String.format("Could not create home folder (%s)!", homeDir))
}
folder.absolutePath + "/"
}
val TEMPORARY_FOLDER = System.getProperty("java.io.tmpdir", "$HOME_DIRECTORY/tmp/") + "/"
}

View File

@ -10,29 +10,26 @@
*
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
*/
package de.bixilon.minosoft.util
package de.bixilon.minosoft.util;
object OSUtil {
@JvmStatic
val OS: OSs
public final class OSUtil {
public static final OSs OS;
static {
String name = System.getProperty("os.name");
if (name.startsWith("Windows")) {
OS = OSs.WINDOWS;
} else if (name.startsWith("Linux")) {
OS = OSs.LINUX;
} else if (name.startsWith("Mac")) {
OS = OSs.MAC;
} else {
OS = OSs.OTHER;
}
}
public enum OSs {
enum class OSs {
WINDOWS,
LINUX,
MAC,
OTHER
OTHER,
}
init {
val name = System.getProperty("os.name")
OS = when {
name.startsWith("Windows") -> OSs.WINDOWS
name.startsWith("Linux") -> OSs.LINUX
name.startsWith("Mac") -> OSs.MAC
else -> OSs.OTHER
}
}
}