fixed it not being able to get the webhook
This commit is contained in:
@@ -55,7 +55,7 @@ public class Main extends JavaPlugin {
|
||||
//FileWriter pubMessageWebhookConfigWriter = new FileWriter(pubMessageWebhookConfig);
|
||||
//notifyWebhookConfigWriter.write("{\"url_notify\": \"default-ns\"}");
|
||||
FileWriter linkConfigWriter = new FileWriter(webhookConfig);
|
||||
linkConfigWriter.write("{\n \"url_publicmsg\": \"default-ns\", \n \"url_notify\": \"default-ns\"\n}");
|
||||
linkConfigWriter.write("{\"url_publicmsg\": \"default-ns\",\"url_notify\": \"default-ns\"}");
|
||||
linkConfigWriter.close();
|
||||
//notifyWebhookConfigWriter.close();
|
||||
} else {
|
||||
@@ -93,6 +93,10 @@ public class Main extends JavaPlugin {
|
||||
|
||||
public static boolean validateWebhook_Pub() {
|
||||
try {
|
||||
if (getPublicMessageWebhook().equals("default-ns") || !getPublicMessageWebhook().contains("https://")) {
|
||||
System.out.println("There was no webhook set for the public messages function. The send-message command cannot be used until you do.");
|
||||
return true;
|
||||
}
|
||||
URL url = new URL(getPublicMessageWebhook());
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
@@ -100,11 +104,12 @@ public class Main extends JavaPlugin {
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
|
||||
System.out.println("Invalid webhook URL provided for your public messages. Please provide the correct webhook and check for any typos.");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
System.out.println("Invalid webhook URL provide for your public messages. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
System.out.println("Exception: %s".formatted(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -117,11 +122,12 @@ public class Main extends JavaPlugin {
|
||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||
return true;
|
||||
} else {
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos.");
|
||||
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos.");
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.out.println("Invalid webhook URL provided. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
System.out.println("Invalid webhook URL provided for the event logs. Please provide the correct webhook and check for any typos. (Caught exception)");
|
||||
System.out.println("Exception: %s".formatted(e));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -133,18 +139,12 @@ public class Main extends JavaPlugin {
|
||||
String lineMsg = MsgParse.getAsJsonObject().get("url_publicmsg").getAsString();
|
||||
|
||||
brfmsg.close();
|
||||
if (lineMsg.equals("default-ns")) {
|
||||
System.out.printf("Please set the public message webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
|
||||
webhooksAreValidUrls = false;
|
||||
return lineMsg;
|
||||
} else if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) {
|
||||
if (lineMsg.startsWith("https://") || lineMsg.startsWith("http://")) {
|
||||
webhooksAreValidUrls = true;
|
||||
return lineMsg;
|
||||
} else {
|
||||
System.out.printf("Please set the public message webhook URL in %s and restart the server", webhookConfig.getAbsolutePath());
|
||||
webhooksAreValidUrls = false;
|
||||
return lineMsg;
|
||||
}
|
||||
|
||||
return "default-ns";
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public class ServerUtils {
|
||||
Socket s = new Socket();
|
||||
s.connect(new InetSocketAddress(serverAddress, Integer.parseInt(serverPort.toString())), 15);
|
||||
s.close();
|
||||
System.out.println("Server is online. Sending message to webhook_notify... (Pinged " + serverAddress + ":" + server.getPort() + ")");
|
||||
System.out.println("Server is online. Test notifying by sending a message to your webhook... (Pinged " + serverAddress + ":" + server.getPort() + ")");
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
System.out.println("Server is inactive. Pinging fallback address...");
|
||||
|
||||
Reference in New Issue
Block a user