Merge branch 'master' into spigot

This commit is contained in:
sekwah 2018-01-23 05:37:42 +00:00
commit 5433baea0b
8 changed files with 67 additions and 18 deletions

View File

@ -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.

View File

@ -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;
}
}

View File

@ -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"));
}
}
}
}

View File

@ -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;

View File

@ -30,4 +30,8 @@ public class Config {
public void setUseOnlySpecialAxe(boolean useOnlyServerMadeAxe) {
useOnlySpecialAxe = useOnlyServerMadeAxe;
}
public String getTranslation() {
return translationFile;
}
}

View File

@ -33,16 +33,28 @@ public class DataStorage {
}
public <T> T loadJson(Class<T> dataHolder, String location) {
return this.loadJson(dataHolder, location, false);
}
public <T> T loadJson(Class<T> 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 {
* <p>
* 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" +

View File

@ -21,11 +21,11 @@ public class Lang {
private static final Lang instance = new Lang();
private final HashMap<String, String> 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<String, String> 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<String, String> newLangMap = lang.parseLang(stream);
if (newLangMap != null) {

View File

@ -8,4 +8,11 @@ public class PlayerContainer {
public String getUUID() {
return "";
}
public void sendMessage(String message) {
}
public boolean isOp() {
return false;
}
}