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.flag.PlotFlag;
023import org.checkerframework.checker.nullness.qual.NonNull;
024
025import java.util.Arrays;
026import java.util.Collection;
027
028public class FlyFlag extends PlotFlag<FlyFlag.FlyStatus, FlyFlag> {
029
030    public static final FlyFlag FLIGHT_FLAG_DISABLED = new FlyFlag(FlyStatus.DISABLED);
031    public static final FlyFlag FLIGHT_FLAG_ENABLED = new FlyFlag(FlyStatus.ENABLED);
032    public static final FlyFlag FLIGHT_FLAG_DEFAULT = new FlyFlag(FlyStatus.DEFAULT);
033
034    protected FlyFlag(final FlyStatus value) {
035        super(
036                value,
037                TranslatableCaption.of("flags.flag_category_boolean"),
038                TranslatableCaption.of("flags.flag_description_flight")
039        );
040    }
041
042    @Override
043    public FlyFlag parse(final @NonNull String input) {
044        return switch (input.toLowerCase()) {
045            case "true", "enabled", "allow" -> FLIGHT_FLAG_ENABLED;
046            case "false", "disabled", "disallow" -> FLIGHT_FLAG_DISABLED;
047            default -> FLIGHT_FLAG_DEFAULT;
048        };
049    }
050
051    @Override
052    public FlyFlag merge(final @NonNull FlyStatus newValue) {
053        if (newValue == FlyStatus.ENABLED || this.getValue() == FlyStatus.ENABLED) {
054            return FLIGHT_FLAG_ENABLED;
055        }
056        return flagOf(newValue);
057    }
058
059    @Override
060    public String toString() {
061        return this.getValue().name().toLowerCase();
062    }
063
064    @Override
065    public String getExample() {
066        return "true";
067    }
068
069    @Override
070    protected FlyFlag flagOf(final @NonNull FlyStatus value) {
071        switch (value) {
072            case ENABLED:
073                return FLIGHT_FLAG_ENABLED;
074            case DISABLED:
075                return FLIGHT_FLAG_DISABLED;
076            default:
077                return FLIGHT_FLAG_DEFAULT;
078        }
079    }
080
081    @Override
082    public Collection<String> getTabCompletions() {
083        return Arrays.asList("true", "false", "default");
084    }
085
086    public enum FlyStatus {
087        ENABLED,
088        DISABLED,
089        DEFAULT
090    }
091
092}