use of org.spongepowered.api.event.message.MessageChannelEvent in project SpongeCommon by SpongePowered.
the class ChatUtil method sendMessage.
public static void sendMessage(ITextComponent component, MessageChannel channel, CommandSource source, boolean isChat) {
Text raw = SpongeTexts.toText(component);
MessageFormatter formatter = new MessageEvent.MessageFormatter(raw);
final boolean isMainThread = Sponge.isServerAvailable() && Sponge.getServer().isMainThread();
Cause cause = isMainThread ? Sponge.getCauseStackManager().getCurrentCause() : Cause.of(EventContext.empty(), source);
MessageChannelEvent event;
if (isChat) {
event = SpongeEventFactory.createMessageChannelEventChat(cause, channel, Optional.of(channel), formatter, raw, false);
} else {
event = SpongeEventFactory.createMessageChannelEvent(cause, channel, Optional.of(channel), formatter, false);
}
if (!SpongeImpl.postEvent(event) && !event.isMessageCancelled() && event.getChannel().isPresent()) {
event.getChannel().get().send(source, event.getMessage(), isChat ? ChatTypes.CHAT : ChatTypes.SYSTEM);
}
}
use of org.spongepowered.api.event.message.MessageChannelEvent in project UltimateChat by FabioZumbi12.
the class UCChannel method sendMessage.
/**
* Send a message from a channel as player.
* @param src {@code Player}
* @param message {@code Text} - Message to send.
* @param direct {@code boolean} - Send message direct to players on channel.
*/
public void sendMessage(Player src, Text message, boolean direct) {
if (direct) {
for (Player p : Sponge.getServer().getOnlinePlayers()) {
UCChannel chp = UChat.get().getPlayerChannel(p);
if (UChat.get().getPerms().channelReadPerm(p, this) && !this.isIgnoring(p.getName()) && (!this.neeFocus() || chp.equals(this))) {
UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Direct Message");
p.sendMessage(message);
}
}
src.sendMessage(message);
} else {
MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(UChat.get().getVHelper().getCause(src), src.getMessageChannel(), Optional.of(src.getMessageChannel()), new MessageEvent.MessageFormatter(Text.builder("<" + src.getName() + "> ").onShiftClick(TextActions.insertText(src.getName())).onClick(TextActions.suggestCommand("/msg " + src.getName())).build(), message), message, false);
UChat.get().getLogger().timings(timingType.START, "UCChannel#sendMessage()|Fire MessageChannelEvent");
if (!Sponge.getEventManager().post(event)) {
UChat.get().tempChannels.put(src.getName(), this.getAlias());
}
}
}
Aggregations