1.2.0: Remove unnecessary events, use yml as a config, implement log disabling

This commit is contained in:
2025-11-25 23:10:57 +08:00
parent eabb5a69c1
commit 02f73ad13e
13 changed files with 193 additions and 140 deletions
@@ -1,6 +1,7 @@
package moe.sob.events.player;
import moe.sob.DiscordWebhook;
import moe.sob.Main;
import moe.sob.ServerUtils;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@@ -16,36 +17,38 @@ import java.util.Date;
public class PlayerCommandPreprocess implements Listener {
@EventHandler
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
Bukkit.getConsoleSender().sendMessage("%s used a command".formatted(event.getPlayer().getName()));
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")
.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);
}
// 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);
if (Main.configR.getBoolean("log")) {
Bukkit.getConsoleSender().sendMessage("%s used a command".formatted(event.getPlayer().getName()));
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")
.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 {
ntf.execute();
notify.execute();
} 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);
}
}
}
}
}