From e13efa5e6589b4190e09f8fe2a3211223ef4f13b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Thu, 25 Oct 2018 14:09:58 +0200 Subject: [PATCH] Some chat msg and user data changes --- .../java/buttondevteam/lib/chat/TBMCChatAPI.java | 13 ++++++++++++- .../buttondevteam/lib/player/ChromaGamerBase.java | 8 +++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java index 1b4c635..b3efcb2 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/chat/TBMCChatAPI.java @@ -214,7 +214,18 @@ public class TBMCChatAPI { * @return The event cancelled state */ public static boolean SendChatMessage(ChatMessage cm) { - val channel = cm.getUser().channel().get(); + return SendChatMessage(cm, cm.getUser().channel().get()); + } + + /** + * Sends a chat message to Minecraft. Make sure that the channel is registered with {@link #RegisterChatChannel(Channel)}.
+ * This will also send the error message to the sender, if they can't send the message. + * + * @param cm The message to send + * @param channel The MC channel to send in + * @return The event cancelled state + */ + public static boolean SendChatMessage(ChatMessage cm, Channel channel) { if (!Channel.getChannels().contains(channel)) throw new RuntimeException("Channel " + channel.DisplayName + " not registered!"); val permcheck = cm.getPermCheck() == null ? cm.getSender() : cm.getPermCheck(); diff --git a/ButtonCore/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java b/ButtonCore/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java index 33c5ac0..571e0fc 100755 --- a/ButtonCore/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java +++ b/ButtonCore/src/main/java/buttondevteam/lib/player/ChromaGamerBase.java @@ -112,13 +112,15 @@ public abstract class ChromaGamerBase implements AutoCloseable { * Get from the given sender. May be null,.but shouldn't be. * * @param sender The sender to use + * @param cl The type of the requested user object - subclasses of {@link TBMCPlayerBase} don't work, use {@link TBMCPlayer} * @return A user as returned by a converter or null if none can supply it */ - public static ChromaGamerBase getFromSender(CommandSender sender) { + @SuppressWarnings("unchecked") + public static T getFromSender(CommandSender sender, Class cl) { for (val converter : senderConverters) { - val ocg = converter.apply(sender); + val ocg = converter.apply(sender).filter(cg -> cl.isAssignableFrom(cg.getClass())); if (ocg.isPresent()) - return ocg.get(); + return (T) ocg.get(); } return null; }