Merge branch 'master' of github.com:essentials/Essentials

This commit is contained in:
KHobbits 2011-08-23 03:43:14 +01:00
commit 9dc54340f8
6 changed files with 65 additions and 33 deletions

View file

@ -209,10 +209,10 @@ public class Essentials extends JavaPlugin implements IEssentials
final EssentialsTimer timer = new EssentialsTimer(this); final EssentialsTimer timer = new EssentialsTimer(this);
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50); getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 50);
Economy.setEss(this); Economy.setEss(this);
if (enableErrorLogging) if (getSettings().isUpdateEnabled())
{ {
updateTimer = new EssentialsUpdateTimer(this); 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()))); LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
} }

View file

@ -68,7 +68,12 @@ public class EssentialsConf extends Configuration
} }
} }
} }
super.load(); try {
super.load();
} catch(RuntimeException e) {
logger.log(Level.INFO, "File: " + configFile.toString());
throw e;
}
if (this.root == null) if (this.root == null)
{ {
this.root = new HashMap<String, Object>(); this.root = new HashMap<String, Object>();

View file

@ -4,65 +4,81 @@ import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.math.BigInteger;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.bukkit.entity.Player;
class EssentialsUpdateTimer implements Runnable class EssentialsUpdateTimer implements Runnable
{ {
private URL url; private transient URL url;
private final Essentials ess; private final transient IEssentials ess;
private static final Logger logger = Logger.getLogger("Minecraft"); 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(Essentials ess)
public EssentialsUpdateTimer(final IEssentials ess)
{ {
this.ess = ess; this.ess = ess;
try try
{ {
url = new URL("http://127.0.0.1:8080/check"); url = new URL("http://essentialsupdate.appspot.com/check");
} }
catch (MalformedURLException ex) catch (MalformedURLException ex)
{ {
logger.log(Level.SEVERE, "Invalid url!", ex); LOGGER.log(Level.SEVERE, "Invalid url!", ex);
} }
} }
@Override
public void run() public void run()
{ {
try try
{ {
StringBuilder sb = new StringBuilder(); final StringBuilder builder = new StringBuilder();
sb.append("v=").append(URLEncoder.encode(ess.getDescription().getVersion(),"UTF-8")); String bukkitVersion = ess.getServer().getVersion();
sb.append("&b=").append(URLEncoder.encode(ess.getServer().getVersion(),"UTF-8")); final Matcher versionMatch = pattern.matcher(bukkitVersion);
sb.append("&jv=").append(URLEncoder.encode(System.getProperty("java.version"),"UTF-8")); if (versionMatch.matches())
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())
{ {
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.setConnectTimeout(10000);
conn.setDoOutput(true); conn.setDoOutput(true);
conn.connect(); conn.connect();
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream()); final OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream());
wr.write(sb.toString()); writer.write(builder.toString());
wr.flush(); writer.flush();
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); final BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String ret = br.readLine(); final String ret = reader.readLine();
wr.close(); writer.close();
br.close(); reader.close();
logger.log(Level.INFO, ret); 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) catch (IOException ex)
{ {
logger.log(Level.SEVERE, "Failed to open connection", ex); LOGGER.log(Level.SEVERE, "Failed to open connection", ex);
} }
} }
} }

View file

@ -131,7 +131,9 @@ public interface ISettings extends IConf
boolean isPlayerCommand(String string); boolean isPlayerCommand(String string);
public boolean useBukkitPermissions(); boolean useBukkitPermissions();
public boolean addPrefixSuffix(); boolean addPrefixSuffix();
boolean isUpdateEnabled();
} }

View file

@ -479,4 +479,10 @@ public class Settings implements ISettings
{ {
return config.getBoolean("add-prefix-suffix", ess.getServer().getPluginManager().isPluginEnabled("EssentialsChat")); return config.getBoolean("add-prefix-suffix", ess.getServer().getPluginManager().isPluginEnabled("EssentialsChat"));
} }
@Override
public boolean isUpdateEnabled()
{
return config.getBoolean("update-check", true);
}
} }

View file

@ -230,6 +230,9 @@ remove-god-on-disconnect: false
# This only works if no other permission plugins are installed # This only works if no other permission plugins are installed
use-bukkit-permissions: false use-bukkit-permissions: false
# Check for updates
update-check: true
############################################################ ############################################################
# +------------------------------------------------------+ # # +------------------------------------------------------+ #
# | EssentialsHome | # # | EssentialsHome | #