60 lines
1.4 KiB
Java
60 lines
1.4 KiB
Java
|
package mineplex.bungee.status;
|
||
|
|
||
|
import java.io.File;
|
||
|
import java.io.IOException;
|
||
|
import java.net.InetAddress;
|
||
|
import java.net.UnknownHostException;
|
||
|
import java.util.concurrent.TimeUnit;
|
||
|
|
||
|
import net.md_5.bungee.api.config.ListenerInfo;
|
||
|
import net.md_5.bungee.api.plugin.Plugin;
|
||
|
|
||
|
public class InternetStatus implements Runnable
|
||
|
{
|
||
|
private Plugin _plugin;
|
||
|
private StatusRepository _repository;
|
||
|
|
||
|
public InternetStatus(Plugin plugin)
|
||
|
{
|
||
|
_plugin = plugin;
|
||
|
|
||
|
ListenerInfo listenerInfo = _plugin.getProxy().getConfigurationAdapter().getListeners().iterator().next();
|
||
|
boolean us = !new File("eu.dat").exists();
|
||
|
String address = listenerInfo.getHost().getAddress().getHostAddress() + ":" + listenerInfo.getHost().getPort();
|
||
|
|
||
|
_repository = new StatusRepository(address, us);
|
||
|
_repository.initialize();
|
||
|
|
||
|
_plugin.getProxy().getScheduler().schedule(_plugin, this, 5L, 5L, TimeUnit.MINUTES);
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void run()
|
||
|
{
|
||
|
_repository.updateOnlineStatus(isOnline());
|
||
|
}
|
||
|
|
||
|
private boolean isOnline()
|
||
|
{
|
||
|
try
|
||
|
{
|
||
|
if (InetAddress.getByName("http://www.google.com").isReachable(1000))
|
||
|
return true;
|
||
|
else if (InetAddress.getByName("http://www.espn.com").isReachable(1000))
|
||
|
return true;
|
||
|
else if (InetAddress.getByName("http://www.bing.com").isReachable(1000))
|
||
|
return true;
|
||
|
}
|
||
|
catch (UnknownHostException e)
|
||
|
{
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
catch (IOException e)
|
||
|
{
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|