2020-04-16 04:52:39 +02:00
|
|
|
/*
|
|
|
|
* _____ _ _ _____ _
|
|
|
|
* | __ \| | | | / ____| | |
|
|
|
|
* | |__) | | ___ | |_| (___ __ _ _ _ __ _ _ __ ___ __| |
|
|
|
|
* | ___/| |/ _ \| __|\___ \ / _` | | | |/ _` | '__/ _ \/ _` |
|
|
|
|
* | | | | (_) | |_ ____) | (_| | |_| | (_| | | | __/ (_| |
|
|
|
|
* |_| |_|\___/ \__|_____/ \__, |\__,_|\__,_|_| \___|\__,_|
|
|
|
|
* | |
|
|
|
|
* |_|
|
|
|
|
* PlotSquared plot management system for Minecraft
|
|
|
|
* Copyright (C) 2020 IntellectualSites
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-04-11 02:19:18 +02:00
|
|
|
package com.plotsquared.bukkit.util;
|
2020-02-16 01:33:43 +01:00
|
|
|
|
2020-04-15 21:26:54 +02:00
|
|
|
import com.plotsquared.core.PlotSquared;
|
|
|
|
import com.plotsquared.core.config.Captions;
|
|
|
|
import com.plotsquared.core.config.Settings;
|
2020-02-16 01:33:43 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
import org.bukkit.plugin.java.JavaPlugin;
|
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
|
|
|
|
import javax.net.ssl.HttpsURLConnection;
|
|
|
|
import java.io.BufferedReader;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.InputStreamReader;
|
|
|
|
import java.net.URL;
|
|
|
|
|
|
|
|
public class UpdateUtility implements Listener {
|
|
|
|
|
2020-02-16 02:34:51 +01:00
|
|
|
public static String internalVersion;
|
|
|
|
public static String spigotVersion;
|
|
|
|
public final JavaPlugin javaPlugin;
|
2020-02-16 01:33:43 +01:00
|
|
|
|
|
|
|
public UpdateUtility(final JavaPlugin javaPlugin) {
|
|
|
|
this.javaPlugin = javaPlugin;
|
2020-02-16 02:34:51 +01:00
|
|
|
internalVersion = javaPlugin.getDescription().getVersion();
|
2020-02-16 01:33:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void updateChecker() {
|
|
|
|
new BukkitRunnable() {
|
|
|
|
public void run() {
|
|
|
|
Bukkit.getScheduler().runTaskAsynchronously(UpdateUtility.this.javaPlugin, () -> {
|
|
|
|
if (Settings.Enabled_Components.UPDATE_NOTIFICATIONS) {
|
|
|
|
try {
|
|
|
|
HttpsURLConnection connection = (HttpsURLConnection) new URL("https://api.spigotmc.org/legacy/update.php?resource=1177").openConnection();
|
|
|
|
connection.setRequestMethod("GET");
|
2020-02-16 02:34:51 +01:00
|
|
|
spigotVersion = (new BufferedReader(new InputStreamReader(connection.getInputStream()))).readLine();
|
2020-02-16 01:33:43 +01:00
|
|
|
} catch (IOException e) {
|
2020-04-11 02:19:18 +02:00
|
|
|
PlotSquared.log(
|
|
|
|
Captions.PREFIX + "&cUnable to check for updates because: " + e);
|
2020-02-16 01:33:43 +01:00
|
|
|
this.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-02-16 02:34:51 +01:00
|
|
|
if (!internalVersion.equals(spigotVersion)) {
|
2020-02-16 01:33:43 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "&6There appears to be a PlotSquared update available!");
|
2020-02-16 14:37:07 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "&6You are running version " + internalVersion + ", &6latest version is " + spigotVersion);
|
2020-02-16 01:33:43 +01:00
|
|
|
PlotSquared.log(Captions.PREFIX + "&6https://www.spigotmc.org/resources/1177/updates");
|
|
|
|
} else {
|
|
|
|
PlotSquared.log(Captions.PREFIX + "Congratulations! You are running the latest PlotSquared version.");
|
|
|
|
}
|
2020-02-16 02:34:51 +01:00
|
|
|
}
|
|
|
|
this.cancel();
|
2020-02-16 01:33:43 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}.runTaskTimer(this.javaPlugin, 0L, 12000L);
|
|
|
|
}
|
2020-04-11 01:26:07 +02:00
|
|
|
}
|