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.PlotFlag; 023import org.checkerframework.checker.nullness.qual.NonNull; 024 025import java.util.Arrays; 026import java.util.Collection; 027 028public class LiquidFlowFlag extends PlotFlag<LiquidFlowFlag.FlowStatus, LiquidFlowFlag> { 029 030 public static final LiquidFlowFlag LIQUID_FLOW_ENABLED = new LiquidFlowFlag(FlowStatus.ENABLED); 031 public static final LiquidFlowFlag LIQUID_FLOW_DISABLED = 032 new LiquidFlowFlag(FlowStatus.DISABLED); 033 public static final LiquidFlowFlag LIQUID_FLOW_DEFAULT = new LiquidFlowFlag(FlowStatus.DEFAULT); 034 035 private LiquidFlowFlag(FlowStatus value) { 036 super( 037 value, 038 TranslatableCaption.of("flags.flag_category_boolean"), 039 TranslatableCaption.of("flags.flag_description_liquid_flow") 040 ); 041 } 042 043 @Override 044 public LiquidFlowFlag parse(final @NonNull String input) { 045 return switch (input.toLowerCase()) { 046 case "true", "enabled", "allow" -> LIQUID_FLOW_ENABLED; 047 case "false", "disabled", "disallow" -> LIQUID_FLOW_DISABLED; 048 default -> LIQUID_FLOW_DEFAULT; 049 }; 050 } 051 052 @Override 053 public LiquidFlowFlag merge(final @NonNull FlowStatus newValue) { 054 if (newValue == FlowStatus.ENABLED || this.getValue() == FlowStatus.ENABLED) { 055 return LIQUID_FLOW_ENABLED; 056 } 057 return flagOf(newValue); 058 } 059 060 @Override 061 public String toString() { 062 return this.getValue().name().toLowerCase(); 063 } 064 065 @Override 066 public String getExample() { 067 return "true"; 068 } 069 070 @Override 071 protected LiquidFlowFlag flagOf(final @NonNull FlowStatus value) { 072 return switch (value) { 073 case ENABLED -> LIQUID_FLOW_ENABLED; 074 case DISABLED -> LIQUID_FLOW_DISABLED; 075 default -> LIQUID_FLOW_DEFAULT; 076 }; 077 } 078 079 @Override 080 public Collection<String> getTabCompletions() { 081 return Arrays.asList("true", "false", "default"); 082 } 083 084 public enum FlowStatus { 085 ENABLED, 086 DISABLED, 087 DEFAULT 088 } 089 090}