Started using embeds for a nicer chat #23

Merged
NorbiPeti merged 4 commits from dev into master 2016-12-24 23:56:32 +00:00
3 changed files with 28 additions and 6 deletions
Showing only changes of commit 2f76583a87 - Show all commits

View file

@ -113,7 +113,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
dc.changeStatus(Status.game("testing"));
}
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() {
public void run() {
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
public void onDisable() {
stop = true;
getConfig().set("lastannouncementtime", lastannouncementtime);
getConfig().set("lastseentime", lastseentime);
saveConfig();
sendMessageToChannel(chatchannel, "Server restarting/stopping");
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
try {
dc.changeStatus(Status.game("on TBMC"));
dc.logout();

View file

@ -1,5 +1,6 @@
package buttondevteam.discordplugin.listeners;
import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
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.obj.IReaction;
import sx.blah.discord.handle.obj.IUser;
import sx.blah.discord.util.EmbedBuilder;
import sx.blah.discord.util.RateLimitException;
public class MCChatListener implements Listener, IListener<MessageReceivedEvent> {
@ -28,11 +30,17 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
return;
if (e.getSender() instanceof DiscordSender || e.getSender() instanceof DiscordPlayerSender)
return;
if (e.getChannel().equals(Channel.GlobalChat))
DiscordPlugin.sendMessageToChannel(DiscordPlugin.chatchannel,
DiscordPlugin.sanitizeString("<" + (e.getSender() instanceof Player //
if (e.getChannel().equals(Channel.GlobalChat)) {
final EmbedBuilder embed = new EmbedBuilder()
.withAuthorName(DiscordPlugin.sanitizeString(e.getSender() instanceof Player //
? ((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",

View file

@ -1,11 +1,14 @@
package buttondevteam.discordplugin.listeners;
import org.bukkit.Bukkit;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.server.ServerCommandEvent;
import buttondevteam.discordplugin.DiscordPlayer;
import buttondevteam.discordplugin.DiscordPlugin;
import buttondevteam.discordplugin.commands.ConnectCommand;
@ -61,4 +64,9 @@ public class MCListener implements Listener {
DiscordPlugin.sanitizeString(e.getAffected().getBase().getDisplayName()) + " is "
+ (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
}
}