diff --git a/src/main/java/buttondevteam/discordplugin/ChromaBot.java b/src/main/java/buttondevteam/discordplugin/ChromaBot.java index e597095..2db1a17 100755 --- a/src/main/java/buttondevteam/discordplugin/ChromaBot.java +++ b/src/main/java/buttondevteam/discordplugin/ChromaBot.java @@ -47,7 +47,7 @@ public class ChromaBot { /** * Send a message to the chat channels and private chats. - * + * * @param message * The message to send, duh * @param embed @@ -57,6 +57,16 @@ public class ChromaBot { MCChatListener.forAllMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message, embed)); } + /** + * Send a message to the chat channels, private chats and custom chats. + * + * @param message The message to send, duh + * @param embed Custom fancy stuff, use {@link EmbedBuilder} to create one + */ + public void sendMessageCustomAsWell(String message, EmbedObject embed) { + MCChatListener.forCustomAndAllMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message, embed)); + } + /** * Send a message to an arbitrary channel. This will not send it to the private chats. * diff --git a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java index 34669c4..d126523 100755 --- a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java +++ b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java @@ -158,17 +158,17 @@ public class DiscordPlugin extends JavaPlugin implements IListener { DiscordCommandBase.registerCommands(); if (ResetMCCommand.resetting) - ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.CYAN) + ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.CYAN) .withTitle("Discord plugin restarted - chat connected.").build()); //Really important to note the chat, hmm else if (getConfig().getBoolean("serverup", false)) { - ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.YELLOW) + ChromaBot.getInstance().sendMessageCustomAsWell("", 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 - ChromaBot.getInstance().sendMessage("", new EmbedBuilder().withColor(Color.GREEN) + ChromaBot.getInstance().sendMessageCustomAsWell("", new EmbedBuilder().withColor(Color.GREEN) .withTitle("Server started - chat connected.").build()); ResetMCCommand.resetting = false; //This is the last event handling this flag @@ -261,7 +261,7 @@ public class DiscordPlugin extends JavaPlugin implements IListener { } saveConfig(); - MCChatListener.forAllMCChat(ch -> { + MCChatListener.forCustomAndAllMCChat(ch -> { try { if (ResetMCCommand.resetting) DiscordPlugin.sendMessageToChannelWait(ch, "", diff --git a/src/main/java/buttondevteam/discordplugin/listeners/MCChatListener.java b/src/main/java/buttondevteam/discordplugin/listeners/MCChatListener.java index 49bcf63..89f02be 100755 --- a/src/main/java/buttondevteam/discordplugin/listeners/MCChatListener.java +++ b/src/main/java/buttondevteam/discordplugin/listeners/MCChatListener.java @@ -2,10 +2,7 @@ package buttondevteam.discordplugin.listeners; import buttondevteam.discordplugin.*; import buttondevteam.discordplugin.playerfaker.VanillaCommandListener; -import buttondevteam.lib.TBMCChatEvent; -import buttondevteam.lib.TBMCChatPreprocessEvent; -import buttondevteam.lib.TBMCCoreAPI; -import buttondevteam.lib.TBMCSystemChatEvent; +import buttondevteam.lib.*; import buttondevteam.lib.chat.Channel; import buttondevteam.lib.chat.ChatMessage; import buttondevteam.lib.chat.ChatRoom; @@ -17,6 +14,7 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.val; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; @@ -255,8 +253,7 @@ public class MCChatListener implements Listener, IListener // The maps may not contain the senders for UnconnectedSenders public static boolean isMinecraftChatEnabled(DiscordPlayer dp) { - return lastmsgPerUser.stream().anyMatch( - lmd -> ((IPrivateChannel) lmd.channel).getRecipient().getStringID().equals(dp.getDiscordID())); + return isMinecraftChatEnabled(dp.getDiscordID()); } public static boolean isMinecraftChatEnabled(String did) { // Don't load the player data just for this @@ -330,9 +327,22 @@ public class MCChatListener implements Listener, IListener action.accept(DiscordPlugin.chatchannel); for (LastMsgData data : lastmsgPerUser) action.accept(data.channel); + // lastmsgCustom.forEach(cc -> action.accept(cc.channel)); - Only send relevant messages to custom chat + } + + public static void forCustomAndAllMCChat(Consumer action) { + forAllMCChat(action); lastmsgCustom.forEach(cc -> action.accept(cc.channel)); } + public static void forAllowedCustomMCChat(Consumer action, CommandSender sender) { + lastmsgCustom.stream().filter(clmd -> { + //new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel).shouldSendTo(clmd.dcp) - Thought it was this simple hehe - Wait, it *should* be this simple + val e = new TBMCChannelConnectFakeEvent(sender, clmd.mcchannel); + return clmd.groupID.equals(e.getGroupID(sender)); + }).forEach(cc -> action.accept(cc.channel)); //TODO: Use getScore and getGroupID in fake event constructor - This should also send error messages on channel connect + } + private static void forAllowedMCChat(Consumer action, TBMCSystemChatEvent event) { if (Channel.GlobalChat.ID.equals(event.getChannel().ID)) action.accept(DiscordPlugin.chatchannel); diff --git a/src/main/java/buttondevteam/discordplugin/listeners/MCListener.java b/src/main/java/buttondevteam/discordplugin/listeners/MCListener.java index 74ee6a2..2a86220 100755 --- a/src/main/java/buttondevteam/discordplugin/listeners/MCListener.java +++ b/src/main/java/buttondevteam/discordplugin/listeners/MCListener.java @@ -62,8 +62,10 @@ public class MCListener implements Listener { + " do /discord accept"); p.sendMessage("§bIf it wasn't you, do /discord decline"); } + final String message = e.GetPlayer().PlayerName().get() + " joined the game"; if (!DiscordPlugin.hooked) - MCChatListener.sendSystemMessageToChat(e.GetPlayer().PlayerName().get() + " joined the game"); + MCChatListener.sendSystemMessageToChat(message); + MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer()); MCChatListener.ListC = 0; ChromaBot.getInstance().updatePlayerList(); }); @@ -81,6 +83,10 @@ public class MCListener implements Listener { .ifPresent(dcp -> callEventExcludingSome(new PlayerJoinEvent(dcp, "")))); Bukkit.getScheduler().runTaskLaterAsynchronously(DiscordPlugin.plugin, ChromaBot.getInstance()::updatePlayerList, 5); + final String message = e.GetPlayer().PlayerName().get() + " left the game"; + if (!DiscordPlugin.hooked) + MCChatListener.sendSystemMessageToChat(message); //TODO: Probably double sends if kicked and unhooked + MCChatListener.forAllowedCustomMCChat(ch -> DiscordPlugin.sendMessageToChannel(ch, message), e.getPlayer()); } @EventHandler(priority = EventPriority.HIGHEST) @@ -111,7 +117,7 @@ public class MCListener implements Listener { } @EventHandler - public void onPlayerAFK(AfkStatusChangeEvent e) { + public void onPlayerAFK(AfkStatusChangeEvent e) { //TODO: Add AFK to custom chats? if (e.isCancelled() || !e.getAffected().getBase().isOnline()) return; MCChatListener.sendSystemMessageToChat(DPUtils.sanitizeString(e.getAffected().getBase().getDisplayName())