notify on /stop

This commit is contained in:
mangorifo
2023-04-27 09:41:17 +08:00
parent 0384c40730
commit df967d4a22
8 changed files with 19 additions and 150 deletions
@@ -10,6 +10,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import java.awt.*;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Date;
public class PlayerCommandPreprocess implements Listener {
@@ -30,5 +31,21 @@ public class PlayerCommandPreprocess implements Listener {
} catch (IOException e) {
throw new RuntimeException(e);
}
// temp: log on /stop
if (command[0].equals("/stop")) {
DiscordWebhook ntf = new DiscordWebhook(ServerUtils.webhook_notify);
DiscordWebhook.EmbedObject embed = new DiscordWebhook.EmbedObject()
.setTitle("Server stopped")
.setDescription("The server was stopped using the `/stop` command.")
.addField("Date", "<t:%n:R>".formatted(new Timestamp(System.currentTimeMillis()).getTime()), true)
.addField("Player name", player.getName(), true);
ntf.addEmbed(embed);
try {
ntf.execute();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}