Using embeds for chat and separated restart and stop messages
This commit is contained in:
parent
9383f5ea0c
commit
2f76583a87
3 changed files with 28 additions and 6 deletions
|
@ -113,7 +113,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
dc.changeStatus(Status.game("testing"));
|
dc.changeStatus(Status.game("testing"));
|
||||||
}
|
}
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this, () -> sendMessageToChannel(chatchannel, "",
|
Bukkit.getScheduler().runTaskAsynchronously(this, () -> sendMessageToChannel(chatchannel, "",
|
||||||
new EmbedBuilder().withColor(Color.BLUE).withTitle("Server started - chat connected.").build()));
|
new EmbedBuilder().withColor(Color.GREEN).withTitle("Server started - chat connected.").build()));
|
||||||
Runnable r = new Runnable() {
|
Runnable r = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
AnnouncementGetterThreadMethod();
|
AnnouncementGetterThreadMethod();
|
||||||
|
@ -133,13 +133,19 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Always true, except when running "stop" from console
|
||||||
|
*/
|
||||||
|
public static boolean Restart;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDisable() {
|
public void onDisable() {
|
||||||
stop = true;
|
stop = true;
|
||||||
getConfig().set("lastannouncementtime", lastannouncementtime);
|
getConfig().set("lastannouncementtime", lastannouncementtime);
|
||||||
getConfig().set("lastseentime", lastseentime);
|
getConfig().set("lastseentime", lastseentime);
|
||||||
saveConfig();
|
saveConfig();
|
||||||
sendMessageToChannel(chatchannel, "Server restarting/stopping");
|
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||||
|
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
|
||||||
try {
|
try {
|
||||||
dc.changeStatus(Status.game("on TBMC"));
|
dc.changeStatus(Status.game("on TBMC"));
|
||||||
dc.logout();
|
dc.logout();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
@ -19,6 +20,7 @@ import sx.blah.discord.api.events.IListener;
|
||||||
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
import sx.blah.discord.handle.impl.events.MessageReceivedEvent;
|
||||||
import sx.blah.discord.handle.obj.IReaction;
|
import sx.blah.discord.handle.obj.IReaction;
|
||||||
import sx.blah.discord.handle.obj.IUser;
|
import sx.blah.discord.handle.obj.IUser;
|
||||||
|
import sx.blah.discord.util.EmbedBuilder;
|
||||||
import sx.blah.discord.util.RateLimitException;
|
import sx.blah.discord.util.RateLimitException;
|
||||||
|
|
||||||
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
|
||||||
|
@ -28,11 +30,17 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
||||||
return;
|
return;
|
||||||
if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender)
|
if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender)
|
||||||
return;
|
return;
|
||||||
if (e.getChannel().equals(Channel.GlobalChat))
|
if (e.getChannel().equals(Channel.GlobalChat)) {
|
||||||
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
|
final EmbedBuilder embed = new EmbedBuilder()
|
||||||
DiscordPlugin.sanitizeString("<" + (e.getSender() instanceof Player //
|
.withAuthorName(DiscordPlugin.sanitizeString(e.getSender() instanceof Player //
|
||||||
? ((Player) e.getSender()).getDisplayName() //
|
? ((Player) e.getSender()).getDisplayName() //
|
||||||
: e.getSender().getName()) + "> " + e.getMessage()));
|
: e.getSender().getName()))
|
||||||
|
.withDescription(e.getMessage());
|
||||||
|
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel, "",
|
||||||
|
e.getSender() instanceof Player ? embed
|
||||||
|
.withAuthorIcon("https://minotar.net/avatar/" + ((Player) e.getSender()).getName() + "/32.png")
|
||||||
|
.build() : embed.build());
|
||||||
|
} // TODO: Author URL
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
private static final String[] UnconnectedCmds = new String[] { "list", "u", "shrug", "tableflip", "unflip", "mwiki",
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
package buttondevteam.discordplugin.listeners;
|
package buttondevteam.discordplugin.listeners;
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||||
|
import org.bukkit.event.server.ServerCommandEvent;
|
||||||
|
|
||||||
import buttondevteam.discordplugin.DiscordPlayer;
|
import buttondevteam.discordplugin.DiscordPlayer;
|
||||||
import buttondevteam.discordplugin.DiscordPlugin;
|
import buttondevteam.discordplugin.DiscordPlugin;
|
||||||
import buttondevteam.discordplugin.commands.ConnectCommand;
|
import buttondevteam.discordplugin.commands.ConnectCommand;
|
||||||
|
@ -61,4 +64,9 @@ public class MCListener implements Listener {
|
||||||
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
|
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
|
||||||
+ (e.getValue() ? "now" : "no longer") + " AFK.");
|
+ (e.getValue() ? "now" : "no longer") + " AFK.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onServerCommand(ServerCommandEvent e) {
|
||||||
|
DiscordPlugin.Restart = !e.getCommand().equalsIgnoreCase("stop"); // The variable is always true except if stopped
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue