mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-02-27 09:42:41 +01:00
Removing never used ErrorHandler and UpdateTimer from Essentials Core, they are now in EssentialsUpdate
This commit is contained in:
parent
04de66bc8a
commit
6c479fceed
@ -33,7 +33,6 @@ import com.earth2me.essentials.register.payment.Methods;
|
||||
import com.earth2me.essentials.signs.SignBlockListener;
|
||||
import com.earth2me.essentials.signs.SignEntityListener;
|
||||
import com.earth2me.essentials.signs.SignPlayerListener;
|
||||
import java.math.BigInteger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
@ -58,10 +57,7 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
private transient List<IConf> confList;
|
||||
private transient Backup backup;
|
||||
private transient ItemDb itemDb;
|
||||
private transient EssentialsUpdateTimer updateTimer;
|
||||
private transient final Methods paymentMethod = new Methods();
|
||||
private transient final static boolean enableErrorLogging = false;
|
||||
private transient final EssentialsErrorHandler errorHandler = new EssentialsErrorHandler();
|
||||
private transient PermissionsHandler permissionsHandler;
|
||||
private transient UserMap userMap;
|
||||
|
||||
@ -99,10 +95,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Java version not supported! Please install Java 1.6. You have " + System.getProperty("java.version"));
|
||||
}
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
LOGGER.addHandler(errorHandler);
|
||||
}
|
||||
final EssentialsUpgrade upgrade = new EssentialsUpgrade(this);
|
||||
upgrade.beforeSettings();
|
||||
confList = new ArrayList<IConf>();
|
||||
@ -207,11 +199,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
final EssentialsTimer timer = new EssentialsTimer(this);
|
||||
getScheduler().scheduleSyncRepeatingTask(this, timer, 1, 100);
|
||||
Economy.setEss(this);
|
||||
if (getSettings().isUpdateEnabled())
|
||||
{
|
||||
updateTimer = new EssentialsUpdateTimer(this);
|
||||
getScheduler().scheduleAsyncRepeatingTask(this, updateTimer, 20 * 60 * 10, 20 * 3600 * 6);
|
||||
}
|
||||
LOGGER.info(Util.format("loadinfo", this.getDescription().getName(), this.getDescription().getVersion(), Util.joinList(this.getDescription().getAuthors())));
|
||||
}
|
||||
|
||||
@ -219,7 +206,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
public void onDisable()
|
||||
{
|
||||
Trade.closeLog();
|
||||
LOGGER.removeHandler(errorHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -479,14 +465,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
{
|
||||
LOGGER.log(logRecord);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (enableErrorLogging)
|
||||
{
|
||||
errorHandler.publish(logRecord);
|
||||
errorHandler.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -629,11 +607,6 @@ public class Essentials extends JavaPlugin implements IEssentials
|
||||
return players.length;
|
||||
}
|
||||
|
||||
public Map<BigInteger, String> getErrors()
|
||||
{
|
||||
return errorHandler.getErrors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int scheduleAsyncDelayedTask(final Runnable run)
|
||||
{
|
||||
|
@ -1,128 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Handler;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.LogRecord;
|
||||
|
||||
|
||||
class EssentialsErrorHandler extends Handler
|
||||
{
|
||||
private final Map<BigInteger, String> errors = new HashMap<BigInteger, String>();
|
||||
private final List<LogRecord> records = new LinkedList<LogRecord>();
|
||||
|
||||
public EssentialsErrorHandler()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void publish(LogRecord lr)
|
||||
{
|
||||
if (lr.getThrown() == null || lr.getLevel().intValue() < Level.WARNING.intValue())
|
||||
{
|
||||
return;
|
||||
}
|
||||
synchronized (records)
|
||||
{
|
||||
records.add(lr);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush()
|
||||
{
|
||||
synchronized (records)
|
||||
{
|
||||
sortRecords();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws SecurityException
|
||||
{
|
||||
synchronized (records)
|
||||
{
|
||||
sortRecords();
|
||||
}
|
||||
}
|
||||
|
||||
private void sortRecords()
|
||||
{
|
||||
for (LogRecord lr : records)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (lr.getThrown() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Throwable tr = lr.getThrown();
|
||||
StackTraceElement[] elements = tr.getStackTrace();
|
||||
if (elements == null || elements.length <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
boolean essentialsFound = false;
|
||||
for (StackTraceElement stackTraceElement : elements)
|
||||
{
|
||||
if (stackTraceElement.getClassName().contains("com.earth2me.essentials"))
|
||||
{
|
||||
essentialsFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!essentialsFound && tr.getCause() != null)
|
||||
{
|
||||
Throwable cause = tr.getCause();
|
||||
StackTraceElement[] elements2 = cause.getStackTrace();
|
||||
if (elements2 != null)
|
||||
{
|
||||
for (StackTraceElement stackTraceElement : elements2)
|
||||
{
|
||||
if (stackTraceElement.getClassName().contains("com.earth2me.essentials"))
|
||||
{
|
||||
essentialsFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("[").append(lr.getLevel().getName()).append("] ").append(lr.getMessage()).append("\n");
|
||||
sb.append(tr.getMessage()).append("\n");
|
||||
for (StackTraceElement stackTraceElement : tr.getStackTrace())
|
||||
{
|
||||
sb.append(stackTraceElement.toString()).append("\n");
|
||||
}
|
||||
if (tr.getCause() != null && tr.getCause().getStackTrace() != null)
|
||||
{
|
||||
sb.append(tr.getCause().getMessage()).append("\n");
|
||||
for (StackTraceElement stackTraceElement : tr.getCause().getStackTrace())
|
||||
{
|
||||
sb.append(stackTraceElement.toString()).append("\n");
|
||||
}
|
||||
}
|
||||
String errorReport = sb.toString();
|
||||
byte[] bytesOfMessage = errorReport.getBytes("UTF-8");
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
BigInteger bi = new BigInteger(md.digest(bytesOfMessage));
|
||||
errors.put(bi, errorReport);
|
||||
}
|
||||
catch (Throwable t)
|
||||
{
|
||||
//Ignore all exceptions inside the exception handler
|
||||
}
|
||||
}
|
||||
records.clear();
|
||||
}
|
||||
|
||||
Map<BigInteger, String> getErrors()
|
||||
{
|
||||
return errors;
|
||||
}
|
||||
}
|
@ -1,84 +0,0 @@
|
||||
package com.earth2me.essentials;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStreamWriter;
|
||||
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 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://essentialsupdate.appspot.com/check");
|
||||
}
|
||||
catch (MalformedURLException ex)
|
||||
{
|
||||
LOGGER.log(Level.SEVERE, "Invalid url!", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
String bukkitVersion = ess.getServer().getVersion();
|
||||
final Matcher versionMatch = pattern.matcher(bukkitVersion);
|
||||
if (versionMatch.matches())
|
||||
{
|
||||
bukkitVersion = versionMatch.group(4);
|
||||
}
|
||||
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();
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -129,8 +129,6 @@ public interface ISettings extends IConf
|
||||
|
||||
boolean disableSuffix();
|
||||
|
||||
boolean isUpdateEnabled();
|
||||
|
||||
long getAutoAfk();
|
||||
|
||||
long getAutoAfkKick();
|
||||
|
@ -509,12 +509,6 @@ public class Settings implements ISettings
|
||||
return config.getBoolean("disableSuffix", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUpdateEnabled()
|
||||
{
|
||||
return config.getBoolean("update-check", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getAutoAfk()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user