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.events;
020
021import java.util.HashMap;
022import java.util.Map;
023
024/**
025 * Enum for {@link CancellablePlotEvent}.
026 * <p>
027 * DENY: do not allow the event to happen
028 * ALLOW: allow the event to continue as normal, subject to standard checks
029 * FORCE: force the event to occur, even if normal checks would deny.
030 * WARNING: this may have unintended consequences! Make sure you study the appropriate code before using!
031 */
032public enum Result {
033
034    DENY(0),
035    ACCEPT(1),
036    FORCE(2);
037
038    private static final Map<Integer, Result> map = new HashMap<>();
039
040    static {
041        for (Result eventResult : Result.values()) {
042            map.put(eventResult.value, eventResult);
043        }
044    }
045
046    private final int value;
047
048    Result(int value) {
049        this.value = value;
050    }
051
052    /**
053     * Obtain the Result enum associated with the int value
054     *
055     * @param eventResult the int value
056     * @return the corresponding Result
057     */
058    public static Result valueOf(int eventResult) {
059        return map.get(eventResult);
060    }
061
062    /**
063     * Get int value of enum
064     *
065     * @return integer value
066     */
067    public int getValue() {
068        return value;
069    }
070}