mirror of
https://github.com/NoCheatPlus/NoCheatPlus.git
synced 2025-01-02 13:57:49 +01:00
Config version check back in, prepare update checking.
This commit is contained in:
parent
def16174da
commit
994ccc681f
@ -47,6 +47,7 @@ import fr.neatmonster.nocheatplus.players.Permissions;
|
||||
import fr.neatmonster.nocheatplus.utilities.BlockProperties;
|
||||
import fr.neatmonster.nocheatplus.utilities.LagMeasureTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.TickTask;
|
||||
import fr.neatmonster.nocheatplus.utilities.Updates;
|
||||
|
||||
/*
|
||||
* M"""""""`YM MM'""""'YMM dP dP MM"""""""`YM dP
|
||||
@ -295,35 +296,17 @@ public class NoCheatPlus extends JavaPlugin implements Listener {
|
||||
|
||||
// if (config.getBoolean(ConfPaths.MISCELLANEOUS_CHECKFORUPDATES)){
|
||||
// // Is a new update available?
|
||||
// BufferedReader bufferedReader = null;
|
||||
// updateAvailable = false;
|
||||
// try {
|
||||
// final String[] split = getDescription().getVersion().split("-b");
|
||||
// final int currentVersion = Integer.parseInt(split[split.length - 1]);
|
||||
// final URL url = new URL("http://nocheatplus.org:8080/job/NoCheatPlus/lastSuccessfulBuild/api/json");
|
||||
// connection.setReadTimeout(config.getInt(ConfPaths.MISCELLANEOUS_READTIMEOUT, 4) * 1000);
|
||||
// final URLConnection connection = url.openConnection();
|
||||
//
|
||||
// bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
// String line, content = "";
|
||||
// while ((line = bufferedReader.readLine()) != null)
|
||||
// content += line;
|
||||
// final int jenkinsVersion = Integer.parseInt(content.split("\"number\":")[1].split(",")[0]);
|
||||
// updateAvailable = currentVersion < jenkinsVersion;
|
||||
// } catch (final Exception e) {}
|
||||
// finally{
|
||||
// if (bufferedReader != null) try{bufferedReader.close();}catch (IOException e){};
|
||||
// }
|
||||
// final int timeout = config.getInt(ConfPaths.MISCELLANEOUS_UPDATETIMEOUT, 4) * 1000;
|
||||
// getServer().getScheduler().scheduleAsyncDelayedTask(this, new Runnable() {
|
||||
// @Override
|
||||
// public void run() {
|
||||
// updateAvailable = Updates.CheckForUpdatesTask(getDescription().getVersion(), timeout);
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
|
||||
// // Is the configuration outdated?
|
||||
// try {
|
||||
// final int currentVersion = Integer.parseInt(getDescription().getVersion().split("-b")[1]);
|
||||
// final int configurationVersion = Integer.parseInt(
|
||||
// config.options().header().split("-b")[1].split("\\.")[0]);
|
||||
// if (currentVersion > configurationVersion)
|
||||
// configOutdated = true;
|
||||
// } catch (final Exception e) {}
|
||||
// Is the configuration outdated?
|
||||
configOutdated = Updates.isConfigOutdated(getDescription().getVersion(), config);
|
||||
|
||||
// Debug information about unknown blocks.
|
||||
// (Probably removed later.)
|
||||
|
@ -47,8 +47,8 @@ public abstract class ConfPaths {
|
||||
public static final String MISCELLANEOUS_ALLOWCLIENTMODS = MISCELLANEOUS + "allowclientmods";
|
||||
public static final String MISCELLANEOUS_OPINCONSOLEONLY = MISCELLANEOUS + "opinconsoleonly";
|
||||
public static final String MISCELLANEOUS_PROTECTPLUGINS = MISCELLANEOUS + "protectplugins";
|
||||
// public static final String MISCELLANEOUS_CHECKFORUPDATES = MISCELLANEOUS + "checkforupdates";
|
||||
// public static final String MISCELLANEOUS_READTIMEOUT = MISCELLANEOUS + "readtimeout";
|
||||
public static final String MISCELLANEOUS_CHECKFORUPDATES = MISCELLANEOUS + "checkforupdates";
|
||||
public static final String MISCELLANEOUS_UPDATETIMEOUT = MISCELLANEOUS + "updatetimeout";
|
||||
public static final String MISCELLANEOUS_REPORTTOMETRICS = MISCELLANEOUS + "reporttometrics";
|
||||
private static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY = MISCELLANEOUS + "nomovedtooquickly.";
|
||||
public static final String MISCELLANEOUS_NOMOVEDTOOQUICKLY_ENABLED = MISCELLANEOUS_NOMOVEDTOOQUICKLY + "enabled";
|
||||
|
58
src/fr/neatmonster/nocheatplus/utilities/Updates.java
Normal file
58
src/fr/neatmonster/nocheatplus/utilities/Updates.java
Normal file
@ -0,0 +1,58 @@
|
||||
package fr.neatmonster.nocheatplus.utilities;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
|
||||
import fr.neatmonster.nocheatplus.config.ConfigFile;
|
||||
|
||||
public class Updates {
|
||||
|
||||
/**
|
||||
*
|
||||
* @param versionString Current version string (getDescription().getVersion()).
|
||||
* @param config
|
||||
* @return
|
||||
*/
|
||||
public static boolean isConfigOutdated(String versionString, ConfigFile config){
|
||||
try {
|
||||
final int currentVersion = Integer.parseInt(versionString.split("-b")[1]);
|
||||
final int configurationVersion = Integer.parseInt(
|
||||
config.options().header().split("-b")[1].split("\\.")[0]);
|
||||
if (currentVersion > configurationVersion)
|
||||
return true;
|
||||
} catch (final Exception e) {}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* To be called from an async task.
|
||||
* @param versionString Current version string (getDescription().getVersion()).
|
||||
* @param updateTimeout
|
||||
* @return
|
||||
*/
|
||||
public static boolean CheckForUpdatesTask(String versionString, int updateTimeout) {
|
||||
BufferedReader bufferedReader = null;
|
||||
boolean updateAvailable = false;
|
||||
try {
|
||||
final String[] split = versionString.split("-b");
|
||||
final int currentVersion = Integer.parseInt(split[split.length - 1]);
|
||||
final URL url = new URL("http://nocheatplus.org:8080/job/NoCheatPlus/lastSuccessfulBuild/api/json");
|
||||
final URLConnection connection = url.openConnection();
|
||||
connection.setConnectTimeout(updateTimeout);
|
||||
connection.setReadTimeout(2 * updateTimeout);
|
||||
bufferedReader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
|
||||
String line, content = "";
|
||||
while ((line = bufferedReader.readLine()) != null)
|
||||
content += line;
|
||||
final int jenkinsVersion = Integer.parseInt(content.split("\"number\":")[1].split(",")[0]);
|
||||
updateAvailable = currentVersion < jenkinsVersion;
|
||||
} catch (final Exception e) {}
|
||||
finally{
|
||||
if (bufferedReader != null) try{bufferedReader.close();}catch (IOException e){};
|
||||
}
|
||||
return updateAvailable;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user