43 lines
1.7 KiB
Java
43 lines
1.7 KiB
Java
package moe.sob.commands;
|
|
|
|
import moe.sob.DiscordWebhook;
|
|
import moe.sob.Main;
|
|
import moe.sob.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) {
|
|
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.setContent(String.format("**%s**: %s", sender.getName(), message));
|
|
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);
|
|
}
|
|
}
|
|
} 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;
|
|
}
|
|
}
|
|
}
|