// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.server.core.command.commands.debug;

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.server.core.util.ProcessUtil;
import com.hypixel.hytale.server.core.Options;
import com.hypixel.hytale.server.core.Constants;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public class PIDCheckCommand extends CommandBase
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_PID_CHECK_SINGLEPLAYER_ONLY;
    @Nonnull
    private final FlagArg singleplayerFlag;
    @Nonnull
    private final OptionalArg<Integer> pidArg;
    
    public PIDCheckCommand() {
        super("pidcheck", "server.commands.pidcheck.desc");
        this.singleplayerFlag = this.withFlagArg("singleplayer", "server.commands.pidcheck.singleplayer.desc");
        this.pidArg = this.withOptionalArg("pid", "server.commands.pidcheck.pid.desc", ArgTypes.INTEGER);
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        if (((Argument<Arg, Boolean>)this.singleplayerFlag).get(context)) {
            if (!Constants.SINGLEPLAYER) {
                context.sendMessage(PIDCheckCommand.MESSAGE_COMMANDS_PID_CHECK_SINGLEPLAYER_ONLY);
                return;
            }
            final int pid = Options.getOptionSet().valueOf(Options.CLIENT_PID);
            final Message runningMessage = Message.translation(ProcessUtil.isProcessRunning(pid) ? "server.commands.pidcheck.isRunning" : "server.commands.pidcheck.isNotRunning");
            context.sendMessage(Message.translation("server.commands.pidcheck.clientPIDRunning").param("pid", pid).param("running", runningMessage));
        }
        else {
            if (!this.pidArg.provided(context)) {
                context.sendMessage(Message.translation("server.commands.pidcheck.pidRequired"));
                return;
            }
            final int pid = this.pidArg.get(context);
            final Message runningMessage = Message.translation(ProcessUtil.isProcessRunning(pid) ? "server.commands.pidcheck.isRunning" : "server.commands.pidcheck.isNotRunning");
            context.sendMessage(Message.translation("server.commands.pidcheck.PIDRunning").param("pid", pid).param("running", runningMessage));
        }
    }
    
    static {
        MESSAGE_COMMANDS_PID_CHECK_SINGLEPLAYER_ONLY = Message.translation("server.commands.pidcheck.singlePlayerOnly");
    }
}
