Initial commit
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
package cf.sobrooms;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Socket;
|
||||
|
||||
public class ServerUtils {
|
||||
public static int port = 25565;
|
||||
public static String address = "http://mc-srv2-singapore.rrryfoo.cf";
|
||||
public static String address_fallback = Utils.getServerHostPublicIP();
|
||||
public static String webhook_notify = Main.getNotifyWebhook();
|
||||
public static String webhook_messages = Main.getPublicMessageWebhook();
|
||||
|
||||
public static boolean serverIsUp(String serverAddress, Integer serverPort) {
|
||||
/*Socket socket;
|
||||
try {
|
||||
socket = new Socket(address, port);
|
||||
socket.close();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
try {
|
||||
System.out.println("Server is inactive on default address. Pinging on fallback address (" + address_fallback + ")...");
|
||||
Socket socket2 = new Socket(address_fallback, port);
|
||||
socket2.close();
|
||||
return true;
|
||||
} catch (Exception exception) {
|
||||
System.out.println("Server is inactive on fallback address. No longer pinging...");
|
||||
return false;
|
||||
}
|
||||
}*/
|
||||
try {
|
||||
Server server = Bukkit.getServer();
|
||||
Socket s = new Socket();
|
||||
s.connect(new InetSocketAddress(serverAddress.toString(), Integer.parseInt(serverPort.toString())), 15);
|
||||
s.close();
|
||||
System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + Utils.getServerHostPublicIP() + ":" + server.getPort() + ")");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Server is inactive. Pinging fallback address...");
|
||||
try {
|
||||
Server server = Bukkit.getServer();
|
||||
Socket s = new Socket();
|
||||
s.connect(new InetSocketAddress(address_fallback, Integer.parseInt(serverPort.toString())), 15);
|
||||
s.close();
|
||||
} catch (Exception err) {
|
||||
System.out.println("Fallback address is inactive. No longer pinging...");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user