Смотрите видео ниже, чтобы узнать, как установить наш сайт в качестве веб-приложения на домашнем экране.
Примечание: This feature may not be available in some browsers.
public class UpdateException extends Exception {
private static final long serialVersionUID = -7371026016860990753L;
private final String message;
private final Updater updater;
public UpdateException(String message, Updater updater) {
super(message);
this.message = message;
this.updater = updater;
}
public void print() {
RepSender.log(printableMessage());
}
public String printableMessage() {
return "Error while trying to check update!";
}
}
public enum UpdateResult {
UPDATE_FOUND, UPDATE_NOT_FOUND;
public boolean hasUpdates() {
return...
Я это понимаю, мне и самому не нравиться. Именно поэтому я планировал что бы эти функции отключались в конфиге. Но мне оно надо. Потому что на сервере для которого я пишу плагины, владелец начал жаловаться что я слишком часто делаю фиксы/обновы и т.п. а ему каждый раз загружать ихне надо пожалуста пожалей юзеров, никто не любит ваши авто апдейты и чекеры
public class UpdateException extends Exception {
private static final long serialVersionUID = -7371026016860990753L;
private final String message;
private final Updater updater;
public UpdateException(String message, Updater updater) {
super(message);
this.message = message;
this.updater = updater;
}
public void print() {
RepSender.log(printableMessage());
}
public String printableMessage() {
return "Error while trying to check update!";
}
}
public enum UpdateResult {
UPDATE_FOUND, UPDATE_NOT_FOUND;
public boolean hasUpdates() {
return this.equals(UPDATE_FOUND);
}
}
public class Updater {
//Base GitHubAPI URL
public static final String BASE_URL = "https://api.github.com/";
//Using for parsing input responses
public static final Gson GSON = new Gson();
//Plugin version
private int currentVersion = 0;
//GitHub repo
private final String repositoryUrl;
public Updater(String user, String repository) {
this.repositoryUrl = "/".concat(user.concat("/").concat(repository).concat("/"));
}
public UpdateResult checkUpdates() throws UpdateException {
if(this.currentVersion == 0) currentVersion = parseVersion();
try {
URL url = new URL(BASE_URL.concat("repos").concat(repositoryUrl).concat("commits"));
JsonObject[] objects = GSON.fromJson(
new BufferedReader(
new InputStreamReader(url.openStream(), Charsets.UTF_8.name())
),
JsonObject[].class);
if(objects.length == 0) {
throw new UpdateException("commits is empty", this);
}
JsonObject object = objects[0];
String[] toParse = object.get("commit").getAsJsonObject().get("message").getAsString().replace(".","").split("\\n");
if(toParse.length == 0) {
throw new UpdateException("commits is empty", this);
}
int version = Integer.parseInt(toParse[0]);
if(version != currentVersion) {
return UpdateResult.UPDATE_FOUND;
}
}catch (IOException | NumberFormatException ignore) { }
return UpdateResult.UPDATE_NOT_FOUND;
}
private int parseVersion() {
try {
return Reputation.getVersion();
}catch (NumberFormatException ignored) { }
return -1;
}
public int getCurrentVersion() {
return currentVersion;
}
}
public class Download {
private static boolean isRedirected( Map<String, List<String>> header ) {
for( String hv : header.get( null )) {
if( hv.contains( " 301 " )
|| hv.contains( " 302 " )) return true;
}
return false;
}
public static void main( String[] args ) throws Throwable
{
String link =
"ссылка" +
"файл.jar";
String fileName = "сохраняемый файл.jar";
URL url = new URL( link );
HttpURLConnection http = (HttpURLConnection)url.openConnection();
Map< String, List< String >> header = http.getHeaderFields();
while( isRedirected( header )) {
link = header.get( "Location" ).get( 0 );
url = new URL( link );
http = (HttpURLConnection)url.openConnection();
header = http.getHeaderFields();
}
InputStream input = http.getInputStream();
byte[] buffer = new byte[4096];
int n = -1;
OutputStream output = new FileOutputStream( new File( fileName ));
while ((n = input.read(buffer)) != -1) {
output.write( buffer, 0, n );
}
output.close();
}
}
Мы используем основные cookies для обеспечения работы этого сайта, а также дополнительные cookies для обеспечения максимального удобства пользователя.
Посмотрите дополнительную информацию и настройте свои предпочтения