Search in sources :

Example 11 with MessageChannel

use of org.spongepowered.api.text.channel.MessageChannel in project Nucleus by NucleusPowered.

the class KickAllCommand method executeCommand.

@Override
public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
    String r = args.<String>getOne(reason).orElse(plugin.getMessageProvider().getMessageWithFormat("command.kick.defaultreason"));
    Boolean f = args.<Boolean>getOne("w").orElse(false);
    if (f) {
        Sponge.getServer().setHasWhitelist(true);
    }
    // Don't kick self
    Sponge.getServer().getOnlinePlayers().stream().filter(x -> !(src instanceof Player) || !((Player) src).getUniqueId().equals(x.getUniqueId())).collect(Collectors.toList()).forEach(x -> x.kick(TextSerializers.FORMATTING_CODE.deserialize(r)));
    MessageChannel mc = MessageChannel.fixed(Sponge.getServer().getConsole(), src);
    mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.kickall.message"));
    mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.reason", r));
    if (f) {
        mc.send(plugin.getMessageProvider().getTextMessageWithFormat("command.kickall.whitelist"));
    }
    return CommandResult.success();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MessageChannel(org.spongepowered.api.text.channel.MessageChannel)

Example 12 with MessageChannel

use of org.spongepowered.api.text.channel.MessageChannel in project TriggerReactor by wysohn.

the class ScriptEditManager method onChat.

@Listener
public void onChat(MessageChannelEvent.Chat e, @First Player sender) {
    SpongeScriptEditorUser editorUser = new SpongeScriptEditorUser(sender);
    if (editings.containsKey(editorUser)) {
        e.setCancelled(true);
        ScriptEditor editor = editings.get(editorUser);
        if (viewingUsage.remove(editorUser)) {
            editor.printScript(editorUser);
            return;
        }
        Text message = e.getRawMessage();
        String arg1 = message.toPlainSingle();
        if (arg1.equals("save")) {
            try {
                editor.save();
            } catch (IOException | ScriptException ex) {
                plugin.handleException(e, ex);
            } finally {
                editings.remove(editorUser);
                editorUser.sendMessage("&aSaved!");
            }
        } else if (arg1.equals("exit")) {
            if (exitDoublecheck.remove(editorUser)) {
                editings.remove(editorUser);
                editorUser.sendMessage("&7Done");
            } else {
                exitDoublecheck.add(editorUser);
                editorUser.sendMessage("&6Are you sure to exit? &cUnsaved data will be all discared! " + "&dType &6exit &done more time to confirm.");
            }
            return;
        } else if (arg1.equals("il")) {
            editor.insertNewLine();
        } else if (arg1.equals("dl")) {
            editor.deleteLine();
        } else if (arg1.length() > 0 && arg1.charAt(0) == 'u') {
            String[] split = arg1.split(" ");
            int lines = 1;
            try {
                lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
            } catch (NumberFormatException ex) {
                plugin.handleException(e, ex);
            }
            editor.up(lines);
        } else if (arg1.length() > 0 && arg1.charAt(0) == 'd') {
            String[] split = arg1.split(" ");
            int lines = 1;
            try {
                lines = split.length > 1 ? Integer.parseInt(split[1]) : 1;
            } catch (NumberFormatException ex) {
                plugin.handleException(e, ex);
            }
            editor.down(lines);
        } else {
            if (!exitDoublecheck.remove(editorUser)) {
                editor.intput(arg1.replaceAll("\\^", " "));
            }
        }
        editor.printScript(editorUser);
    } else {
        MessageChannel channel = e.getOriginalChannel();
        Collection<MessageReceiver> copy = new LinkedList<>();
        for (Iterator<MessageReceiver> iter = channel.getMembers().iterator(); iter.hasNext(); ) {
            MessageReceiver receiver = iter.next();
            if (receiver instanceof Player) {
                SpongeScriptEditorUser receivingUser = new SpongeScriptEditorUser((Player) receiver);
                if (!editings.containsKey(receivingUser))
                    copy.add(receiver);
            }
        }
        e.setChannel(MessageChannel.fixed(copy));
    }
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) Text(org.spongepowered.api.text.Text) IOException(java.io.IOException) ScriptEditor(io.github.wysohn.triggerreactor.tools.ScriptEditor) ScriptException(javax.script.ScriptException) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageReceiver(org.spongepowered.api.text.channel.MessageReceiver) Listener(org.spongepowered.api.event.Listener)

Example 13 with MessageChannel

use of org.spongepowered.api.text.channel.MessageChannel in project SpongeVanilla by SpongePowered.

the class NetHandlerPlayServerMixin_Vanilla method vanilla$onProcessChatMessage.

