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