001/*
002 * PlotSquared, a land and world management plugin for Minecraft.
003 * Copyright (C) IntellectualSites <https://intellectualsites.com>
004 * Copyright (C) IntellectualSites team and contributors
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU General Public License for more details.
015 *
016 * You should have received a copy of the GNU General Public License
017 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
018 */
019package com.plotsquared.core.plot.flag.implementations;
020
021import com.plotsquared.core.configuration.caption.TranslatableCaption;
022import com.plotsquared.core.plot.PlotWeather;
023import com.plotsquared.core.plot.flag.PlotFlag;
024import org.checkerframework.checker.nullness.qual.NonNull;
025
026import java.util.Arrays;
027import java.util.Collection;
028
029public class WeatherFlag extends PlotFlag<PlotWeather, WeatherFlag> {
030
031    public static final WeatherFlag PLOT_WEATHER_FLAG_RAIN = new WeatherFlag(PlotWeather.RAIN);
032    public static final WeatherFlag PLOT_WEATHER_FLAG_CLEAR = new WeatherFlag(PlotWeather.CLEAR);
033    public static final WeatherFlag PLOT_WEATHER_FLAG_WORLD = new WeatherFlag(PlotWeather.WORLD);
034    public static final WeatherFlag PLOT_WEATHER_FLAG_OFF = new WeatherFlag(PlotWeather.OFF);
035
036    /**
037     * Construct a new flag instance.
038     *
039     * @param value Flag value
040     */
041    protected WeatherFlag(@NonNull PlotWeather value) {
042        super(
043                value,
044                TranslatableCaption.of("flags.flag_category_weather"),
045                TranslatableCaption.of("flags.flag_description_weather")
046        );
047    }
048
049    @Override
050    public WeatherFlag parse(@NonNull String input) {
051        return switch (input.toLowerCase()) {
052            case "rain" -> flagOf(PlotWeather.RAIN);
053            case "clear" -> flagOf(PlotWeather.CLEAR);
054            case "reset" -> flagOf(PlotWeather.WORLD);
055            default -> flagOf(PlotWeather.OFF);
056        };
057    }
058
059    @Override
060    public WeatherFlag merge(@NonNull PlotWeather newValue) {
061        return flagOf(newValue);
062    }
063
064    @Override
065    public String toString() {
066        return getValue().toString();
067    }
068
069    @Override
070    public String getExample() {
071        return "rain";
072    }
073
074    @Override
075    protected WeatherFlag flagOf(@NonNull PlotWeather value) {
076        return switch (value) {
077            case RAIN -> PLOT_WEATHER_FLAG_RAIN;
078            case CLEAR -> PLOT_WEATHER_FLAG_CLEAR;
079            case WORLD -> PLOT_WEATHER_FLAG_WORLD;
080            default -> PLOT_WEATHER_FLAG_OFF;
081        };
082    }
083
084    @Override
085    public Collection<String> getTabCompletions() {
086        return Arrays
087                .asList("clear", "rain");
088    }
089
090}