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.command;
020
021import com.plotsquared.core.configuration.caption.Caption;
022import com.plotsquared.core.configuration.caption.LocaleHolder;
023import com.plotsquared.core.configuration.caption.TranslatableCaption;
024import com.plotsquared.core.player.PlotPlayer;
025import org.checkerframework.checker.nullness.qual.NonNull;
026
027/**
028 * CommandCategory.
029 */
030public enum CommandCategory implements Caption {
031    /**
032     * Claiming CommandConfig.
033     * Such as: /plot claim
034     */
035    CLAIMING(TranslatableCaption.of("category.command_category_claiming")),
036    /**
037     * Teleportation CommandConfig.
038     * Such as: /plot visit
039     */
040    TELEPORT(TranslatableCaption.of("category.command_category_teleport")),
041    /**
042     * Protection.
043     */
044    SETTINGS(TranslatableCaption.of("category.command_category_settings")),
045    /**
046     * Chat.
047     */
048    CHAT(TranslatableCaption.of("category.command_category_chat")),
049    /**
050     * Web.
051     */
052    SCHEMATIC(TranslatableCaption.of("category.command_category_schematic")),
053    /**
054     * Cosmetic.
055     */
056    APPEARANCE(TranslatableCaption.of("category.command_category_appearance")),
057    /**
058     * Information CommandConfig.
059     * Such as: /plot info
060     */
061    INFO(TranslatableCaption.of("category.command_category_info")),
062    /**
063     * Debug CommandConfig.
064     * Such as: /plot debug
065     */
066    DEBUG(TranslatableCaption.of("category.command_category_debug")),
067    /**
068     * Administration commands.
069     */
070    ADMINISTRATION(TranslatableCaption.of("category.command_category_administration"));
071    /**
072     * The category name (Readable).
073     */
074    private final Caption caption;
075
076    CommandCategory(final Caption caption) {
077        this.caption = caption;
078    }
079
080    // TODO this method shouldn't be invoked
081    @Deprecated
082    @Override
083    public String toString() {
084        return this.caption.getComponent(LocaleHolder.console());
085    }
086
087    @NonNull
088    @Override
089    public String getComponent(@NonNull LocaleHolder localeHolder) {
090        return this.caption.getComponent(localeHolder);
091    }
092
093    /**
094     * Checks if a player has access to this command category
095     *
096     * @param player The player to check against
097     * @return {@code true} if at least one command of this category can be executed by the player, {@code false} otherwise
098     * @since 6.5.0
099     */
100    boolean canAccess(PlotPlayer<?> player) {
101        return !MainCommand.getInstance().getCommands(this, player).isEmpty();
102    }
103
104}