package net.minecraft.server.commands;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.brigadier.context.CommandContext;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import net.minecraft.commands.Commands;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import net.minecraft.commands.CommandSourceStack;
import com.mojang.brigadier.CommandDispatcher;

public class WeatherCommand {
    public static void register(final CommandDispatcher<CommandSourceStack> commandDispatcher) {
        commandDispatcher.register((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)((LiteralArgumentBuilder)Commands.literal("weather").requires(cq -> cq.hasPermission(2))).then(((LiteralArgumentBuilder)Commands.literal("clear").executes(commandContext -> setClear((CommandSourceStack)commandContext.getSource(), 6000))).then(Commands.argument("duration", (com.mojang.brigadier.arguments.ArgumentType<Object>)IntegerArgumentType.integer(0, 1000000)).executes(commandContext -> setClear((CommandSourceStack)commandContext.getSource(), IntegerArgumentType.getInteger(commandContext, "duration") * 20))))).then(((LiteralArgumentBuilder)Commands.literal("rain").executes(commandContext -> setRain((CommandSourceStack)commandContext.getSource(), 6000))).then(Commands.argument("duration", (com.mojang.brigadier.arguments.ArgumentType<Object>)IntegerArgumentType.integer(0, 1000000)).executes(commandContext -> setRain((CommandSourceStack)commandContext.getSource(), IntegerArgumentType.getInteger(commandContext, "duration") * 20))))).then(((LiteralArgumentBuilder)Commands.literal("thunder").executes(commandContext -> setThunder((CommandSourceStack)commandContext.getSource(), 6000))).then(Commands.argument("duration", (com.mojang.brigadier.arguments.ArgumentType<Object>)IntegerArgumentType.integer(0, 1000000)).executes(commandContext -> setThunder((CommandSourceStack)commandContext.getSource(), IntegerArgumentType.getInteger(commandContext, "duration") * 20)))));
    }
    
    private static int setClear(final CommandSourceStack cq, final int integer) {
        cq.getLevel().getLevelData().setClearWeatherTime(integer);
        cq.getLevel().getLevelData().setRainTime(0);
        cq.getLevel().getLevelData().setThunderTime(0);
        cq.getLevel().getLevelData().setRaining(false);
        cq.getLevel().getLevelData().setThundering(false);
        cq.sendSuccess(new TranslatableComponent("commands.weather.set.clear", new Object[0]), true);
        return integer;
    }
    
    private static int setRain(final CommandSourceStack cq, final int integer) {
        cq.getLevel().getLevelData().setClearWeatherTime(0);
        cq.getLevel().getLevelData().setRainTime(integer);
        cq.getLevel().getLevelData().setThunderTime(integer);
        cq.getLevel().getLevelData().setRaining(true);
        cq.getLevel().getLevelData().setThundering(false);
        cq.sendSuccess(new TranslatableComponent("commands.weather.set.rain", new Object[0]), true);
        return integer;
    }
    
    private static int setThunder(final CommandSourceStack cq, final int integer) {
        cq.getLevel().getLevelData().setClearWeatherTime(0);
        cq.getLevel().getLevelData().setRainTime(integer);
        cq.getLevel().getLevelData().setThunderTime(integer);
        cq.getLevel().getLevelData().setRaining(true);
        cq.getLevel().getLevelData().setThundering(true);
        cq.sendSuccess(new TranslatableComponent("commands.weather.set.thunder", new Object[0]), true);
        return integer;
    }
}
