org.spongepowered.api.event.message.MessageChannelEvent Java Examples

The following examples show how to use org.spongepowered.api.event.message.MessageChannelEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UCCommands.java    From UltimateChat with GNU General Public License v3.0 6 votes vote down vote up
private void sendPreTell(CommandSource sender, CommandSource receiver, Text msg) {
    CommandSource src = sender;
    if (sender instanceof ConsoleSource) {
        src = receiver;
    }

    UChat.get().getLogger().timings(UCLogger.timingType.START, "UCListener#sendPreTell()|Fire AsyncPlayerChatEvent");

    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(), msg),
            msg,
            false);
    Sponge.getEventManager().post(event);
}
 
Example #2
Source File: PokeListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onChat(MessageChannelEvent.Chat event) {
    String message = event.getRawMessage().toPlain();
    for (Player p : Sponge.getServer().getOnlinePlayers()) {
        if (message.contains(p.getName())) {
            ModuleConfig config = Modules.POKE.get().getConfig().get();
            CommentedConfigurationNode node = config.get();
            String soundname = node.getNode("sound", "sound").getString();
            String categoryname = node.getNode("sound", "category").getString();
            Double volume = node.getNode("sound", "volume").getDouble();
            Double pitch = node.getNode("sound", "pitch").getDouble();
            Double minVolume = node.getNode("sound", "minVolume").getDouble();
            SoundType type = Sponge.getRegistry().getType(CatalogTypes.SOUND_TYPE, soundname.toUpperCase()).get();
            //TODO wait for CatalogTypes.SOUND_CATEGORY to be added
            SoundCategory category;
            try {
                category = Sponge.getRegistry().getType(CatalogTypes.SOUND_CATEGORY, categoryname.toUpperCase()).get();
            } catch (Error ex) {
                category = SoundCategories.PLAYER;
            }
            p.playSound(type, category, p.getLocation().getPosition(), volume, pitch, minVolume);
        }
    }
}
 
Example #3
Source File: SpyListener.java    From UltimateCore with MIT License 6 votes vote down vote up
@Listener
public void onWhisper(MessageChannelEvent e) {
    if (!Modules.PERSONALMESSAGE.isPresent()) {
        return;
    }
    if (e instanceof PersonalmessageEvent) {
        PersonalmessageEvent ev = (PersonalmessageEvent) e;
        CommandSource s = ev.getPMSender();
        CommandSource t = ev.getPMTarget();

        for (Player p : Sponge.getServer().getOnlinePlayers()) {
            if (!p.hasPermission(SpyPermissions.UC_SPY_MESSAGESPY_SEE.get())) {
                continue;
            }
            if (s.getIdentifier().equals(p.getIdentifier()) || t.getIdentifier().equals(p.getIdentifier())) {
                continue;
            }
            if (!UltimateCore.get().getUserService().getUser(p).get(SpyKeys.MESSAGESPY_ENABLED).get()) {
                continue;
            }
            Messages.send(p, "spy.format.messagespy", "%player%", s, "%target%", t, "%message%", ev.getPMUnformattedMessage());
        }
    }
}
 
Example #4
Source File: SpongeChatListener.java    From Plan with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
    if (event.isCancelled()) {
        return;
    }

    try {
        actOnChatEvent(player);
    } catch (Exception e) {
        errorLogger.log(L.ERROR, e, ErrorContext.builder().related(event).build());
    }
}
 
Example #5
Source File: ChatUILib.java    From ChatUI with MIT License 5 votes vote down vote up
@Listener(order = Order.PRE, beforeModifications = true)
@IsCancelled(Tristate.UNDEFINED)
public void onIncomingMessage(MessageChannelEvent.Chat event, @Root Player player) {
    if (getView(player).handleIncoming(event.getRawMessage())) {
        // No plugins should interpret this as chat
        event.setCancelled(true);
        event.setChannel(MessageChannel.TO_NONE);
    }
}
 
Example #6
Source File: UCChannel.java    From UltimateChat with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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());
        }
    }
}
 
