Some chat msg and user data changes

This commit is contained in:
Norbi Peti 2018-10-25 14:09:58 +02:00
parent 7ab997ddad
commit e13efa5e65
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
2 changed files with 17 additions and 4 deletions

View file

@ -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)}.<br>
* 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();

View file

@ -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 extends ChromaGamerBase> T getFromSender(CommandSender sender, Class<T> 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;
}