small changes

This commit is contained in:
mangorifo
2023-03-29 11:51:14 +08:00
parent d221a42f89
commit 539cbe9104
2 changed files with 8 additions and 0 deletions
@@ -0,0 +1,51 @@
package cf.sobrooms.events.server;
import cf.sobrooms.DiscordWebhook;
import cf.sobrooms.Main;
import cf.sobrooms.ServerUtils;
import cf.sobrooms.Utils;
import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.server.ServerLoadEvent;
import java.awt.*;
import java.io.IOException;
import java.util.Date;
import cf.sobrooms.DiscordWebhook.EmbedObject;
public class ServerStart implements Listener {
public static int timesCalled = 0;
@EventHandler
public void onServerStart(ServerLoadEvent event) {
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(Main.serverAddress, 25565)) {
System.out.println(ServerUtils.webhook_messages);
System.out.println(ServerUtils.webhook_notify);
DiscordWebhook notify = new DiscordWebhook(Main.getNotifyWebhook());
EmbedObject embedObject = new EmbedObject().setTitle("Server started up successfully").setDescription(String.format("The server at %s:%d has started successfully.", Utils.getServerHostPublicIP(), Bukkit.getServer().getPort()))
.addField("Date of start", new Date().toString(), false)
.setColor(Color.GREEN);
if (Main.getLoggingConfig().equals("false"))
embedObject.addField("Extra notes", "The server will not try to log any events.", false);
notify.addEmbed(embedObject);
try {
notify.execute();
} catch (IOException e) {
throw new RuntimeException(e);
}
timesCalled++;
} else {
Bukkit.getConsoleSender().sendMessage("OnServerStart was called, but the server is currently offline... This may trigger more than once.");
}
} else {
Bukkit.getConsoleSender().sendMessage("(debug) server start event was called more than 1 time");
}
}
}