Example #7
Source File: ChatListener.java    From Nations with MIT License 5 votes vote down vote up
@Listener(order = Order.LATE)
public void onPlayerChat(MessageChannelEvent.Chat e, @First Player p)
{
	Nation nation = DataHandler.getNationOfPlayer(p.getUniqueId());
	if (nation == null)
	{
		return;
	}
	MessageChannel chan = MessageChannel.TO_ALL;
	Optional<MessageChannel> channel = e.getChannel();
	if (channel.isPresent())
	{
		chan = channel.get();
	}
	
	MessageFormatter formater = e.getFormatter();
	
	if (chan.equals(MessageChannel.TO_ALL) && ConfigHandler.getNode("others", "enableNationTag").getBoolean(true))
	{
		e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "publicChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), formater.getHeader().toText()), formater.getBody().toText());
	}
	else if (chan instanceof NationMessageChannel)
	{
		e.setMessage(Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationChatFormat").getString().replaceAll("\\{NATION\\}", nation.getTag()).replaceAll("\\{TITLE\\}", DataHandler.getCitizenTitle(p.getUniqueId()))), formater.getHeader().toText()), Text.of(TextColors.YELLOW, formater.getBody().toText()));
		DataHandler.getSpyChannel().send(p, Text.of(TextSerializers.FORMATTING_CODE.deserialize(ConfigHandler.getNode("others", "nationSpyChatTag").getString()), TextColors.RESET, e.getMessage()));
	}
}
 
Example #8
Source File: CacheService.java    From Web-API with MIT License 5 votes vote down vote up
@Listener(order = Order.POST)
public void onMessage(MessageChannelEvent event) {
    Optional<Player> player = event.getCause().first(Player.class);

    MessageChannel channel = event.getChannel().orElse(event.getOriginalChannel());
    CachedMessage msg = player.isPresent() ?
            new CachedChatMessage(player.get(), channel.getMembers(), event.getMessage()) :
            new CachedMessage(channel.getMembers(), event.getMessage());
    messages.add(msg);

    while (messages.size() > numChatMessages) {
        messages.poll();
    }
}
 
Example #9
Source File: JailListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onChat(MessageChannelEvent.Chat event, @First Player p) {
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(JailKeys.JAIL).isPresent()) {
        if (!Modules.JAIL.get().getConfig().get().get().getNode("allow-chat").getBoolean()) {
            JailData data = up.get(JailKeys.JAIL).get();
            event.setCancelled(true);
            Messages.send(p, "jail.event.chat", "%time%", (data.getEndtime() == -1L ? Messages.getFormatted("core.time.ever") : TimeUtil.formatDateDiff(data.getEndtime())), "%reason%", data.getReason());
        }
    }
}
 
Example #10
Source File: MuteListener.java    From UltimateCore with MIT License 5 votes vote down vote up
@Listener
public void onChat(MessageChannelEvent.Chat event) {
    Player p = event.getCause().first(Player.class).orElse(null);
    if (p == null) return;
    UltimateUser up = UltimateCore.get().getUserService().getUser(p);
    if (up.get(MuteKeys.MUTE).isPresent()) {
        Mute mute = up.get(MuteKeys.MUTE).get();
        event.setCancelled(true);
        Messages.send(p, "mute.muted", "%time%", (mute.getEndtime() == -1L ? Messages.getFormatted("core.time.ever") : Text.of(TimeUtil.formatDateDiff(mute.getEndtime()))), "%reason%", mute.getReason());
    }
}
 
