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

package com.hypixel.hytale.builtin.weather.commands;

import com.hypixel.hytale.server.core.universe.world.WorldConfig;
import com.hypixel.hytale.builtin.weather.resources.WeatherResource;
import javax.annotation.Nullable;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class WeatherSetCommand extends AbstractWorldCommand
{
    @Nonnull
    private final RequiredArg<Weather> weatherArg;
    
    public WeatherSetCommand() {
        super("set", "server.commands.weather.set.desc");
        this.weatherArg = this.withRequiredArg("weather", "server.commands.weather.set.weather.desc", ArgTypes.WEATHER_ASSET);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final Weather weather = this.weatherArg.get(context);
        final String weatherName = weather.getId();
        setForcedWeather(world, weatherName, store);
        context.sendMessage(Message.translation("server.commands.weather.set.forcedWeatherSet").param("worldName", world.getName()).param("weather", weatherName));
    }
    
    protected static void setForcedWeather(@Nonnull final World world, @Nullable final String forcedWeather, final ComponentAccessor<EntityStore> componentAccessor) {
        final WeatherResource weatherResource = componentAccessor.getResource(WeatherResource.getResourceType());
        weatherResource.setForcedWeather(forcedWeather);
        final WorldConfig config = world.getWorldConfig();
        config.setForcedWeather(forcedWeather);
        config.markChanged();
    }
}
