/*
This file is a part of the SteamWar software.
Copyright (C) 2020 SteamWar.de-Serverteam
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see .
*/
package de.steamwar.bausystem.commands;
import de.steamwar.bausystem.tracer.record.RecordStateMachine;
import de.steamwar.bausystem.tracer.record.RecordStatus;
import de.steamwar.bausystem.tracer.show.mode.Basic;
import de.steamwar.bausystem.tracer.show.mode.BasicNoWater;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class CommandTraceTabCompleter implements TabCompleter {
@Override
public List onTabComplete(CommandSender sender, Command command, String label, String[] args) {
if(!(sender instanceof Player)) return new ArrayList<>();
return tracerTabComplete((Player) sender, args);
}
private List tracerTabComplete(Player player, String[] args) {
List tabComplete = new ArrayList<>();
if (RecordStateMachine.getRecordStatus() == RecordStatus.IDLE || RecordStateMachine.getRecordStatus() == RecordStatus.IDLE_AUTO) {
tabComplete.add("start");
} else {
tabComplete.add("stop");
}
tabComplete.add("toggleauto");
tabComplete.add("auto");
tabComplete.add("show");
if (args[0].equalsIgnoreCase("show") && args.length == 2) {
return manageList(new ArrayList<>(Arrays.asList("water", "nowater", "no_water", "removedwater", "removed_water", "basic", "default")), args, 1);
}
tabComplete.add("hide");
tabComplete.add("delete");
tabComplete.add("clear");
//tabComplete.add("gui");
//tabComplete.add("list");
if (args.length >= 2) {
return new ArrayList<>();
}
return manageList(tabComplete, args, 0);
}
private List manageList(List strings, String[] args, int index) {
for (int i = strings.size() - 1; i >= 0; i--) {
if (!strings.get(i).startsWith(args[index])) {
strings.remove(i);
}
}
return strings;
}
}