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