/*
 * This file is part of UltimateCore, licensed under the MIT License (MIT).
 *
 * Copyright (c) Bammerbom
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package bammerbom.ultimatecore.sponge.modules.spy.listeners;

import bammerbom.ultimatecore.sponge.api.module.Modules;
import bammerbom.ultimatecore.sponge.modules.personalmessage.api.PersonalmessageEvent;
import bammerbom.ultimatecore.sponge.modules.spy.api.SpyPermissions;
import bammerbom.ultimatecore.sponge.utils.Messages;
import bammerbom.ultimatecore.sponge.utils.VariableUtil;
import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.message.MessageChannelEvent;

public class SpyListener {
    @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_MESSAGESPY_SEE.get())) {
                    continue;
                }
                if (s.getIdentifier().equals(p.getIdentifier()) || t.getIdentifier().equals(p.getIdentifier())) {
                    continue;
                }
                p.sendMessage(Messages.getFormatted("spy.format.messagespy", "%player%", VariableUtil.getName(s), "%target%", VariableUtil.getName(t), "%message%", ev
                        .getPMUnformattedMessage()));
            }
        }
    }
}

@@ -1797,34 +1797,144 @@
 ent.
-message.MessageChannelEven
+command.SendCommandEvent;%0Aimport org.spongepowered.api.event.message.MessageChannelEvent;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Lis
 t;%0A%0A
@@ -2926,11 +2926,828 @@
  %7D%0A    %7D
+%0A%0A    @Listener%0A    public void onCommand(SendCommandEvent e) %7B%0A        Player t = e.getCause().first(Player.class).orElse(null);%0A        if (t == null) return;%0A        for (Player p : Sponge.getServer().getOnlinePlayers()) %7B%0A            if (!p.hasPermission(SpyPermissions.UC_COMMANDSPY_SEE.get())) %7B%0A                continue;%0A            %7D%0A            if (p == t) %7B%0A                continue;%0A            %7D%0A            //Ignored commands%0A            List%3CString%3E ignored = Arrays.asList(%22personalmessage%22, %22pm%22, %22dm%22, %22msg%22, %22w%22, %22whisper%22, %22tell%22, %22reply%22, %22respond%22, %22r%22);%0A            if (ignored.contains(e.getCommand())) continue;%0A            p.sendMessage(Messages.getFormatted(%22spy.format.commandspy%22, %22%25player%25%22, VariableUtil.getName(t), %22%25message%25%22, e.getCommand() + %22 %22 + e.getArguments()));%0A        %7D%0A    %7D
 %0A%7D%0A

Implement /commandspy