Channel IDs shown always + more
* Server restart/stop now sends to PMs * Special handling of players kicked because of shutdown/restart * Enter safe mode on disable so actions won't be attempted to be performed anymore * Channel ID relocation in PMs also has the effect of showing the actual message in notifications
This commit is contained in:
parent
faa1c96a4b
commit
6027315d09
5 changed files with 33 additions and 15 deletions
|
@ -36,8 +36,8 @@ public final class DPUtils {
|
|||
public static <T> T perform(IRequest<T> action) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
return null;
|
||||
if (Thread.currentThread() == DiscordPlugin.mainThread)
|
||||
throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
||||
// if (Thread.currentThread() == DiscordPlugin.mainThread) - TODO: Ignore shutdown message <--
|
||||
// throw new RuntimeException("Tried to wait for a Discord request on the main thread. This could cause lag.");
|
||||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.ArrayList;
|
|||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
@ -125,15 +126,16 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
if (task != null)
|
||||
task.cancel();
|
||||
if (!sent) {
|
||||
new ChromaBot(this).updatePlayerList();
|
||||
if (getConfig().getBoolean("serverup", false)) {
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.YELLOW)
|
||||
ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.YELLOW)
|
||||
.withTitle("Server recovered from a crash - chat connected.").build());
|
||||
val thr = new Throwable(
|
||||
"The server shut down unexpectedly. See the log of the previous run for more details.");
|
||||
thr.setStackTrace(new StackTraceElement[0]);
|
||||
TBMCCoreAPI.SendException("The server crashed!", thr);
|
||||
} else
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Color.GREEN)
|
||||
ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.GREEN)
|
||||
.withTitle("Server started - chat connected.").build());
|
||||
getConfig().set("serverup", true);
|
||||
saveConfig();
|
||||
|
@ -168,7 +170,6 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
"You could make a religion out of this");
|
||||
}
|
||||
}
|
||||
new ChromaBot(this).updatePlayerList();
|
||||
}
|
||||
}, 0, 10);
|
||||
for (IListener<?> listener : CommandListener.getListeners())
|
||||
|
@ -211,9 +212,20 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
getConfig().set("gameroles", GameRoles);
|
||||
getConfig().set("serverup", false);
|
||||
saveConfig();
|
||||
sendMessageToChannel(chatchannel, "", new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||
.withTitle(Restart ? "Server restarting" : "Server stopping").build());
|
||||
MCChatListener.forAllMCChat(ch -> DiscordPlugin.sendMessageToChannelWait(ch, "",
|
||||
new EmbedBuilder().withColor(Restart ? Color.ORANGE : Color.RED)
|
||||
.withTitle(Restart ? "Server restarting" : "Server stopping")
|
||||
.withDescription(
|
||||
Bukkit.getOnlinePlayers().size() > 0
|
||||
? (DPUtils
|
||||
.sanitizeString(Bukkit.getOnlinePlayers().stream()
|
||||
.map(p -> p.getDisplayName()).collect(Collectors.joining(", ")))
|
||||
+ (Bukkit.getOnlinePlayers().size() == 1 ? " was " : " were ")
|
||||
+ "asked *politely* to leave the server for a bit.")
|
||||
: "")
|
||||
.build()));
|
||||
try {
|
||||
SafeMode = true; // Stop interacting with Discord
|
||||
ChromaBot.delete();
|
||||
dc.online("on TBMC");
|
||||
dc.logout();
|
||||
|
|
|
@ -54,17 +54,17 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
+ ((DiscordSenderBase) e.getSender()).getUser().getStringID()); // TODO: Constant/method to get URLs like this
|
||||
if (e.getSender() instanceof DiscordSenderBase)
|
||||
embed.withAuthorName("[D]" + authorPlayer);
|
||||
// embed.withFooterText(e.getChannel().DisplayName);
|
||||
final long nanoTime = System.nanoTime();
|
||||
Consumer<LastMsgData> doit = lastmsgdata -> {
|
||||
final EmbedObject embedObject = embed.build();
|
||||
final String dmsg = lastmsgdata.channel.isPrivate()
|
||||
? DPUtils.sanitizeString(e.getChannel().DisplayName)
|
||||
: "";
|
||||
embedObject.author.name = "[" + DPUtils.sanitizeString(e.getChannel().DisplayName) + "] "
|
||||
+ embedObject.author.name;
|
||||
if (lastmsgdata.message == null || lastmsgdata.message.isDeleted()
|
||||
|| !authorPlayer.equals(lastmsgdata.message.getEmbeds().get(0).getAuthor().getName())
|
||||
|| lastmsgdata.time / 1000000000f < nanoTime / 1000000000f - 120
|
||||
|| !lastmsgdata.mcchannel.ID.equals(e.getChannel().ID)) {
|
||||
lastmsgdata.message = DiscordPlugin.sendMessageToChannelWait(lastmsgdata.channel, dmsg,
|
||||
lastmsgdata.message = DiscordPlugin.sendMessageToChannelWait(lastmsgdata.channel, "",
|
||||
embedObject); // TODO Use ChromaBot API
|
||||
lastmsgdata.time = nanoTime;
|
||||
lastmsgdata.mcchannel = e.getChannel();
|
||||
|
@ -74,7 +74,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
lastmsgdata.content = embedObject.description = lastmsgdata.content + "\n"
|
||||
+ embedObject.description;// The message object doesn't get updated
|
||||
final LastMsgData _lastmsgdata = lastmsgdata;
|
||||
DPUtils.perform(() -> _lastmsgdata.message.edit(dmsg, embedObject));
|
||||
DPUtils.perform(() -> _lastmsgdata.message.edit("", embedObject));
|
||||
} catch (MissingPermissionsException | DiscordException e1) {
|
||||
TBMCCoreAPI.SendException("An error occured while editing chat message!", e1);
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.bukkit.event.HandlerList;
|
|||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerKickEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
@ -86,12 +87,17 @@ public class MCListener implements Listener {
|
|||
() -> MCChatListener.ConnectedSenders.values().stream()
|
||||
.filter(s -> s.getUniqueId().equals(e.getPlayer().getUniqueId())).findAny()
|
||||
.ifPresent(dcp -> callEventExcludingSome(new PlayerJoinEvent(dcp, ""))));
|
||||
if (!DiscordPlugin.hooked)
|
||||
MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " left the game");
|
||||
Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin,
|
||||
ChromaBot.getInstance()::updatePlayerList, 5);
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.HIGHEST)
|
||||
public void onPlayerKick(PlayerKickEvent e) {
|
||||
if (!DiscordPlugin.hooked && !e.getReason().equals("The server is restarting")
|
||||
&& !e.getReason().equals("Server closed")) // The leave messages errored with the previous setup, I could make it wait since I moved it here, but instead I have a special
|
||||
MCChatListener.sendSystemMessageToChat(e.getPlayer().getName() + " left the game"); // message for this - Oh wait this doesn't even send normally because of the hook
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onGetInfo(TBMCPlayerGetInfoEvent e) {
|
||||
if (DiscordPlugin.SafeMode)
|
||||
|
|
|
@ -67,7 +67,7 @@ public abstract class DiscordLivingEntity extends DiscordEntity implements Livin
|
|||
}
|
||||
|
||||
@Override
|
||||
public AttributeInstance getAttribute(Attribute attribute) { // We don't support any attribute
|
||||
public AttributeInstance getAttribute(Attribute attribute) { // We don't support any attributes
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue