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.util;
020
021import com.plotsquared.core.plot.PlotArea;
022import com.plotsquared.core.plot.flag.PlotFlag;
023
024import java.util.Objects;
025
026/**
027 * Util class for generic methods relating to plot flags.
028 *
029 * @since 6.10.4
030 */
031public final class PlotFlagUtil {
032
033    private PlotFlagUtil() {
034        //No-op
035    }
036
037    /**
038     * Check if the value of a {@link PlotFlag} matches the given value. If
039     * road flags are disabled for the given plot area, returns false.
040     *
041     * @param flagClass boolean flag to get value of
042     * @param value     boolean value to check flag value against
043     * @param <T>       The flag value type
044     * @return true if road flag value matches with road flags enabled
045     * @since 6.10.4
046     */
047    public static <T> boolean isAreaRoadFlagsAndFlagEquals(
048            PlotArea area, final Class<? extends PlotFlag<T, ?>> flagClass, T value
049    ) {
050        return area.isRoadFlags() && Objects.equals(area.getRoadFlag(flagClass), value);
051    }
052
053}