@Inject(method = "processChatMessage", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;sendMessage(Lnet/minecraft/util/text/ITextComponent;Z)V"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD)
private void vanilla$onProcessChatMessage(CPacketChatMessage packet, CallbackInfo ci, String s, ITextComponent component) {
    ChatFormatter.formatChatComponent((TextComponentTranslation) component);
    // safe cast
    final Text[] message = SpongeTexts.splitChatMessage((TextComponentTranslation) component);
    final MessageChannel originalChannel = ((Player) this.player).getMessageChannel();
    Sponge.getCauseStackManager().pushCause(this.player);
    final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(message[0], message[1]), Text.of(s), false);
    if (!SpongeImpl.postEvent(event) && !event.isMessageCancelled()) {
        event.getChannel().ifPresent(channel -> channel.send(this.player, event.getMessage(), ChatTypes.CHAT));
    } else {
        ci.cancel();
    }
    Sponge.getCauseStackManager().popCause();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Text(org.spongepowered.api.text.Text) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 14 with MessageChannel

use of org.spongepowered.api.text.channel.MessageChannel in project SpongeCommon by SpongePowered.

the class MixinEntityPlayerMP method simulateChat.

@Override
public MessageChannelEvent.Chat simulateChat(Text message, Cause cause) {
    checkNotNull(message, "message");
    TextComponentTranslation component = new TextComponentTranslation("chat.type.text", SpongeTexts.toComponent(this.getDisplayNameText()), SpongeTexts.toComponent(message));
    final Text[] messages = SpongeTexts.splitChatMessage(component);
    final MessageChannel originalChannel = this.getMessageChannel();
    final MessageChannelEvent.Chat event = SpongeEventFactory.createMessageChannelEventChat(cause, originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(messages[0], messages[1]), message, false);
    if (!SpongeImpl.postEvent(event) && !event.isMessageCancelled()) {
        event.getChannel().ifPresent(channel -> channel.send(this, event.getMessage(), ChatTypes.CHAT));
    }
    return event;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageChannelEvent(org.spongepowered.api.event.message.MessageChannelEvent) MessageEvent(org.spongepowered.api.event.message.MessageEvent) Text(org.spongepowered.api.text.Text)

Example 15 with MessageChannel

use of org.spongepowered.api.text.channel.MessageChannel in project SpongeCommon by SpongePowered.

the class MixinNetHandlerPlayServer method onDisconnectHandler.

@Redirect(method = "onDisconnect", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/management/PlayerList;sendMessage(Lnet/minecraft/util/text/ITextComponent;)V"))
public void onDisconnectHandler(PlayerList this$0, ITextComponent component) {
    // be fired either.
    if (this.player.connection == null) {
        return;
    }
    final Player player = ((Player) this.player);
    final Text message = SpongeTexts.toText(component);
    final MessageChannel originalChannel = player.getMessageChannel();
    Sponge.getCauseStackManager().pushCause(player);
    final ClientConnectionEvent.Disconnect event = SpongeEventFactory.createClientConnectionEventDisconnect(Sponge.getCauseStackManager().getCurrentCause(), originalChannel, Optional.of(originalChannel), new MessageEvent.MessageFormatter(message), player, false);
    SpongeImpl.postEvent(event);
    Sponge.getCauseStackManager().popCause();
    if (!event.isMessageCancelled()) {
        event.getChannel().ifPresent(channel -> channel.send(player, event.getMessage()));
    }
    ((IMixinEntityPlayerMP) this.player).getWorldBorderListener().onPlayerDisconnect();
}
Also used : Player(org.spongepowered.api.entity.living.player.Player) IMixinEntityPlayer(org.spongepowered.common.interfaces.entity.player.IMixinEntityPlayer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) CPacketPlayer(net.minecraft.network.play.client.CPacketPlayer) IMixinInventoryPlayer(org.spongepowered.common.interfaces.entity.player.IMixinInventoryPlayer) MessageChannel(org.spongepowered.api.text.channel.MessageChannel) MessageEvent(org.spongepowered.api.event.message.MessageEvent) ClientConnectionEvent(org.spongepowered.api.event.network.ClientConnectionEvent) Text(org.spongepowered.api.text.Text) Redirect(org.spongepowered.asm.mixin.injection.Redirect)

Aggregations

MessageChannel (org.spongepowered.api.text.channel.MessageChannel)24 Player (org.spongepowered.api.entity.living.player.Player)17 Text (org.spongepowered.api.text.Text)17 MessageEvent (org.spongepowered.api.event.message.MessageEvent)11 UUID (java.util.UUID)6 ClientConnectionEvent (org.spongepowered.api.event.network.ClientConnectionEvent)5 Instant (java.time.Instant)4 MessageChannelEvent (org.spongepowered.api.event.message.MessageChannelEvent)4 NucleusTextTemplateImpl (io.github.nucleuspowered.nucleus.internal.text.NucleusTextTemplateImpl)3 Optional (java.util.Optional)3 Sponge (org.spongepowered.api.Sponge)3 User (org.spongepowered.api.entity.living.player.User)3 Listener (org.spongepowered.api.event.Listener)3 Cause (org.spongepowered.api.event.cause.Cause)3 ChatTypes (org.spongepowered.api.text.chat.ChatTypes)3 Preconditions (com.google.common.base.Preconditions)2 HashMultimap (com.google.common.collect.HashMultimap)2 Lists (com.google.common.collect.Lists)2 Maps (com.google.common.collect.Maps)2 Multimap (com.google.common.collect.Multimap)2