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.types; 020 021import com.plotsquared.core.configuration.caption.Caption; 022import com.plotsquared.core.configuration.caption.TranslatableCaption; 023import com.plotsquared.core.plot.flag.FlagParseException; 024import org.checkerframework.checker.nullness.qual.NonNull; 025 026public abstract class IntegerFlag<F extends NumberFlag<Integer, F>> extends NumberFlag<Integer, F> { 027 028 protected IntegerFlag( 029 final int value, int minimum, int maximum, 030 @NonNull Caption flagDescription 031 ) { 032 super(value, minimum, maximum, TranslatableCaption.of("flags.flag_category_integers"), flagDescription); 033 } 034 035 protected IntegerFlag(@NonNull Caption flagDescription) { 036 this(0, Integer.MIN_VALUE, Integer.MAX_VALUE, flagDescription); 037 } 038 039 @Override 040 public F merge(@NonNull Integer newValue) { 041 return flagOf(getValue() + newValue); 042 } 043 044 @Override 045 public String toString() { 046 return this.getValue().toString(); 047 } 048 049 @Override 050 public String getExample() { 051 return "10"; 052 } 053 054 @NonNull 055 @Override 056 protected Integer parseNumber(String input) throws FlagParseException { 057 try { 058 return Integer.parseInt(input); 059 } catch (Throwable throwable) { 060 throw new FlagParseException(this, input, TranslatableCaption.of("flags.flag_error_integer")); 061 } 062 } 063 064}