mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-28 03:57:48 +01:00
Update check for Essentials
This commit is contained in:
parent
91393e3180
commit
90419cdbf5
@ -209,10 +209,10 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
|
||||
Economy.setEss(this);
|
||||
if (enableErrorLogging)
|
||||
if (getSettings().isUpdateEnabled())
|
||||
{
|
||||
updateTimer = new EssentialsUpdateTimer(this);
|
||||
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 50, 50 * 60 * (this.getDescription().getVersion().startsWith("Dev") ? 60 : 360));
|
||||
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60, 20 * 3600 * 6);
|
||||
}
|
||||
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
||||
}
|
||||
|
@ -4,65 +4,81 @@ import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.math.BigInteger;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
class EssentialsUpdateTimer implements Runnable
|
||||
{
|
||||
private URL url;
|
||||
private final Essentials ess;
|
||||
private static final Logger logger = Logger.getLogger("Minecraft");
|
||||
|
||||
public EssentialsUpdateTimer(Essentials ess)
|
||||
private transient URL url;
|
||||
private final transient IEssentials ess;
|
||||
private static final Logger LOGGER = Logger.getLogger("Minecraft");
|
||||
private final transient Pattern pattern = Pattern.compile("git-Bukkit-([0-9]+).([0-9]+).([0-9]+)-[0-9]+-[0-9a-z]+-b([0-9]+)jnks.*");
|
||||
|
||||
public EssentialsUpdateTimer(final IEssentials ess)
|
||||
{
|
||||
this.ess = ess;
|
||||
try
|
||||
{
|
||||
url = new URL("http://127.0.0.1:8080/check");
|
||||
url = new URL("http://essentialsupdate.appspot.com/check");
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, "Invalid url!", ex);
|
||||
LOGGER.log(Level.SEVERE, "Invalid url!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("v=").append(URLEncoder.encode(ess.getDescription().getVersion(),"UTF-8"));
|
||||
sb.append("&b=").append(URLEncoder.encode(ess.getServer().getVersion(),"UTF-8"));
|
||||
sb.append("&jv=").append(URLEncoder.encode(System.getProperty("java.version"),"UTF-8"));
|
||||
sb.append("&l=").append(URLEncoder.encode(Util.getCurrentLocale().toString(),"UTF-8"));
|
||||
sb.append("&on=").append(URLEncoder.encode(System.getProperty("os.name"),"UTF-8"));
|
||||
sb.append("&ov=").append(URLEncoder.encode(System.getProperty("os.version"),"UTF-8"));
|
||||
for (BigInteger bigInteger : ess.getErrors().keySet())
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String bukkitVersion = ess.getServer().getVersion();
|
||||
final Matcher versionMatch = pattern.matcher(bukkitVersion);
|
||||
if (versionMatch.matches())
|
||||
{
|
||||
sb.append("&e[]=").append(bigInteger.toString(36));
|
||||
bukkitVersion = versionMatch.group(4);
|
||||
}
|
||||
URLConnection conn = url.openConnection();
|
||||
builder.append("v=").append(URLEncoder.encode(ess.getDescription().getVersion(), "UTF-8"));
|
||||
builder.append("&b=").append(URLEncoder.encode(bukkitVersion, "UTF-8"));
|
||||
final URLConnection conn = url.openConnection();
|
||||
conn.setConnectTimeout(10000);
|
||||
conn.setDoOutput(true);
|
||||
conn.connect();
|
||||
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
||||
wr.write(sb.toString());
|
||||
wr.flush();
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
String ret = br.readLine();
|
||||
wr.close();
|
||||
br.close();
|
||||
logger.log(Level.INFO, ret);
|
||||
final OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
|
||||
writer.write(builder.toString());
|
||||
writer.flush();
|
||||
final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
||||
final String ret = reader.readLine();
|
||||
writer.close();
|
||||
reader.close();
|
||||
if (!ret.isEmpty() && !ret.equalsIgnoreCase("OK"))
|
||||
{
|
||||
LOGGER.log(Level.INFO, "Essentials Update-Check: " + ret);
|
||||
if (ret.startsWith("New Version"))
|
||||
{
|
||||
for (Player player : ess.getServer().getOnlinePlayers())
|
||||
{
|
||||
final User user = ess.getUser(player);
|
||||
if (user.isAuthorized("essentials.admin.notices.update"))
|
||||
{
|
||||
user.sendMessage(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
logger.log(Level.SEVERE, "Failed to open connection", ex);
|
||||
LOGGER.log(Level.SEVERE, "Failed to open connection", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -129,7 +129,9 @@ public interface ISettings extends IConf
|
||||
|
||||
boolean isPlayerCommand(String string);
|
||||
|
||||
public boolean useBukkitPermissions();
|
||||
boolean useBukkitPermissions();
|
||||
|
||||
public boolean addPrefixSuffix();
|
||||
boolean addPrefixSuffix();
|
||||
|
||||
boolean isUpdateEnabled();
|
||||
}
|
||||
|
@ -473,4 +473,10 @@ public class Settings implements ISettings
|
||||
{
|
||||
return config.getBoolean("add-prefix-suffix", ess.getServer().getPluginManager().isPluginEnabled("EssentialsChat"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateEnabled()
|
||||
{
|
||||
return config.getBoolean("update-check", true);
|
||||
}
|
||||
}
|
||||
|
@ -230,6 +230,9 @@ remove-god-on-disconnect: false
|
||||
# This only works if no other permission plugins are installed
|
||||
use-bukkit-permissions: false
|
||||
|
||||
# Check for updates
|
||||
update-check: true
|
||||
|
||||
############################################################
|
||||
# +------------------------------------------------------+ #
|
||||
# | EssentialsHome | #
|
||||
|
Loading…
Reference in New Issue
Block a user