001/* 002 * This file is part of Baritone. 003 * 004 * Baritone is free software: you can redistribute it and/or modify 005 * it under the terms of the GNU Lesser General Public License as published by 006 * the Free Software Foundation, either version 3 of the License, or 007 * (at your option) any later version. 008 * 009 * Baritone is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 012 * GNU Lesser General Public License for more details. 013 * 014 * You should have received a copy of the GNU Lesser General Public License 015 * along with Baritone. If not, see <https://www.gnu.org/licenses/>. 016 */ 017 018package baritone.api.command; 019 020import baritone.api.IBaritone; 021import baritone.api.utils.IPlayerContext; 022 023import java.util.Collections; 024import java.util.List; 025import java.util.Locale; 026import java.util.stream.Collectors; 027import java.util.stream.Stream; 028 029/** 030 * A default implementation of {@link ICommand} which provides easy access to the 031 * command's bound {@link IBaritone} instance, {@link IPlayerContext} and an easy 032 * way to provide multiple valid command execution names through the default constructor. 033 * <p> 034 * So basically, you should use it because it provides a small amount of boilerplate, 035 * but you're not forced to use it. 036 * 037 * @author LoganDark 038 * @see ICommand 039 */ 040public abstract class Command implements ICommand { 041 042 protected IBaritone baritone; 043 protected IPlayerContext ctx; 044 045 /** 046 * The names of this command. This is what you put after the command prefix. 047 */ 048 protected final List<String> names; 049 050 /** 051 * Creates a new Baritone control command. 052 * 053 * @param names The names of this command. This is what you put after the command prefix. 054 */ 055 protected Command(IBaritone baritone, String... names) { 056 this.names = Collections.unmodifiableList(Stream.of(names) 057 .map(s -> s.toLowerCase(Locale.US)) 058 .collect(Collectors.toList())); 059 this.baritone = baritone; 060 this.ctx = baritone.getPlayerContext(); 061 } 062 063 @Override 064 public final List<String> getNames() { 065 return this.names; 066 } 067}