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

package com.hypixel.hytale.builtin.landiscovery;

import com.hypixel.hytale.server.core.util.message.MessageFormat;
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.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;

public class LANDiscoveryCommand extends CommandBase
{
    @Nonnull
    private static final Message MESSAGE_IO_LAN_DISCOVERY_DISABLED;
    @Nonnull
    private static final Message MESSAGE_IO_LAN_DISCOVERY_ENABLED;
    @Nonnull
    private final OptionalArg<Boolean> enabledArg;
    
    public LANDiscoveryCommand() {
        super("landiscovery", "server.commands.landiscovery.desc");
        this.enabledArg = this.withOptionalArg("enabled", "server.commands.landiscovery.enabled.desc", ArgTypes.BOOLEAN);
    }
    
    @Override
    protected void executeSync(@Nonnull final CommandContext context) {
        if (this.enabledArg.provided(context)) {
            final boolean enabled = this.enabledArg.get(context);
            final LANDiscoveryPlugin plugin = LANDiscoveryPlugin.get();
            if (!enabled && plugin.getLanDiscoveryThread() != null) {
                plugin.setLANDiscoveryEnabled(false);
                context.sendMessage(LANDiscoveryCommand.MESSAGE_IO_LAN_DISCOVERY_DISABLED);
            }
            else if (enabled && plugin.getLanDiscoveryThread() == null) {
                plugin.setLANDiscoveryEnabled(true);
                context.sendMessage(LANDiscoveryCommand.MESSAGE_IO_LAN_DISCOVERY_ENABLED);
            }
            else {
                context.sendMessage(Message.translation("server.io.landiscovery.alreadyToggled").param("status", MessageFormat.enabled(enabled)));
            }
            return;
        }
        final LANDiscoveryPlugin plugin2 = LANDiscoveryPlugin.get();
        if (plugin2.getLanDiscoveryThread() == null) {
            plugin2.setLANDiscoveryEnabled(true);
            context.sendMessage(LANDiscoveryCommand.MESSAGE_IO_LAN_DISCOVERY_ENABLED);
        }
        else {
            plugin2.setLANDiscoveryEnabled(false);
            context.sendMessage(LANDiscoveryCommand.MESSAGE_IO_LAN_DISCOVERY_DISABLED);
        }
    }
    
    static {
        MESSAGE_IO_LAN_DISCOVERY_DISABLED = Message.translation("server.io.landiscovery.disabled");
        MESSAGE_IO_LAN_DISCOVERY_ENABLED = Message.translation("server.io.landiscovery.enabled");
    }
}
