2023-03-28 19:24:11 +08:00
|
|
|
package cf.sobrooms.events.player;
|
|
|
|
|
|
|
|
|
|
import cf.sobrooms.DiscordWebhook;
|
|
|
|
|
import cf.sobrooms.ServerUtils;
|
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
import org.bukkit.event.EventHandler;
|
|
|
|
|
import org.bukkit.event.Listener;
|
|
|
|
|
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.io.IOException;
|
2023-04-27 09:41:17 +08:00
|
|
|
import java.sql.Timestamp;
|
2023-03-28 19:24:11 +08:00
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
public class PlayerCommandPreprocess implements Listener {
|
|
|
|
|
@EventHandler
|
|
|
|
|
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
|
|
|
|
|
Bukkit.getConsoleSender().sendMessage("PlayerCommandPreprocess event triggered");
|
|
|
|
|
Player player = event.getPlayer();
|
|
|
|
|
String[] command = event.getMessage().split(" "); // get the command name
|
|
|
|
|
DiscordWebhook notify = new DiscordWebhook(ServerUtils.webhook_notify);
|
|
|
|
|
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject().setTitle("Command used").setDescription("A player has used a command.")
|
|
|
|
|
.addField("Date of usage", new Date().toString(), false)
|
|
|
|
|
.addField("Player name", player.getName(), false)
|
|
|
|
|
.addField("Command", command[0], true)
|
|
|
|
|
.setColor(Color.BLUE);
|
|
|
|
|
notify.addEmbed(embedObject);
|
|
|
|
|
try {
|
|
|
|
|
notify.execute();
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
2023-04-27 09:41:17 +08:00
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-28 19:24:11 +08:00
|
|
|
}
|
|
|
|
|
}
|