From 1c94ced87556e4cd14032b58ce2abcad04ca6e84 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 6 Feb 2020 11:37:13 +0100 Subject: [PATCH 1/3] [wip] Try to load i18n file with utf-8 encoding --- build.gradle | 4 +- .../chunkmaster/lib/LanguageManager.kt | 22 ++++++-- .../resources/i18n/DEFAULT.i18n.properties | 44 ++++++++-------- src/main/resources/i18n/de.i18n.properties | 52 +++++++++---------- src/main/resources/i18n/en.i18n.properties | 44 ++++++++-------- src/main/resources/plugin.yml | 2 +- 6 files changed, 92 insertions(+), 76 deletions(-) diff --git a/build.gradle b/build.gradle index 247b88c..d2538ec 100644 --- a/build.gradle +++ b/build.gradle @@ -22,7 +22,7 @@ idea { } group "net.trivernis" -version "0.14-beta" +version "0.15-beta" sourceCompatibility = 1.8 @@ -53,6 +53,8 @@ dependencies { compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0' compile "io.papermc:paperlib:1.0.2" compile "org.bstats:bstats-bukkit:1.5" + compile "org.apache.commons:commons-lang3:3.9" + compile "org.apache.commons:commons-io:1.3.2" } apply plugin: "com.github.johnrengelman.shadow" diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt index da48546..de4ee97 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt @@ -1,9 +1,13 @@ package net.trivernis.chunkmaster.lib import net.trivernis.chunkmaster.Chunkmaster -import java.io.BufferedReader import java.io.File import java.lang.Exception import java.util.Properties +import org.apache.commons.io.IOUtils +import org.apache.commons.lang.StringEscapeUtils +import java.io.InputStream +import java.io.StringReader +import java.io.StringWriter class LanguageManager(private val plugin: Chunkmaster) { private val langProps = Properties() @@ -22,7 +26,7 @@ class LanguageManager(private val plugin: Chunkmaster) { val loader = Thread.currentThread().contextClassLoader val defaultStream = this.javaClass.getResourceAsStream("/i18n/DEFAULT.i18n.properties") if (defaultStream != null) { - langProps.load(defaultStream) + langProps.load(getReaderForProperties(defaultStream)) defaultStream.close() } else { plugin.logger.severe("Couldn't load default language properties.") @@ -31,7 +35,7 @@ class LanguageManager(private val plugin: Chunkmaster) { try { val inputStream = loader.getResourceAsStream(langFile) if (inputStream != null) { - langProps.load(inputStream) + langProps.load(getReaderForProperties(inputStream)) langFileLoaded = true inputStream.close() } @@ -42,7 +46,7 @@ class LanguageManager(private val plugin: Chunkmaster) { } else { val inputStream = this.javaClass.getResourceAsStream("/i18n/$language.i18n.properties") if (inputStream != null) { - langProps.load(inputStream) + langProps.load(getReaderForProperties(inputStream)) langFileLoaded = true inputStream.close() } else { @@ -58,4 +62,14 @@ class LanguageManager(private val plugin: Chunkmaster) { val localizedString = langProps.getProperty(key) return String.format(localizedString, *replacements) } + + /** + * Reads a properties file as utf-8 and returns a string reader for the contents + */ + private fun getReaderForProperties(stream: InputStream): StringReader { + val writer = StringWriter(); + IOUtils.copy(stream, writer, "UTF-8") + val escapedStringContent = StringEscapeUtils.escapeJava(writer.toString()) + return StringReader(escapedStringContent) + } } \ No newline at end of file diff --git a/src/main/resources/i18n/DEFAULT.i18n.properties b/src/main/resources/i18n/DEFAULT.i18n.properties index e0771de..a692811 100644 --- a/src/main/resources/i18n/DEFAULT.i18n.properties +++ b/src/main/resources/i18n/DEFAULT.i18n.properties @@ -1,48 +1,48 @@ RESUME_FOR_WORLD = Resuming chunk generation task for world '%s'... TASK_FINISHED = Task #%d finished after %d chunks. TASK_CANCELED = Canceled task #%s. -TASK_LOAD_FAILED = \u00A7cFailed to load task #%d. +TASK_LOAD_FAILED = §cFailed to load task #%d. TASK_LOAD_SUCCESS = %d saved tasks loaded. -TASK_NOT_FOUND = \u00A7cTask %s not found! +TASK_NOT_FOUND = §cTask %s not found! CREATE_DELAYED_LOAD = Creating task to load chunk generation Tasks later... TASK_PERIODIC_REPORT = Task #%d running for '%s'. Progress: %d chunks %s %s, Speed: %.1f ch/s, Last Chunk: %d, %d -TASK_SAVE_FAILED = \u00A7cException when saving tasks: %s +TASK_SAVE_FAILED = §cException when saving tasks: %s -WORLD_NAME_REQUIRED = \u00A7cYou need to provide a world name! -WORLD_NOT_FOUND = \u00A7cWorld \u00A72%s \u00A7cnot found! -TASK_ALREADY_EXISTS = \u00A7cA task for '%s' already exists! -TASK_CREATION_SUCCESS = \u00A79Generation Task for world \u00A72%s \u00A79 until \u00A72%s \u00A79successfully created! -TASK_ID_REQUIRED = \u00A7cYou need to provide a task id! +WORLD_NAME_REQUIRED = §cYou need to provide a world name! +WORLD_NOT_FOUND = §cWorld §2%s §cnot found! +TASK_ALREADY_EXISTS = §cA task for '%s' already exists! +TASK_CREATION_SUCCESS = §9Generation Task for world §2%s §9 until §2%s §9successfully created! +TASK_ID_REQUIRED = §cYou need to provide a task id! PAUSED_TASKS_HEADER = Currently Paused Generation Tasks -TASKS_ENTRY = - \u00A79#%d\u00A7r - \u00A72%s\u00A7r - \u00A72%d chunks %s\u00A7r +TASKS_ENTRY = - §9#%d§r - §2%s§r - §2%d chunks %s§r RUNNING_TASKS_HEADER = Currently Running Generation Tasks NO_GENERATION_TASKS = There are no generation tasks. -PAUSE_SUCCESS = \u00A79Paused all generation tasks. -ALREADY_PAUSED = \u00A7cThe generation process is already paused! +PAUSE_SUCCESS = §9Paused all generation tasks. +ALREADY_PAUSED = §cThe generation process is already paused! -RESUME_SUCCESS = \u00A79Resumed all generation Tasks. -NOT_PAUSED = \u00A7cThe generation process is not paused! +RESUME_SUCCESS = §9Resumed all generation Tasks. +NOT_PAUSED = §cThe generation process is not paused! CONFIG_RELOADING = Reloading the config file... -CONFIG_RELOADED = \u00A72The config file has been reloaded! +CONFIG_RELOADED = §2The config file has been reloaded! -TELEPORTED = \u00A79You have been teleported to chunk \u00A72%s, %s -TP_ONLY_PLAYER = \u00A7cThis command can only be executed by a player! +TELEPORTED = §9You have been teleported to chunk §2%s, %s +TP_ONLY_PLAYER = §cThis command can only be executed by a player! -NO_PERMISSION = \u00A7cYou do not have the permission for this command! -SUBCOMMAND_NOT_FOUND = \u00A7cSubcommand \u00A72%s \u00A7cnot found! +NO_PERMISSION = §cYou do not have the permission for this command! +SUBCOMMAND_NOT_FOUND = §cSubcommand §2%s §cnot found! STOPPING_ALL_TASKS = Stopping all generation tasks... DB_INIT = Initializing database... DB_INIT_FINISHED = Database fully initialized. DB_INIT_EROR = Failed to init database: %s. -DATABASE_CONNECTION_ERROR = \u00A7cCould not get the database connection! -SQL_ERROR = \u00A7cAn eror occured on sql %s! -NO_DATABASE_CONNECTION = \u00A7cCould not execute sql: No database connection. +DATABASE_CONNECTION_ERROR = §cCould not get the database connection! +SQL_ERROR = §cAn eror occured on sql %s! +NO_DATABASE_CONNECTION = §cCould not execute sql: No database connection. CREATE_TABLE_DEFINITION = Created table %s with definition %s. -TABLE_CREATE_ERROR = \u00A7cError when creation table %s. +TABLE_CREATE_ERROR = §cError when creation table %s. UPDATE_TABLE_DEFINITION = Updated table %s with sql %s. UPDATE_TABLE_FAILED = Failed to update table %s with sql %s. \ No newline at end of file diff --git a/src/main/resources/i18n/de.i18n.properties b/src/main/resources/i18n/de.i18n.properties index e1ee078..307800b 100644 --- a/src/main/resources/i18n/de.i18n.properties +++ b/src/main/resources/i18n/de.i18n.properties @@ -1,48 +1,48 @@ -RESUME_FOR_WORLD = Setze das Chunk-Generieren f\u00fcr Welt '%s' fort... +RESUME_FOR_WORLD = Setze das Chunk-Generieren für Welt '%s' fort... TASK_FINISHED = Aufgabe #%d wurde nach %d chunks beendet. TASK_CANCELED = Aufgabe #%s wurde abgebrochen. -TASK_LOAD_FAILED = \u00A7cAufgabe #%d konnte nicht geladen werden. +TASK_LOAD_FAILED = §cAufgabe #%d konnte nicht geladen werden. TASK_LOAD_SUCCESS = %d gespeicherte Aufgaben wurden geladen. -TASK_NOT_FOUND = \u00A7cAufgabe %s konnte nicht gefunden werden! -CREATE_DELAYED_LOAD = Erstelle einen Bukkit-Task zum verz\u00f6gerten Laden von Aufgaben... -TASK_PERIODIC_REPORT = Aufgabe #%d f\u00fcr Welt '%s'. Fortschritt: %d chunks %s %s, Geschwindigkeit: %.1f ch/s, Letzer Chunk: %d, %d -TASK_SAVE_FAILED = \u00A7cFehler beim Speichern der Aufgaben: %s +TASK_NOT_FOUND = §cAufgabe %s konnte nicht gefunden werden! +CREATE_DELAYED_LOAD = Erstelle einen Bukkit-Task zum verzögerten Laden von Aufgaben... +TASK_PERIODIC_REPORT = Aufgabe #%d für Welt '%s'. Fortschritt: %d chunks %s %s, Geschwindigkeit: %.1f ch/s, Letzer Chunk: %d, %d +TASK_SAVE_FAILED = §cFehler beim Speichern der Aufgaben: %s -WORLD_NAME_REQUIRED = \u00A7cDu musst einen Weltennamen angeben! -WORLD_NOT_FOUND = \u00A7c Die Welt \u00A72%s \u00A7cwurde nicht gefunden! -TASK_ALREADY_EXISTS = \u00A7cEs existiert bereits eine Aufgabe f\u00fcr \u00A72%s\u00A7c! -TASK_CREATION_SUCCESS = \u00A79Generierungs-Aufgabe \u00A72%s \u00A79 bis \u00A72%s \u00A79wurde erfolgreich erstellt! -TASK_ID_REQUIRED = \u00A7cDu musst eine Aufgaben-Id angeben! +WORLD_NAME_REQUIRED = §cDu musst einen Weltennamen angeben! +WORLD_NOT_FOUND = §c Die Welt §2%s §cwurde nicht gefunden! +TASK_ALREADY_EXISTS = §cEs existiert bereits eine Aufgabe für §2%s§c! +TASK_CREATION_SUCCESS = §9Generierungs-Aufgabe §2%s §9 bis §2%s §9wurde erfolgreich erstellt! +TASK_ID_REQUIRED = §cDu musst eine Aufgaben-Id angeben! -PAUSED_TASKS_HEADER = \u00A7lPausierte Generierungsaufgaben\u00A7r +PAUSED_TASKS_HEADER = §lPausierte Generierungsaufgaben§r -RUNNING_TASKS_HEADER = \u00A7lLaufende Generierungsaufgaben\u00A7r +RUNNING_TASKS_HEADER = §lLaufende Generierungsaufgaben§r NO_GENERATION_TASKS = Es gibt keine Aufgaben. -PAUSE_SUCCESS = \u00A79Alle Aufgaben wurden pausiert. -ALREADY_PAUSED = \u00A7cDas Generieren ist bereits pausiert. +PAUSE_SUCCESS = §9Alle Aufgaben wurden pausiert. +ALREADY_PAUSED = §cDas Generieren ist bereits pausiert. -RESUME_SUCCESS = \u00A79Alle Aufgaben wurden fortgesetzt. -NOT_PAUSED = \u00A7cEs gibt keine pausierten Aufgaben! +RESUME_SUCCESS = §9Alle Aufgaben wurden fortgesetzt. +NOT_PAUSED = §cEs gibt keine pausierten Aufgaben! CONFIG_RELOADING = Die Konfigurationsdatei wird neu eingelesen... -CONFIG_RELOADED = \u00A72Die Konfigurationsdatei wurde neu geladen! +CONFIG_RELOADED = §2Die Konfigurationsdatei wurde neu geladen! -TELEPORTED = \u00A79Du wurdest zum Chunk \u00A72%s, %s \u00A79teleportiert -TP_ONLY_PLAYER = \u00A7cDieser Befehl kann nur von einem Spieler ausgef\u00fchrt werden. +TELEPORTED = §9Du wurdest zum Chunk §2%s, %s §9teleportiert +TP_ONLY_PLAYER = §cDieser Befehl kann nur von einem Spieler ausgeführt werden. -NO_PERMISSION = \u00A7cDu hast nicht die Rechte für diesen Befehl! -SUBCOMMAND_NOT_FOUND = \u00A7cUnteraktion \u00A72%s \u00A7cwurde nicht gefunden! +NO_PERMISSION = §cDu hast nicht die Rechte für diesen Befehl! +SUBCOMMAND_NOT_FOUND = §cUnteraktion §2%s §cwurde nicht gefunden! STOPPING_ALL_TASKS = Stoppt alle Aufgaben... DB_INIT = Initialisiere Datenbank... DB_INIT_FINISHED = Die Datenbank wurde initialisiert. DB_INIT_EROR = Fehler beim Initalisieren der Datenbank: %s. -DATABASE_CONNECTION_ERROR = \u00A7cDie Datenbankverbindung konnte nicht erzeugt werden. -SQL_ERROR = \u00A7cEin Fehler trat mit sql %s auf! -NO_DATABASE_CONNECTION = \u00A7cSql konnte nicht ausgef\u00fchrt werden: Keine Datenbankverbindung. +DATABASE_CONNECTION_ERROR = §cDie Datenbankverbindung konnte nicht erzeugt werden. +SQL_ERROR = §cEin Fehler trat mit sql %s auf! +NO_DATABASE_CONNECTION = §cSql konnte nicht ausgeführt werden: Keine Datenbankverbindung. CREATE_TABLE_DEFINITION = Tabelle %s mit Definition %s wurde erstellt. -TABLE_CREATE_ERROR = \u00A7cFehler beim erstellen der Tabelle %s. +TABLE_CREATE_ERROR = §cFehler beim erstellen der Tabelle %s. UPDATE_TABLE_DEFINITION = Tabelle %s wurde mit sql %s geupdated. UPDATE_TABLE_FAILED = Fehler beim Updaten der Tabelle %s mit sql %s. \ No newline at end of file diff --git a/src/main/resources/i18n/en.i18n.properties b/src/main/resources/i18n/en.i18n.properties index e0771de..a692811 100644 --- a/src/main/resources/i18n/en.i18n.properties +++ b/src/main/resources/i18n/en.i18n.properties @@ -1,48 +1,48 @@ RESUME_FOR_WORLD = Resuming chunk generation task for world '%s'... TASK_FINISHED = Task #%d finished after %d chunks. TASK_CANCELED = Canceled task #%s. -TASK_LOAD_FAILED = \u00A7cFailed to load task #%d. +TASK_LOAD_FAILED = §cFailed to load task #%d. TASK_LOAD_SUCCESS = %d saved tasks loaded. -TASK_NOT_FOUND = \u00A7cTask %s not found! +TASK_NOT_FOUND = §cTask %s not found! CREATE_DELAYED_LOAD = Creating task to load chunk generation Tasks later... TASK_PERIODIC_REPORT = Task #%d running for '%s'. Progress: %d chunks %s %s, Speed: %.1f ch/s, Last Chunk: %d, %d -TASK_SAVE_FAILED = \u00A7cException when saving tasks: %s +TASK_SAVE_FAILED = §cException when saving tasks: %s -WORLD_NAME_REQUIRED = \u00A7cYou need to provide a world name! -WORLD_NOT_FOUND = \u00A7cWorld \u00A72%s \u00A7cnot found! -TASK_ALREADY_EXISTS = \u00A7cA task for '%s' already exists! -TASK_CREATION_SUCCESS = \u00A79Generation Task for world \u00A72%s \u00A79 until \u00A72%s \u00A79successfully created! -TASK_ID_REQUIRED = \u00A7cYou need to provide a task id! +WORLD_NAME_REQUIRED = §cYou need to provide a world name! +WORLD_NOT_FOUND = §cWorld §2%s §cnot found! +TASK_ALREADY_EXISTS = §cA task for '%s' already exists! +TASK_CREATION_SUCCESS = §9Generation Task for world §2%s §9 until §2%s §9successfully created! +TASK_ID_REQUIRED = §cYou need to provide a task id! PAUSED_TASKS_HEADER = Currently Paused Generation Tasks -TASKS_ENTRY = - \u00A79#%d\u00A7r - \u00A72%s\u00A7r - \u00A72%d chunks %s\u00A7r +TASKS_ENTRY = - §9#%d§r - §2%s§r - §2%d chunks %s§r RUNNING_TASKS_HEADER = Currently Running Generation Tasks NO_GENERATION_TASKS = There are no generation tasks. -PAUSE_SUCCESS = \u00A79Paused all generation tasks. -ALREADY_PAUSED = \u00A7cThe generation process is already paused! +PAUSE_SUCCESS = §9Paused all generation tasks. +ALREADY_PAUSED = §cThe generation process is already paused! -RESUME_SUCCESS = \u00A79Resumed all generation Tasks. -NOT_PAUSED = \u00A7cThe generation process is not paused! +RESUME_SUCCESS = §9Resumed all generation Tasks. +NOT_PAUSED = §cThe generation process is not paused! CONFIG_RELOADING = Reloading the config file... -CONFIG_RELOADED = \u00A72The config file has been reloaded! +CONFIG_RELOADED = §2The config file has been reloaded! -TELEPORTED = \u00A79You have been teleported to chunk \u00A72%s, %s -TP_ONLY_PLAYER = \u00A7cThis command can only be executed by a player! +TELEPORTED = §9You have been teleported to chunk §2%s, %s +TP_ONLY_PLAYER = §cThis command can only be executed by a player! -NO_PERMISSION = \u00A7cYou do not have the permission for this command! -SUBCOMMAND_NOT_FOUND = \u00A7cSubcommand \u00A72%s \u00A7cnot found! +NO_PERMISSION = §cYou do not have the permission for this command! +SUBCOMMAND_NOT_FOUND = §cSubcommand §2%s §cnot found! STOPPING_ALL_TASKS = Stopping all generation tasks... DB_INIT = Initializing database... DB_INIT_FINISHED = Database fully initialized. DB_INIT_EROR = Failed to init database: %s. -DATABASE_CONNECTION_ERROR = \u00A7cCould not get the database connection! -SQL_ERROR = \u00A7cAn eror occured on sql %s! -NO_DATABASE_CONNECTION = \u00A7cCould not execute sql: No database connection. +DATABASE_CONNECTION_ERROR = §cCould not get the database connection! +SQL_ERROR = §cAn eror occured on sql %s! +NO_DATABASE_CONNECTION = §cCould not execute sql: No database connection. CREATE_TABLE_DEFINITION = Created table %s with definition %s. -TABLE_CREATE_ERROR = \u00A7cError when creation table %s. +TABLE_CREATE_ERROR = §cError when creation table %s. UPDATE_TABLE_DEFINITION = Updated table %s with sql %s. UPDATE_TABLE_FAILED = Failed to update table %s with sql %s. \ No newline at end of file diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index dee18cb..19804bf 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ main: net.trivernis.chunkmaster.Chunkmaster name: Chunkmaster -version: '0.14-beta' +version: '0.15-beta' description: Chunk commands plugin. author: Trivernis website: trivernis.net From e5f812e3bc5542d86193e8170279689fe2626d72 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 6 Feb 2020 20:15:32 +0100 Subject: [PATCH 2/3] Fix unicode loading of i18n files --- .../net/trivernis/chunkmaster/lib/LanguageManager.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt index de4ee97..6fbf156 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt @@ -1,13 +1,10 @@ package net.trivernis.chunkmaster.lib import net.trivernis.chunkmaster.Chunkmaster -import java.io.File import java.lang.Exception import java.util.Properties import org.apache.commons.io.IOUtils import org.apache.commons.lang.StringEscapeUtils -import java.io.InputStream -import java.io.StringReader -import java.io.StringWriter +import java.io.* class LanguageManager(private val plugin: Chunkmaster) { private val langProps = Properties() @@ -66,10 +63,7 @@ class LanguageManager(private val plugin: Chunkmaster) { /** * Reads a properties file as utf-8 and returns a string reader for the contents */ - private fun getReaderForProperties(stream: InputStream): StringReader { - val writer = StringWriter(); - IOUtils.copy(stream, writer, "UTF-8") - val escapedStringContent = StringEscapeUtils.escapeJava(writer.toString()) - return StringReader(escapedStringContent) + private fun getReaderForProperties(stream: InputStream): Reader { + return BufferedReader(InputStreamReader(stream, "UTF-8")) } } \ No newline at end of file From 109699f6396d429919deaf6d1f99189900b45957 Mon Sep 17 00:00:00 2001 From: trivernis Date: Thu, 6 Feb 2020 20:18:48 +0100 Subject: [PATCH 3/3] Remove unused dependencies --- build.gradle | 2 -- .../kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt | 2 -- 2 files changed, 4 deletions(-) diff --git a/build.gradle b/build.gradle index d2538ec..e9148c8 100644 --- a/build.gradle +++ b/build.gradle @@ -53,8 +53,6 @@ dependencies { compile group: 'org.xerial', name: 'sqlite-jdbc', version: '3.28.0' compile "io.papermc:paperlib:1.0.2" compile "org.bstats:bstats-bukkit:1.5" - compile "org.apache.commons:commons-lang3:3.9" - compile "org.apache.commons:commons-io:1.3.2" } apply plugin: "com.github.johnrengelman.shadow" diff --git a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt index 6fbf156..467cdfa 100644 --- a/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt +++ b/src/main/kotlin/net/trivernis/chunkmaster/lib/LanguageManager.kt @@ -2,8 +2,6 @@ package net.trivernis.chunkmaster.lib import net.trivernis.chunkmaster.Chunkmaster import java.lang.Exception import java.util.Properties -import org.apache.commons.io.IOUtils -import org.apache.commons.lang.StringEscapeUtils import java.io.* class LanguageManager(private val plugin: Chunkmaster) {