package uk.co.drnaylor.minecraft.quickstart.commands.kick;

import org.spongepowered.api.Sponge;
import org.spongepowered.api.command.CommandResult;
import org.spongepowered.api.command.CommandSource;
import org.spongepowered.api.command.args.CommandContext;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.command.spec.CommandSpec;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.api.text.Text;
import org.spongepowered.api.text.channel.MessageChannel;
import org.spongepowered.api.text.format.TextColors;
import uk.co.drnaylor.minecraft.quickstart.QuickStart;
import uk.co.drnaylor.minecraft.quickstart.Util;
import uk.co.drnaylor.minecraft.quickstart.api.PluginModule;
import uk.co.drnaylor.minecraft.quickstart.internal.CommandBase;
import uk.co.drnaylor.minecraft.quickstart.internal.annotations.Modules;
import uk.co.drnaylor.minecraft.quickstart.internal.annotations.Permissions;

import java.text.MessageFormat;
import java.util.List;
import java.util.stream.Collectors;

@Permissions
@Modules(PluginModule.KICKS)
public class KickAllCommand extends CommandBase {
    private final String reason = "reason";

    @Override
    public CommandSpec createSpec() {
        return CommandSpec.builder().description(Text.of("Kicks all player.")).executor(this)
                .arguments(
                        GenericArguments.onlyOne(GenericArguments.remainingJoinedStrings(Text.of(reason)))
                ).build();
    }

    @Override
    public String[] getAliases() {
        return new String[] { "kick" };
    }

    @Override
    public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
        String r = args.<String>getOne(reason).orElse(Util.messageBundle.getString("command.kick.defaultreason"));

        Sponge.getServer().getOnlinePlayers().stream().filter(x -> !(src instanceof Player) || ((Player) src).getUniqueId().equals(x.getUniqueId())).forEach(x -> {
            x.kick(Text.of(TextColors.RED, r));
        });

        List<CommandSource> lcs = Sponge.getServer().getOnlinePlayers().stream().filter(x -> x.hasPermission(QuickStart.PERMISSIONS_PREFIX + "kick.notify"))
                .map(y -> (CommandSource)y).collect(Collectors.toList());
        lcs.add(Sponge.getServer().getConsole());

        MessageChannel mc = MessageChannel.fixed(Sponge.getServer().getConsole(), src);
        mc.send(Text.of(TextColors.GREEN, Util.messageBundle.getString("command.kickall.message")));
        mc.send(Text.of(TextColors.GREEN, MessageFormat.format(Util.messageBundle.getString("command.reason"), r)));
        return CommandResult.success();
    }
}

@@ -1312,16 +1312,17 @@
 l player
+s
 .%22)).exe
@@ -1586,16 +1586,19 @@
  %7B %22kick
+all
 %22 %7D;%0A   
@@ -1995,22 +1995,8 @@
 x -%3E
- %7B%0A           
  x.k
@@ -2030,19 +2030,8 @@
  r))
-;%0A        %7D
 );%0A%0A

Fix /kickall