From f31389f6bb0f9e6e473a045a2ccfb27b9122eff7 Mon Sep 17 00:00:00 2001 From: Ben Willenbring Date: Sun, 1 Aug 2021 16:01:52 +0200 Subject: [PATCH] feat: add option in configuration to set the jar name --- README.md | 10 ++++++---- example/speedrun.json | 3 ++- src/adapter/configuration.ts | 12 ++++++++---- src/model/configuration.ts | 15 ++++++++------- src/model/configurationApi.ts | 12 ++++++++++++ src/server.ts | 11 +++++++---- src/validation/configuration.spec.ts | 8 ++++---- src/validation/configuration.ts | 4 ++-- 8 files changed, 49 insertions(+), 26 deletions(-) create mode 100644 src/model/configurationApi.ts diff --git a/README.md b/README.md index 30cee33..1c1602b 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,10 @@ _Note: Enabling flight will prevent random disconnects when traveling too fast v "WHITELIST": ["Notch"], // List of whitelisted players "DATA_PACK": false, // set to true, if datapacks should be copied into the world "SEEDS": ["-9223372036854775808", "9223372036854775807"], // List of set seeds that are played one by one, set [] to disable this option - "AUTO_SAVE": false, // Turn off to prevent 5 minute lag, default false - "KEEP_WORLDS": false, // Turn on if worlds should be renamed instead of deleted, default false - "LOAD_WORLD": "world_2021-05-21_15-31-24" // Default: "". Set world folder name that should be loaded on server start instead of deleting/archiving the world. + "AUTO_SAVE": false, // Turn off to prevent 5 minute lag + "KEEP_WORLDS": false, // Turn on if worlds should be renamed instead of deleted + "LOAD_WORLD": "world_2021-05-21_15-31-24", // Set world folder name that should be loaded on server start instead of deleting/archiving the world. + "JAR_NAME": "server.jar" // Set this value in case you use a different jar, e.g. by using a fabric server. } ``` @@ -53,7 +54,8 @@ _Note: Enabling flight will prevent random disconnects when traveling too fast v "SEEDS": [], "AUTO_SAVE": false, "KEEP_WORLDS": false, - "LOAD_WORLD": "" + "LOAD_WORLD": "", + "JAR_NAME": "server.jar" } ``` diff --git a/example/speedrun.json b/example/speedrun.json index 315497d..8994cac 100644 --- a/example/speedrun.json +++ b/example/speedrun.json @@ -7,5 +7,6 @@ "SEEDS": ["-9223372036854775808", "9223372036854775807"], "AUTO_SAVE": false, "KEEP_WORLDS": false, - "LOAD_WORLD": "" + "LOAD_WORLD": "", + "JAR_NAME": "server.jar" } diff --git a/src/adapter/configuration.ts b/src/adapter/configuration.ts index 457f87b..af045c3 100644 --- a/src/adapter/configuration.ts +++ b/src/adapter/configuration.ts @@ -1,11 +1,14 @@ import { Configuration } from "../model/configuration" import { promises } from "fs" +import { validateConfiguration } from "../validation/configuration" +import { ConfigurationApi } from "../model/configurationApi" export async function parseConfiguration(): Promise { console.log("Parsing speedrun.json ...") const json = await promises.readFile("speedrun.json", "utf-8") - const configuration: Configuration = JSON.parse(json) - return useFallbacks(configuration) + const configuration: ConfigurationApi = JSON.parse(json) + validateConfiguration(configuration) + return useFallbacks(configuration as Configuration) } export async function removeSeed(configuration: Configuration) { @@ -14,7 +17,7 @@ export async function removeSeed(configuration: Configuration) { await promises.writeFile("speedrun.json", JSON.stringify(configuration), "utf8") } -async function useFallbacks(configuration: Configuration): Promise { +async function useFallbacks(configuration: ConfigurationApi): Promise { return { MIN_RAM: configuration.MIN_RAM, MAX_RAM: configuration.MAX_RAM, @@ -24,6 +27,7 @@ async function useFallbacks(configuration: Configuration): Promise { + server.kill() + process.exit(1) + }) + server.on("exit", async () => { server.kill() await startServer() diff --git a/src/validation/configuration.spec.ts b/src/validation/configuration.spec.ts index 079b7f1..317d143 100644 --- a/src/validation/configuration.spec.ts +++ b/src/validation/configuration.spec.ts @@ -1,5 +1,5 @@ import { validateConfiguration } from "./configuration" -import { Configuration } from "../model/configuration" +import { ConfigurationApi } from "../model/configurationApi" describe("Configuration", () => { function testShouldFail() { @@ -22,7 +22,7 @@ describe("Configuration", () => { it("should throw an error if mandatory value is missing", () => { const message = "Error during validation. Missing configuration values for: MAX_RAM." - const configuration: Configuration = { MIN_RAM: 4, MAX_RAM: undefined } + const configuration = { MIN_RAM: 4, MAX_RAM: undefined } try { validateConfiguration(configuration) @@ -33,13 +33,13 @@ describe("Configuration", () => { }) it("should not throw an error if configuration is valid", () => { - const configuration: Configuration = { MIN_RAM: 4, MAX_RAM: 8 } + const configuration: ConfigurationApi = { MIN_RAM: 4, MAX_RAM: 8 } validateConfiguration(configuration) }) it("should not throw an error if optional property exists without a value", () => { - const configuration: Configuration = { MIN_RAM: 4, MAX_RAM: 8, DATA_PACK: undefined } + const configuration: ConfigurationApi = { MIN_RAM: 4, MAX_RAM: 8, DATA_PACK: undefined } validateConfiguration(configuration) }) diff --git a/src/validation/configuration.ts b/src/validation/configuration.ts index 53d2b4f..607ea41 100644 --- a/src/validation/configuration.ts +++ b/src/validation/configuration.ts @@ -1,6 +1,6 @@ -import { Configuration } from "../model/configuration" +import { ConfigurationApi } from "../model/configurationApi" -export function validateConfiguration(configuration: Configuration) { +export function validateConfiguration(configuration: ConfigurationApi) { const mandatoryFields = new Set(["MIN_RAM", "MAX_RAM"]) const missingValues = []