Example #11
Source File: PlayerEventHandler.java    From GriefDefender with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
    if (!GriefDefenderPlugin.getInstance().claimsEnabledForWorld(player.getWorld().getUniqueId())) {
        return;
    }

    GDTimings.PLAYER_CHAT_EVENT.startTimingIfSync();
    final GDPlayerData playerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(player.getWorld(), player.getUniqueId());
    // check for command input
    if (playerData.isWaitingForInput()) {
        playerData.commandInput = event.getRawMessage().toPlain();
        playerData.commandConsumer.accept(player);
        event.setCancelled(true);
        return;
    }

    if (playerData.inTown && playerData.townChat) {
        final MessageChannel channel = event.getChannel().orElse(null);
        if (GriefDefenderPlugin.getInstance().nucleusApiProvider != null && channel != null) {
            if (GriefDefenderPlugin.getInstance().nucleusApiProvider.isChatChannel(channel)) {
                GDTimings.PLAYER_CHAT_EVENT.stopTimingIfSync();
                return;
            }
        }
        final GDClaim sourceClaim = this.dataStore.getClaimAtPlayer(playerData, player.getLocation());
        if (sourceClaim.isInTown()) {
            playerData.inTown = true;
        } else {
            playerData.inTown = false;
        }
        final GDClaim sourceTown = sourceClaim.getTownClaim();
        final Component townTag = sourceTown.getTownData().getTownTag().orElse(null);

        Text header = event.getFormatter().getHeader().toText();
        Text body = event.getFormatter().getBody().toText();
        Text footer = event.getFormatter().getFooter().toText();
        Text townMessage = Text.of(TextColors.GREEN, body);
        if (townTag != null) {
            townMessage = Text.of(SpongeUtil.getSpongeText(townTag), townMessage);
        }
        event.setMessage(townMessage);
        Set<CommandSource> recipientsToRemove = new HashSet<>();
        Iterator<MessageReceiver> iterator = event.getChannel().get().getMembers().iterator();
        while (iterator.hasNext()) {
            MessageReceiver receiver = iterator.next();
            if (receiver instanceof Player) {
                Player recipient = (Player) receiver;
                if (GriefDefenderPlugin.getInstance().nucleusApiProvider != null) {
                    if (NucleusProvider.getPrivateMessagingService().isPresent() && NucleusProvider.getPrivateMessagingService().get().isSocialSpy(recipient)) {
                        // always allow social spy users
                        continue;
                    }
                }

                final GDPlayerData targetPlayerData = GriefDefenderPlugin.getInstance().dataStore.getOrCreatePlayerData(recipient.getWorld(), recipient.getUniqueId());
                if (!targetPlayerData.inTown) {
                    recipientsToRemove.add(recipient);
                    continue;
                }

                final GDClaim targetClaim = this.dataStore.getClaimAtPlayer(targetPlayerData, recipient.getLocation());
                final GDClaim targetTown = targetClaim.getTownClaim();
                if (targetPlayerData.canIgnoreClaim(targetClaim)) {
                    continue;
                }
                if (sourceTown != null && (targetTown == null || !sourceTown.getUniqueId().equals(targetTown.getUniqueId()))) {
                    recipientsToRemove.add(recipient);
                }
            }
        }

        if (!recipientsToRemove.isEmpty()) {
            Set<MessageReceiver> newRecipients = Sets.newHashSet(event.getChannel().get().getMembers().iterator());
            newRecipients.removeAll(recipientsToRemove);
            event.setChannel(new FixedMessageChannel(newRecipients));
        }
    }

    GDTimings.PLAYER_CHAT_EVENT.stopTimingIfSync();
}
 
Example #12
Source File: SpongeAFKListener.java    From Plan with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
    performedAction(player);
}
 
Example #13
Source File: WebHookService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onPlayerChat(MessageChannelEvent.Chat event, @First Player player) {
    notifyHooks(WebHookService.WebHookType.CHAT, event);
}
 
Example #14
Source File: WebHookService.java    From Web-API with MIT License 4 votes vote down vote up
@Listener(order = Order.POST)
public void onMessage(MessageChannelEvent event) {
    notifyHooks(WebHookService.WebHookType.CHAT, event);
}
 
Example #15
Source File: PreventListener.java    From FlexibleLogin with MIT License 4 votes vote down vote up
@Listener(order = Order.FIRST, beforeModifications = true)
public void onChat(MessageChannelEvent.Chat chatEvent, @First Player player) {
    checkLoginStatus(chatEvent, player);
}