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.implementations; 020 021import com.plotsquared.core.configuration.caption.TranslatableCaption; 022import com.plotsquared.core.plot.flag.FlagParseException; 023import com.plotsquared.core.plot.flag.types.TimedFlag; 024import net.kyori.adventure.text.minimessage.Template; 025import org.checkerframework.checker.nullness.qual.NonNull; 026 027public class FeedFlag extends TimedFlag<Integer, FeedFlag> { 028 029 public static final FeedFlag FEED_NOTHING = new FeedFlag(new Timed<>(0, 0)); 030 031 public FeedFlag(@NonNull Timed<Integer> value) { 032 super(value, 1, TranslatableCaption.of("flags.flag_description_feed")); 033 } 034 035 @Override 036 protected Integer parseValue(String input) throws FlagParseException { 037 int parsed; 038 try { 039 parsed = Integer.parseInt(input); 040 } catch (Throwable throwable) { 041 throw new FlagParseException( 042 this, 043 input, 044 TranslatableCaption.of("invalid.not_a_number"), 045 Template.of("value", input) 046 ); 047 } 048 if (parsed < 1) { 049 throw new FlagParseException( 050 this, 051 input, 052 TranslatableCaption.of("invalid.number_not_positive"), 053 Template.of("value", String.valueOf(parsed)) 054 ); 055 } 056 return parsed; 057 } 058 059 @Override 060 protected Integer mergeValue(Integer other) { 061 return this.getValue().getValue() + other; 062 } 063 064 @Override 065 public String getExample() { 066 return "10 5"; 067 } 068 069 @Override 070 protected FeedFlag flagOf(@NonNull Timed<Integer> value) { 071 return new FeedFlag(value); 072 } 073 074}