2023-03-28 19:24:11 +08:00
|
|
|
package cf.sobrooms.commands;
|
|
|
|
|
|
|
|
|
|
import cf.sobrooms.DiscordWebhook;
|
2023-09-25 23:44:12 +08:00
|
|
|
import cf.sobrooms.Main;
|
2023-03-28 19:24:11 +08:00
|
|
|
import cf.sobrooms.ServerUtils;
|
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
|
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
public class SendMessageCommand implements CommandExecutor {
|
|
|
|
|
@Override
|
|
|
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
2023-09-25 23:44:12 +08:00
|
|
|
if (Main.hdc) {
|
|
|
|
|
if (args.length == 0) {
|
|
|
|
|
sender.sendMessage("Please input a message to send...");
|
|
|
|
|
return false;
|
|
|
|
|
} else {
|
|
|
|
|
sender.sendMessage("Sending a public message to the discord server...");
|
|
|
|
|
DiscordWebhook discordWebhook = new DiscordWebhook(ServerUtils.webhook_messages);
|
|
|
|
|
discordWebhook.setUsername("Public Messages");
|
|
|
|
|
String message = String.join(" ", args);
|
|
|
|
|
DiscordWebhook.EmbedObject embedObject = new DiscordWebhook.EmbedObject()
|
|
|
|
|
.setTitle("New public message")
|
|
|
|
|
.setDescription(message)
|
|
|
|
|
.setAuthor(sender.getName(), "", "")
|
|
|
|
|
.setFooter(new Date().toString(), "")
|
|
|
|
|
.setColor(Color.darkGray);
|
|
|
|
|
discordWebhook.addEmbed(embedObject);
|
|
|
|
|
try {
|
|
|
|
|
discordWebhook.execute();
|
|
|
|
|
sender.sendMessage("Sent public message.");
|
|
|
|
|
return true;
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
sender.sendMessage("An error occurred while sending your message...");
|
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
|
}
|
2023-03-28 19:24:11 +08:00
|
|
|
}
|
2023-09-25 23:44:12 +08:00
|
|
|
} else {
|
|
|
|
|
sender.sendMessage("There is no discord server that was set for this command.");
|
|
|
|
|
sender.sendMessage("Please ask the server owner to add a webhook to the configuration. (the entry is called \"url_publicmsg\")");
|
|
|
|
|
return false;
|
2023-03-28 19:24:11 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|