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.plot; 020 021import com.plotsquared.core.configuration.caption.Caption; 022import com.plotsquared.core.configuration.caption.TranslatableCaption; 023import org.checkerframework.checker.nullness.qual.NonNull; 024 025import java.util.Map; 026import java.util.Optional; 027import java.util.function.Function; 028import java.util.stream.Collectors; 029import java.util.stream.Stream; 030 031public enum PlotAreaType { 032 NORMAL(TranslatableCaption.of("plotareatype.plot_area_type_normal")), 033 AUGMENTED(TranslatableCaption.of("plotareatype.plot_area_type_augmented")), 034 PARTIAL(TranslatableCaption.of("plotareatype.plot_area_type_partial")); 035 036 private static final Map<String, PlotAreaType> types = Stream.of(values()) 037 .collect(Collectors.toMap(e -> e.toString().toLowerCase(), Function.identity())); 038 private final Caption description; 039 040 PlotAreaType(final @NonNull Caption description) { 041 this.description = description; 042 } 043 044 public static Map<PlotAreaType, Caption> getDescriptionMap() { 045 return Stream.of(values()).collect(Collectors.toMap(e -> e, PlotAreaType::getDescription)); 046 } 047 048 public static Optional<PlotAreaType> fromString(String typeName) { 049 return Optional.ofNullable(types.get(typeName.toLowerCase())); 050 } 051 052 @Deprecated 053 public static Optional<PlotAreaType> fromLegacyInt(int typeId) { 054 if (typeId < 0 || typeId >= values().length) { 055 return Optional.empty(); 056 } 057 return Optional.of(values()[typeId]); 058 } 059 060 public Caption getDescription() { 061 return this.description; 062 } 063}