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