Separated waiting and not waiting msg sends
This commit is contained in:
parent
1244b50560
commit
4ada764a04
4 changed files with 44 additions and 19 deletions
|
@ -128,7 +128,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
.withTitle("Server started - chat connected.").build());
|
||||
getConfig().set("serverup", true);
|
||||
saveConfig();
|
||||
perform(() -> {
|
||||
performNoWait(() -> {
|
||||
try {
|
||||
List<IMessage> msgs = genchannel.getPinnedMessages();
|
||||
for (int i = msgs.size() - 1; i >= 10; i--) { // Unpin all pinned messages except the newest 10
|
||||
|
@ -262,7 +262,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
}
|
||||
}
|
||||
if (msgsb.length() > 0)
|
||||
genchannel.pin(sendMessageToChannel(genchannel, msgsb.toString()));
|
||||
genchannel.pin(sendMessageToChannelWait(genchannel, msgsb.toString()));
|
||||
if (modmsgsb.length() > 0)
|
||||
sendMessageToChannel(annchannel, modmsgsb.toString());
|
||||
if (lastannouncementtime != lastanntime) {
|
||||
|
@ -282,11 +282,23 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
}
|
||||
}
|
||||
|
||||
public static IMessage sendMessageToChannel(IChannel channel, String message) {
|
||||
return sendMessageToChannel(channel, message, null);
|
||||
public static void sendMessageToChannel(IChannel channel, String message) {
|
||||
sendMessageToChannel(channel, message, null);
|
||||
}
|
||||
|
||||
public static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed) {
|
||||
public static void sendMessageToChannel(IChannel channel, String message, EmbedObject embed) {
|
||||
sendMessageToChannel(channel, message, null, false);
|
||||
}
|
||||
|
||||
public static IMessage sendMessageToChannelWait(IChannel channel, String message) {
|
||||
return sendMessageToChannelWait(channel, message, null);
|
||||
}
|
||||
|
||||
public static IMessage sendMessageToChannelWait(IChannel channel, String message, EmbedObject embed) {
|
||||
return sendMessageToChannel(channel, message, null, true);
|
||||
}
|
||||
|
||||
private static IMessage sendMessageToChannel(IChannel channel, String message, EmbedObject embed, boolean wait) {
|
||||
if (message.length() > 1900) {
|
||||
message = message.substring(0, 1900);
|
||||
Bukkit.getLogger()
|
||||
|
@ -298,8 +310,14 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
else if (channel.isPrivate())
|
||||
MCChatListener.resetLastMessage(channel);
|
||||
final String content = message;
|
||||
return perform(
|
||||
() -> embed == null ? channel.sendMessage(content) : channel.sendMessage(content, embed, false));
|
||||
RequestBuffer.IRequest<IMessage> r = () -> embed == null ? channel.sendMessage(content)
|
||||
: channel.sendMessage(content, embed, false);
|
||||
if (wait)
|
||||
return perform(r);
|
||||
else {
|
||||
performNoWait(r);
|
||||
return null;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
Bukkit.getLogger().warning(
|
||||
"Failed to deliver message to Discord! Channel: " + channel.getName() + " Message: " + message);
|
||||
|
@ -360,8 +378,20 @@ public class DiscordPlugin extends JavaPlugin implements IListener<ReadyEvent> {
|
|||
return RequestBuffer.request(action).get(); // Let the pros handle this
|
||||
}
|
||||
|
||||
public static void performNoWait(IVoidRequest action) {
|
||||
if (SafeMode)
|
||||
return;
|
||||
RequestBuffer.request(action);
|
||||
}
|
||||
|
||||
public static <T> void performNoWait(IRequest<T> action) {
|
||||
if (SafeMode)
|
||||
return;
|
||||
RequestBuffer.request(action);
|
||||
}
|
||||
|
||||
public static void updatePlayerList() {
|
||||
perform(() -> {
|
||||
performNoWait(() -> {
|
||||
String[] s = chatchannel.getTopic().split("\\n----\\n");
|
||||
if (s.length < 3)
|
||||
return;
|
||||
|
|
|
@ -13,7 +13,7 @@ public class AutoUpdaterListener implements Listener {
|
|||
if (DiscordPlugin.SafeMode)
|
||||
return;
|
||||
try {
|
||||
DiscordPlugin.perform(() -> DiscordPlugin.officechannel.getMessageHistory(10).stream()
|
||||
DiscordPlugin.performNoWait(() -> DiscordPlugin.officechannel.getMessageHistory(10).stream()
|
||||
.filter(m -> m.getWebhookLongID() == 239123781401051138L && m.getEmbeds().get(0).getTitle()
|
||||
.contains(event.getData().get("repository").getAsJsonObject().get("name").getAsString()))
|
||||
.findFirst().get().addReaction(DiscordPlugin.DELIVERED_REACTION));
|
||||
|
|
|
@ -62,7 +62,7 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
|| !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.sendMessageToChannel(lastmsgdata.channel, dmsg,
|
||||
lastmsgdata.message = DiscordPlugin.sendMessageToChannelWait(lastmsgdata.channel, dmsg,
|
||||
embedObject);
|
||||
lastmsgdata.time = nanoTime;
|
||||
lastmsgdata.mcchannel = e.getChannel();
|
||||
|
@ -87,12 +87,6 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
? lastmsgdata = new LastMsgData(DiscordPlugin.chatchannel, null, null) : lastmsgdata);
|
||||
|
||||
for (LastMsgData data : lastmsgPerUser) {
|
||||
// System.out.println("Data: " + data);
|
||||
// System.out.println("Data.channel: " + data.channel);
|
||||
// System.out.println("Sender: " + e.getSender());
|
||||
// System.out.println("Sender channel: " + ((DiscordSenderBase) e.getSender()).getChannel()); // TODO
|
||||
// System.out.println("Predicate: " + isdifferentchannel);
|
||||
// System.out.println("DP: " + data.dp); - Didn't update the constructor
|
||||
if (data.dp.isMinecraftChatEnabled() && isdifferentchannel.test(data.channel)
|
||||
&& e.shouldSendTo(getSender(data.channel, data.user, data.dp)))
|
||||
doit.accept(data);
|
||||
|
@ -337,12 +331,13 @@ public class MCChatListener implements Listener, IListener<MessageReceivedEvent>
|
|||
try {
|
||||
final IReaction reaction = m.getReactionByEmoji(DiscordPlugin.DELIVERED_REACTION);
|
||||
if (reaction != null)
|
||||
DiscordPlugin.perform(() -> m.removeReaction(DiscordPlugin.dc.getOurUser(), reaction));
|
||||
DiscordPlugin
|
||||
.performNoWait(() -> m.removeReaction(DiscordPlugin.dc.getOurUser(), reaction));
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while removing reactions from chat!", e);
|
||||
}
|
||||
});
|
||||
DiscordPlugin.perform(() -> event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION));
|
||||
DiscordPlugin.performNoWait(() -> event.getMessage().addReaction(DiscordPlugin.DELIVERED_REACTION));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
TBMCCoreAPI.SendException("An error occured while handling message \"" + dmessage + "\"!", e);
|
||||
|
|
|
@ -124,7 +124,7 @@ public class MCListener implements Listener {
|
|||
@EventHandler
|
||||
public void onPlayerMute(MuteStatusChangeEvent e) {
|
||||
try {
|
||||
DiscordPlugin.perform(() -> {
|
||||
DiscordPlugin.performNoWait(() -> {
|
||||
final IRole role = DiscordPlugin.dc.getRoleByID(164090010461667328L);
|
||||
final CommandSource source = e.getAffected().getSource();
|
||||
if (!source.isPlayer())
|
||||
|
|
Loading…
Reference in a new issue