From cefae0db8993bc09ea05bd06da7d2b52c31a2329 Mon Sep 17 00:00:00 2001 From: sekwah Date: Mon, 22 Jan 2018 22:12:53 +0000 Subject: [PATCH 1/2] Added uppercase first letter on the help menu --- .../advancedportals/core/commands/CommandWithSubCommands.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java b/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java index f8dbecb..6a16aa6 100644 --- a/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java +++ b/src/com/sekwah/advancedportals/core/commands/CommandWithSubCommands.java @@ -57,6 +57,7 @@ public class CommandWithSubCommands implements CommandTemplate { return; } } + commandExecuted = commandExecuted.substring(0,1).toUpperCase() + commandExecuted.substring(1).toLowerCase(); sender.sendMessage(Lang.translateInsertVariablesColor("command.help.header", commandExecuted, helpPage, pages)); int subCommandOffset = (helpPage - 1) * this.subCommandsPerPage; int displayEnd = subCommandOffset + this.subCommandsPerPage; From 5c336000083b54d925c9144389a26b99bc65cf86 Mon Sep 17 00:00:00 2001 From: sekwah Date: Tue, 23 Jan 2018 05:37:16 +0000 Subject: [PATCH 2/2] updated translation and config files --- Resources/lang/en_GB.lang | 8 +++-- .../core/AdvancedPortalsCore.java | 12 ++++++-- .../advancedportals/core/CoreListeners.java | 16 ++++++++++ .../advancedportals/core/util/Config.java | 4 +++ .../core/util/DataStorage.java | 29 +++++++++++++------ .../advancedportals/core/util/Lang.java | 8 ++--- .../container/PlayerContainer.java | 7 +++++ 7 files changed, 66 insertions(+), 18 deletions(-) create mode 100644 src/com/sekwah/advancedportals/core/CoreListeners.java diff --git a/Resources/lang/en_GB.lang b/Resources/lang/en_GB.lang index 3f1d90b..ff608b3 100644 --- a/Resources/lang/en_GB.lang +++ b/Resources/lang/en_GB.lang @@ -11,6 +11,8 @@ # # Also note that some debug messages may not be listed here for translation. # +translatedata.lastchange=1.0.0 +translatedata.translationsoutdated= Some of the translations from the current translation file \u00A7e%1$s\u00A7c are out of date. messageprefix.positive=\u00A7a[\u00A7eAdvancedPortals\u00A7a] messageprefix.negative=\u00A7c[\u00A77AdvancedPortals\u00A7c] @@ -19,9 +21,9 @@ logger.pluginenable=Advanced portals have been successfully enabled! logger.plugindisable=Advanced portals are being disabled! logger.plugincrafterror=This version of craftbukkit is not yet supported or something went wrong, please post this message with the version number and the above stacktrace in an issue on GitHub v:%1$s -command.noargs=Sorry but you need to specify a sub command, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands. +command.noargs= Sorry but you need to specify a sub command, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands. command.help.header=\u00A7e--------- \u00A7a%1$s Help - Page %2$s of %3$s\u00A7e --------------- -command.help.invalidnum=Sorry but \u00A7e%1$s\u00A7c is not a valid page number. +command.help.invalidnum= Sorry but \u00A7e%1$s\u00A7c is not a valid page number. -command.subcommand.nopermission=Sorry but you don't have permission for that, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands. +command.subcommand.nopermission= Sorry but you don't have permission for that, please use \u00A7e/%1$s help \u00A7cif you would like a list of possible sub commands. diff --git a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java index 67adca8..b518142 100644 --- a/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java +++ b/src/com/sekwah/advancedportals/core/AdvancedPortalsCore.java @@ -14,6 +14,8 @@ public class AdvancedPortalsCore { private final DataStorage dataStorage; private final InfoLogger infoLogger; + private final CoreListeners coreListeners; + private Config config; private CommandWithSubCommands portalCommand; @@ -24,13 +26,15 @@ public class AdvancedPortalsCore { this.infoLogger = infoLogger; this.instance = this; this.commandRegister = commandRegister; + this.coreListeners = new CoreListeners(); this.onEnable(); } private void onEnable() { this.dataStorage.copyDefaultFile("lang/en_GB.lang", false); - Lang.loadLanguage("en_GB"); + this.loadPortalConfig(); + Lang.loadLanguage(config.getTranslation()); this.portalCommand = new CommandWithSubCommands(); this.destiCommand = new CommandWithSubCommands(); @@ -45,7 +49,7 @@ public class AdvancedPortalsCore { * (basically if values are missing or whatever) */ private void loadPortalConfig() { - this.config = this.dataStorage.loadJson(Config.class, "config.json", true); + this.config = this.dataStorage.loadJson(Config.class, "config.json"); this.dataStorage.storeJson(this.config, "config.json"); } @@ -64,4 +68,8 @@ public class AdvancedPortalsCore { public static InfoLogger getInfoLogger() { return instance.infoLogger; } + + public CoreListeners getCoreListeners() { + return coreListeners; + } } diff --git a/src/com/sekwah/advancedportals/core/CoreListeners.java b/src/com/sekwah/advancedportals/core/CoreListeners.java new file mode 100644 index 0000000..6e21a3d --- /dev/null +++ b/src/com/sekwah/advancedportals/core/CoreListeners.java @@ -0,0 +1,16 @@ +package com.sekwah.advancedportals.core; + +import com.sekwah.advancedportals.core.util.Lang; +import com.sekwah.advancedportals.coreconnector.container.PlayerContainer; + +public class CoreListeners { + + public void playerJoin(PlayerContainer player) { + if(player.isOp()) { + if(!Lang.translate("translatedata.lastchange").equals("1.0.0")) { + player.sendMessage(Lang.translateColor("messageprefix.negative") + Lang.translateColor("translatedata.translationsoutdated")); + } + } + } + +} diff --git a/src/com/sekwah/advancedportals/core/util/Config.java b/src/com/sekwah/advancedportals/core/util/Config.java index 7593096..192ab2b 100644 --- a/src/com/sekwah/advancedportals/core/util/Config.java +++ b/src/com/sekwah/advancedportals/core/util/Config.java @@ -30,4 +30,8 @@ public class Config { public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) { useOnlySpecialAxe = useOnlyServerMadeAxe; } + + public String getTranslation() { + return translationFile; + } } diff --git a/src/com/sekwah/advancedportals/core/util/DataStorage.java b/src/com/sekwah/advancedportals/core/util/DataStorage.java index 1e5e19d..bc2ce99 100644 --- a/src/com/sekwah/advancedportals/core/util/DataStorage.java +++ b/src/com/sekwah/advancedportals/core/util/DataStorage.java @@ -33,16 +33,28 @@ public class DataStorage { } public T loadJson(Class dataHolder, String location) { - return this.loadJson(dataHolder, location, false); - } - public T loadJson(Class dataHolder, String location, boolean loadDefaultIfMissing) { // TODO get json and if file doesnt exist create default class if true - return gson.fromJson("", dataHolder); + InputStream jsonResource = this.loadResource(location); + if(jsonResource == null) { + try { + return dataHolder.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + return null; + } + BufferedReader bufReader = new BufferedReader(new InputStreamReader(jsonResource)); + return gson.fromJson(bufReader, dataHolder); } public void storeJson(Object dataHolder, String location) { - // TODO do writing code - gson.toJson(dataHolder); + try { + gson.toJson(dataHolder, new FileWriter(new File(this.dataFolder, location))); + } catch (IOException e) { + e.printStackTrace(); + } } /** @@ -89,11 +101,10 @@ public class DataStorage { *

* TODO add loading from the plugin folder first rather than straight from the plugin. * - * @param lang * @param location * @return */ - public InputStream loadResource(Lang lang, String location) { + public InputStream loadResource(String location) { File inFile = new File(dataFolder, location); if (inFile.exists() && !inFile.isDirectory()) { try { @@ -105,7 +116,7 @@ public class DataStorage { } else { try { copyDefaultFile(location, false); - return lang.getClass().getClassLoader().getResourceAsStream(location); + return this.getClass().getClassLoader().getResourceAsStream(location); } catch (NullPointerException e) { e.printStackTrace(); AdvancedPortalsCore.getInfoLogger().logWarning("Could not load " + location + ". The file does" + diff --git a/src/com/sekwah/advancedportals/core/util/Lang.java b/src/com/sekwah/advancedportals/core/util/Lang.java index 5279d91..3a9e605 100644 --- a/src/com/sekwah/advancedportals/core/util/Lang.java +++ b/src/com/sekwah/advancedportals/core/util/Lang.java @@ -21,11 +21,11 @@ public class Lang { private static final Lang instance = new Lang(); private final HashMap languageMap = new HashMap<>(); - private final String DEFAULT_LANG = "en_GB"; + //private final String DEFAULT_LANG = "en_GB"; - public Lang() { + /*public Lang() { injectTranslations(this, DEFAULT_LANG); - } + }*/ public static void loadLanguage(String fileName) { instance.injectTranslations(instance, fileName); @@ -66,7 +66,7 @@ public class Lang { //URL url = lang.getClass().getClassLoader().getResource("lang/" + fileName + ".lang"); //System.out.println(url); //Map newLangMap = lang.parseLang(url.openStream()); - InputStream stream = AdvancedPortalsCore.getDataStorage().loadResource(lang, "lang/" + fileName + ".lang"); + InputStream stream = AdvancedPortalsCore.getDataStorage().loadResource("lang/" + fileName + ".lang"); if (stream != null) { Map newLangMap = lang.parseLang(stream); if (newLangMap != null) { diff --git a/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java b/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java index 2f2ea07..7755a31 100644 --- a/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java +++ b/src/com/sekwah/advancedportals/coreconnector/container/PlayerContainer.java @@ -8,4 +8,11 @@ public class PlayerContainer { public String getUUID() { return ""; } + + public void sendMessage(String message) { + } + + public boolean isOp() { + return false; + } }