Updated code to record the current version being used to allow different code to be run e.g. for 1.12 and 1.13's changes

This commit is contained in:
sekwah41 2018-01-29 11:42:28 +00:00 committed by Sekwah
parent 04fb6c2809
commit d29d668196

View File

@ -21,6 +21,7 @@ public class AdvancedPortalsCore {
private final CommandRegister commandRegister;
private final DataStorage dataStorage;
private final InfoLogger infoLogger;
private final int mcMinorVer;
private WarpEffectRegistry warpEffectRegistry;
private TagRegistry tagRegistry;
@ -38,14 +39,59 @@ public class AdvancedPortalsCore {
public static final String version = "1.0.0";
public static final String lastTranslationUpdate = "1.0.0";
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister) {
/**
*
* @param dataStorage
* @param infoLogger
* @param commandRegister
* @param mcVer Minecraft version e.g. 1.12.2
*/
public AdvancedPortalsCore(DataStorage dataStorage, InfoLogger infoLogger, CommandRegister commandRegister, int[] mcVer) {
this.dataStorage = dataStorage;
this.infoLogger = infoLogger;
this.instance = this;
this.commandRegister = commandRegister;
this.mcMinorVer = this.checkMcVer(mcVer);
this.onEnable();
}
private int checkMcVer(int[] mcVer) {
int maxSupportedVer = 12;
int minSupportedVer = 8;
if(mcVer.length == 2 || mcVer.length == 3) {
if(mcVer[0] == 1) {
if(mcVer[1] < minSupportedVer) {
this.infoLogger.logWarning("Older version of mc detected than officially supported. This is very likely not to work.");
return minSupportedVer;
}
else if (mcVer[1] > maxSupportedVer) {
this.infoLogger.logWarning("Newer version of mc detected than currently supported by this version. The plugin may not work.");
return maxSupportedVer;
}
else {
return mcVer[1];
}
}
else {
this.infoLogger.logWarning("It seems you are using a very strange version of minecraft or something is " +
"seriously wrong with the plugin for getting the version of minecraft.");
return maxSupportedVer;
}
}
else {
String version = String.valueOf(mcVer[0]);
for (int i = 0; i < mcVer.length; i++) {
version += "." + mcVer[i];
}
this.infoLogger.logWarning(version + " is definitely not a valid or currently supported mc version. " +
"Advanced Portals will try to use the newest available logic and see if it works though results " +
"may be unreliable. ");
return maxSupportedVer;
}
}
public static String getTranslationName() {
return instance.config.getTranslation();
}