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 DoubleFlag<F extends NumberFlag<Double, F>> extends NumberFlag<Double, F> { 027 028 protected DoubleFlag( 029 @NonNull Double value, Double minimum, Double maximum, 030 @NonNull Caption flagDescription 031 ) { 032 super(value, minimum, maximum, TranslatableCaption.of("flags.flag_category_doubles"), flagDescription); 033 } 034 035 protected DoubleFlag(@NonNull Double value, @NonNull Caption flagDescription) { 036 this(value, Double.MIN_VALUE, Double.MAX_VALUE, flagDescription); 037 } 038 039 @Override 040 public F merge(@NonNull Double newValue) { 041 return flagOf(getValue() + newValue); 042 } 043 044 @Override 045 public String getExample() { 046 return "12.175"; 047 } 048 049 @Override 050 public String toString() { 051 return getValue().toString(); 052 } 053 054 @NonNull 055 @Override 056 protected Double parseNumber(String input) throws FlagParseException { 057 try { 058 return Double.parseDouble(input); 059 } catch (Throwable throwable) { 060 throw new FlagParseException(this, input, TranslatableCaption.of("flags.flag_error_double")); 061 } 062 } 063 064 @Override 065 public boolean isValuedPermission() { 066 return false; 067 } 068 069}