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

package com.hypixel.hytale.server.core.modules.singleplayer.commands;

import com.hypixel.hytale.server.core.util.message.MessageFormat;
import com.hypixel.hytale.server.core.Message;
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.protocol.packets.serveraccess.Access;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.modules.singleplayer.SingleplayerModule;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public abstract class PlayCommandBase extends CommandBase
{
    @Nonnull
    private final SingleplayerModule singleplayerModule;
    @Nonnull
    private final Access commandAccess;
    @Nonnull
    private final OptionalArg<Boolean> enabledArg;
    
    protected PlayCommandBase(@Nonnull final String name, @Nonnull final String description, @Nonnull final SingleplayerModule singleplayerModule, @Nonnull final Access commandAccess) {
        super(name, description);
        this.enabledArg = this.withOptionalArg("enabled", "server.commands.play.enabled.desc", ArgTypes.BOOLEAN);
        this.singleplayerModule = singleplayerModule;
        this.commandAccess = commandAccess;
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        if (!Constants.SINGLEPLAYER) {
            context.sendMessage(Message.translation("server.commands.play.singleplayerOnly").param("commandAccess", this.commandAccess.toString()));
            return;
        }
        final Access access = SingleplayerModule.get().getAccess();
        if (this.enabledArg.provided(context)) {
            final boolean enabled = this.enabledArg.get(context);
            if (!enabled && access == this.commandAccess) {
                this.singleplayerModule.requestServerAccess(Access.Private);
                context.sendMessage(Message.translation("server.commands.play.accessDisabled").param("commandAccess", this.commandAccess.toString()));
            }
            else if (enabled && access != this.commandAccess) {
                this.singleplayerModule.requestServerAccess(this.commandAccess);
                context.sendMessage(Message.translation("server.commands.play.accessEnabled").param("commandAccess", this.commandAccess.toString()));
            }
            else {
                context.sendMessage(Message.translation("server.commands.play.accessAlreadyToggled").param("commandAccess", this.commandAccess.toString()).param("enabled", MessageFormat.enabled(enabled)));
            }
            return;
        }
        if (access == this.commandAccess) {
            this.singleplayerModule.requestServerAccess(Access.Private);
            context.sendMessage(Message.translation("server.commands.play.accessDisabled").param("commandAccess", this.commandAccess.toString()));
        }
        else {
            this.singleplayerModule.requestServerAccess(this.commandAccess);
            context.sendMessage(Message.translation("server.commands.play.accessEnabled").param("commandAccess", this.commandAccess.toString()));
        }
    }
}
