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

package com.hypixel.hytale.server.core.command.commands.utility.sleep;

import com.hypixel.hytale.server.core.command.system.arguments.system.Argument;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.util.thread.TickingThread;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.FlagArg;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public class SleepOffsetCommand extends CommandBase
{
    @Nonnull
    private final FlagArg percentFlag;
    @Nonnull
    private final OptionalArg<Integer> offsetArg;
    
    public SleepOffsetCommand() {
        super("offset", "server.commands.sleepoffset.desc");
        this.percentFlag = this.withFlagArg("percent", "server.commands.sleepoffset.percent.desc");
        this.offsetArg = this.withOptionalArg("offset", "server.commands.sleepoffset.offset.desc", ArgTypes.INTEGER);
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        if (this.offsetArg.provided(context)) {
            final float oldValue = (float)TickingThread.SLEEP_OFFSET;
            final int newValue = this.offsetArg.get(context);
            TickingThread.SLEEP_OFFSET = newValue;
            if (((Argument<Arg, Boolean>)this.percentFlag).get(context)) {
                context.sendMessage(Message.translation("server.commands.sleepoffset.setPercent").param("newValue", newValue).param("oldValue", oldValue));
            }
            else {
                context.sendMessage(Message.translation("server.commands.sleepoffset.set").param("newValue", newValue).param("oldValue", oldValue));
            }
        }
        else {
            final float value = (float)TickingThread.SLEEP_OFFSET;
            if (((Argument<Arg, Boolean>)this.percentFlag).get(context)) {
                context.sendMessage(Message.translation("server.commands.sleepoffset.getPercent").param("value", value));
            }
            else {
                context.sendMessage(Message.translation("server.commands.sleepoffset.getOffset").param("value", value));
            }
        }
    }
}
