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