diff --git a/README.md b/README.md index f63cefa..343f3f4 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,10 @@ this was just made to remember whatever goofy things we did in a minecraft serve or, you know, notify us when the server starts (but not ends) +# Prerequisites +Before using this plugin, you must: +* Get Spigot +* Get a JAR file from [the releases](https://git.sob.moe/sobrooms/notify-on-start/releases) or [Google Drive](https://drive.google.com/drive/folders/11wMPjOh2b8oRzpeJOrOI4ZAkImOlr93u?usp=sharing) (the drive folder is frequently updated) # making webhooks If you already know how, you can skip this step. @@ -22,7 +26,8 @@ To make a webhook: # using this thing -You must get Spigot.\ +Of course, you must get a release first, as said in the prerequisites. After you get a jar, put it in the `plugins` folder + On first run, it will make a directory where Spigot is.\ These files will be `NoS/notifyWebhook.json` and `NoS/pubMessageWebhook.json`. diff --git a/gradlew-jar.bat b/gradlew-jar.bat index e10dc4b..4338670 100644 --- a/gradlew-jar.bat +++ b/gradlew-jar.bat @@ -1 +1,2 @@ -call ./gradlew jar \ No newline at end of file +@call ./gradlew jar +@pause \ No newline at end of file diff --git a/src/main/java/cf/sobrooms/Main.java b/src/main/java/cf/sobrooms/Main.java index 29dd238..48a578a 100644 --- a/src/main/java/cf/sobrooms/Main.java +++ b/src/main/java/cf/sobrooms/Main.java @@ -32,7 +32,6 @@ public class Main extends JavaPlugin { public static void main(String... args) { System.out.printf("Initializing using server address: %s...%n", ServerUtils.address); } - @Override public void onEnable() { String loggingDir = "./NoS"; @@ -73,7 +72,8 @@ public class Main extends JavaPlugin { } catch (NullPointerException e) { throw new RuntimeException(e); } - + webhooksAreValidUrls = validateWebhook_Ntfy(); + webhooksAreValidUrls = validateWebhook_Pub(); // register events if (getLoggingConfig().equals("true") && webhooksAreValidUrls) registerEvents(); @@ -87,6 +87,19 @@ public class Main extends JavaPlugin { } } + + public static boolean validateWebhook_Pub() { + if (getPublicMessageWebhook().startsWith("https://") || getPublicMessageWebhook().startsWith("http://")) + return true; + else + return false; + } + public static boolean validateWebhook_Ntfy() { + if (getNotifyWebhook().startsWith("https://") || getNotifyWebhook().startsWith("http://")) + return true; + else + return false; + } public static String getPublicMessageWebhook() { try { BufferedReader brfmsg = new BufferedReader(new FileReader(pubMessageWebhookConfig)); @@ -101,6 +114,7 @@ public class Main extends JavaPlugin { webhooksAreValidUrls = false; return lineMsg; } else if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) { + webhooksAreValidUrls = true; return lineMsg; } else { System.out.printf("Please set the webhook URL in %s and restart the server", pubMessageWebhookConfig.getAbsolutePath()); @@ -125,6 +139,7 @@ public class Main extends JavaPlugin { webhooksAreValidUrls = false; return lineNtfy; } else if (lineNtfy.startsWith("https://") || lineNtfy.startsWith("http://")) { + webhooksAreValidUrls = true; return lineNtfy; } else { System.out.printf("Please set the webhook URL in %s and restart the server", notifyWebhookConfig.getAbsolutePath()); diff --git a/src/main/java/cf/sobrooms/ServerUtils.java b/src/main/java/cf/sobrooms/ServerUtils.java index f2c32b9..ad214ac 100644 --- a/src/main/java/cf/sobrooms/ServerUtils.java +++ b/src/main/java/cf/sobrooms/ServerUtils.java @@ -11,7 +11,7 @@ public class ServerUtils { public static String address_fallback = Utils.getServerHostPublicIP(); public static String webhook_notify = Main.getNotifyWebhook(); public static String webhook_messages = Main.getPublicMessageWebhook(); - public static String address = "http://mc-srv2-singapore.rrryfoo.cf"; + public static String address = "mc-srv2-singapore.rrryfoo.cf"; public static boolean serverIsUp(String serverAddress, Integer serverPort) { /*Socket socket; @@ -33,9 +33,9 @@ public class ServerUtils { try { Server server = Bukkit.getServer(); Socket s = new Socket(); - s.connect(new InetSocketAddress(serverAddress.toString(), Integer.parseInt(serverPort.toString())), 15); + s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15); s.close(); - System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + Utils.getServerHostPublicIP() + ":" + server.getPort() + ")"); + System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + serverAddress + ":" + server.getPort() + ")"); return true; } catch (Exception e) { System.out.println("Server is inactive. Pinging fallback address..."); @@ -44,6 +44,8 @@ public class ServerUtils { Socket s = new Socket(); s.connect(new InetSocketAddress(address_fallback, 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 err) { System.out.println("Fallback address is inactive. No longer pinging..."); } diff --git a/src/main/java/cf/sobrooms/events/server/ServerLoad.java b/src/main/java/cf/sobrooms/events/server/ServerLoad.java index 1ca961b..12f2f39 100644 --- a/src/main/java/cf/sobrooms/events/server/ServerLoad.java +++ b/src/main/java/cf/sobrooms/events/server/ServerLoad.java @@ -24,7 +24,7 @@ public class ServerLoad implements Listener { Bukkit.getConsoleSender().sendMessage("Triggered ServerLoad event."); if (timesCalled < 1) { Bukkit.getConsoleSender().sendMessage("Checking if server is up on " + ServerUtils.address + " with port " + ServerUtils.port + "..."); - if (ServerUtils.serverIsUp(address, 25565)) { + if (ServerUtils.serverIsUp(address, Bukkit.getServer().getPort())) { System.out.println(ServerUtils.webhook_messages); System.out.println(ServerUtils.webhook_notify); DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook());