/*
 * This file is part of Nucleus, licensed under the MIT License (MIT). See the LICENSE.txt file
 * at the root of this project for more details.
 */
package io.github.nucleuspowered.nucleus.modules.freezeplayer.commands;

import com.google.inject.Inject;
import io.github.nucleuspowered.nucleus.argumentparsers.NicknameArgument;
import io.github.nucleuspowered.nucleus.argumentparsers.SelectorWrapperArgument;
import io.github.nucleuspowered.nucleus.dataservices.loaders.UserDataManager;
import io.github.nucleuspowered.nucleus.internal.annotations.Permissions;
import io.github.nucleuspowered.nucleus.internal.annotations.RegisterCommand;
import io.github.nucleuspowered.nucleus.internal.command.AbstractCommand;
import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation;
import io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel;
import io.github.nucleuspowered.nucleus.modules.freezeplayer.datamodules.FreezePlayerUserDataModule;
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.CommandElement;
import org.spongepowered.api.command.args.GenericArguments;
import org.spongepowered.api.entity.living.player.User;
import org.spongepowered.api.text.Text;

import java.util.HashMap;
import java.util.Map;

@Permissions
@RegisterCommand({"freezeplayer", "freeze"})
public class FreezePlayerCommand extends AbstractCommand<CommandSource> {

    @Inject private UserDataManager userConfigLoader;

    private final String player = "subject";
    private final String truefalsekey = "true|false";

    @Override
    public Map<String, PermissionInformation> permissionSuffixesToRegister() {
        Map<String, PermissionInformation> m = new HashMap<>();
        m.put("others", new PermissionInformation(plugin.getMessageProvider().getMessageWithFormat("permission.others", this.getAliases()[0]), SuggestedLevel.ADMIN));
        return m;
    }

    @Override
    public CommandElement[] getArguments() {
        return new CommandElement[] {
                GenericArguments.optionalWeak(GenericArguments.requiringPermission(
                        GenericArguments.onlyOne(SelectorWrapperArgument.nicknameSelector(
                                Text.of(player),
                                NicknameArgument.UnderlyingType.USER
                        )), permissions.getPermissionWithSuffix("others"))),
                GenericArguments.optional(GenericArguments.bool(Text.of(truefalsekey)))
        };
    }

    @Override
    public CommandResult executeCommand(CommandSource src, CommandContext args) throws Exception {
        User pl = this.getUserFromArgs(User.class, src, player, args);
        FreezePlayerUserDataModule nu = userConfigLoader.getUnchecked(pl).get(FreezePlayerUserDataModule.class);
        nu.setFrozen(args.<Boolean>getOne(truefalsekey).orElseGet(() -> !nu.isFrozen()));
        src.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat(
            nu.isFrozen() ? "command.freezeplayer.success.frozen" : "command.freezeplayer.success.unfrozen", plugin.getNameUtil().getSerialisedName(pl)));
        return CommandResult.success();
    }
}

@@ -714,169 +714,8 @@
 nd;%0A
-import io.github.nucleuspowered.nucleus.internal.permissions.PermissionInformation;%0Aimport io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel;%0A
 impo
@@ -811,16 +811,16 @@
 Module;%0A
+
 import o
@@ -1192,69 +1192,43 @@
 t;%0A%0A
-import java.util.HashMap;%0Aimport java.util.Map;%0A%0A@Permissions
+@Permissions(supportsOthers = true)
 %0A@Re
@@ -1444,16 +1444,16 @@
 bject%22;%0A
+
     priv
@@ -1503,357 +1503,8 @@
 %22;%0A%0A
-    @Override%0A    public Map%3CString, PermissionInformation%3E permissionSuffixesToRegister() %7B%0A        Map%3CString, PermissionInformation%3E m = new HashMap%3C%3E();%0A        m.put(%22others%22, new PermissionInformation(plugin.getMessageProvider().getMessageWithFormat(%22permission.others%22, this.getAliases()%5B0%5D), SuggestedLevel.ADMIN));%0A        return m;%0A    %7D%0A%0A
     

Remove redundant code.