51 lines
2.2 KiB
Java
51 lines
2.2 KiB
Java
|
|
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");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|