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.setup; 020 021import com.plotsquared.core.command.Command; 022import com.plotsquared.core.command.RequiredType; 023import com.plotsquared.core.player.PlotPlayer; 024import org.checkerframework.checker.nullness.qual.NonNull; 025import org.checkerframework.checker.nullness.qual.Nullable; 026 027import java.util.ArrayList; 028import java.util.Collection; 029import java.util.List; 030 031public interface SetupStep { 032 033 /** 034 * Handles the input for this setup step. 035 * 036 * @param plotPlayer the plot player executing the command 037 * @param builder the plot area builder to work on 038 * @param argument the argument given as input 039 * @return the next step if input was valid, this setup step otherwise 040 */ 041 SetupStep handleInput(final PlotPlayer<?> plotPlayer, PlotAreaBuilder builder, String argument); 042 043 @NonNull Collection<String> getSuggestions(); 044 045 @Nullable String getDefaultValue(); 046 047 /** 048 * Announces this step to the player. 049 * 050 * @param plotPlayer the player to announce this step to. 051 */ 052 void announce(PlotPlayer<?> plotPlayer); 053 054 /** 055 * Creates a collection of suggestions for the current input. 056 * 057 * @param plotPlayer the player to receive the suggestions. 058 * @param argument the argument already typed. 059 * @return a collection of suggestions. 060 */ 061 default Collection<Command> createSuggestions(final PlotPlayer<?> plotPlayer, String argument) { 062 List<Command> result = new ArrayList<>(getSuggestions().size()); 063 for (String suggestion : getSuggestions()) { 064 if (suggestion.startsWith(argument)) { 065 result.add(new Command(null, false, suggestion, "", RequiredType.NONE, null) { 066 }); 067 } 068 } 069 return result; 070 } 071 072 /** 073 * This method is called when the SetupProcess reverts to a previous step. 074 * 075 * @param builder the builder associated with the setup process. 076 */ 077 default void onBack(PlotAreaBuilder builder) { 078 079 } 080 081}