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.flag; 020 021import com.plotsquared.core.configuration.caption.Caption; 022import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver; 023 024public class FlagParseException extends Exception { 025 026 private final PlotFlag<?, ?> flag; 027 private final String value; 028 private final Caption errorMessage; 029 private final TagResolver[] tagResolvers; 030 031 /** 032 * Construct a new flag parse exception to indicate that an attempt to parse a plot 033 * flag was unsuccessful. 034 * 035 * @param flag Flag instance 036 * @param value Value that failed ot parse 037 * @param errorMessage An error message explaining the failure 038 * @param args Arguments used to format the error message 039 */ 040 public FlagParseException( 041 final PlotFlag<?, ?> flag, final String value, 042 final Caption errorMessage, final TagResolver... args 043 ) { 044 super(String.format("Failed to parse flag of type '%s'. Value '%s' was not accepted.", 045 flag.getName(), value 046 )); 047 this.flag = flag; 048 this.value = value; 049 this.errorMessage = errorMessage; 050 this.tagResolvers = args; 051 } 052 053 /** 054 * Returns the value that caused the parse exception 055 * 056 * @return Value that failed to parse 057 */ 058 public String getValue() { 059 return this.value; 060 } 061 062 /** 063 * Returns the class that threw the exception 064 * 065 * @return Flag that threw the exception 066 */ 067 public PlotFlag<?, ?> getFlag() { 068 return this.flag; 069 } 070 071 /** 072 * Get the error message that was supplied by the flag instance. 073 * 074 * @return Error message. 075 */ 076 public Caption getErrorMessage() { 077 return errorMessage; 078 } 079 080 /** 081 * Get the templates that were supplied by the flag instance. 082 * 083 * @return Message templates. 084 */ 085 public TagResolver[] getTagResolvers() { 086 return tagResolvers; 087 } 088 089}