Skip to content

Commit

Permalink
Merge branch '1.13.2' into 1.14.4
Browse files Browse the repository at this point in the history
  • Loading branch information
leijurv committed Oct 12, 2019
2 parents 84a257f + 1c00e16 commit 2b3a302
Show file tree
Hide file tree
Showing 99 changed files with 321 additions and 263 deletions.
4 changes: 2 additions & 2 deletions src/api/java/baritone/api/IBaritoneProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package baritone.api;

import baritone.api.cache.IWorldScanner;
import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.ICommandSystem;
import net.minecraft.client.entity.player.ClientPlayerEntity;

Expand Down Expand Up @@ -77,7 +77,7 @@ default IBaritone getBaritoneForPlayer(ClientPlayerEntity player) {

/**
* Returns the {@link ICommandSystem} instance. This is not bound to a specific {@link IBaritone}
* instance because {@link ICommandSystem} itself controls global behavior for {@link Command}s.
* instance because {@link ICommandSystem} itself controls global behavior for {@link ICommand}s.
*
* @return The {@link ICommandSystem} instance.
*/
Expand Down
46 changes: 14 additions & 32 deletions src/api/java/baritone/api/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,27 @@
package baritone.api.command;

import baritone.api.IBaritone;
import baritone.api.utils.Helper;
import baritone.api.utils.IPlayerContext;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.arguments.IArgConsumer;

import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public abstract class Command implements Helper {
/**
* A default implementation of {@link ICommand} which provides easy access to the
* command's bound {@link IBaritone} instance, {@link IPlayerContext} and an easy
* way to provide multiple valid command execution names through the default constructor.
* <p>
* So basically, you should use it because it provides a small amount of boilerplate,
* but you're not forced to use it.
*
* @see ICommand
*
* @author LoganDark
*/
public abstract class Command implements ICommand {

protected IBaritone baritone;
protected IPlayerContext ctx;
Expand All @@ -52,34 +61,7 @@ protected Command(IBaritone baritone, String... names) {
this.ctx = baritone.getPlayerContext();
}

/**
* Called when this command is executed.
*/
public abstract void execute(String label, IArgConsumer args) throws CommandException;

/**
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
* list.
*/
public abstract Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException;

/**
* @return A <b>single-line</b> string containing a short description of this command's purpose.
*/
public abstract String getShortDesc();

/**
* @return A list of lines that will be printed by the help command when the user wishes to view them.
*/
public abstract List<String> getLongDesc();

/**
* @return {@code true} if this command should be hidden from the help menu
*/
public boolean hiddenFromHelp() {
return false;
}

@Override
public final List<String> getNames() {
return this.names;
}
Expand Down
67 changes: 67 additions & 0 deletions src/api/java/baritone/api/command/ICommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* This file is part of Baritone.
*
* Baritone is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Baritone 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/

package baritone.api.command;

import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;
import baritone.api.utils.Helper;

import java.util.List;
import java.util.stream.Stream;

/**
* The base for a command.
*
* @author Brady
* @since 10/7/2019
*/
public interface ICommand extends Helper {

/**
* Called when this command is executed.
*/
void execute(String label, IArgConsumer args) throws CommandException;

/**
* Called when the command needs to tab complete. Return a Stream representing the entries to put in the completions
* list.
*/
Stream<String> tabComplete(String label, IArgConsumer args) throws CommandException;

/**
* @return A <b>single-line</b> string containing a short description of this command's purpose.
*/
String getShortDesc();

/**
* @return A list of lines that will be printed by the help command when the user wishes to view them.
*/
List<String> getLongDesc();

/**
* @return A list of the names that can be accepted to have arguments passed to this command
*/
List<String> getNames();

/**
* @return {@code true} if this command should be hidden from the help menu
*/
default boolean hiddenFromHelp() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
import baritone.api.command.registry.Registry;

/**
* Used to retrieve {@link IArgParser} instances from the registry, by their target class.
* It can be assumed that a {@link IArgParser} exists for {@link Integer}, {@link Long},
* {@link Float}, {@link Double} and {@link Boolean}.
*
* @author Brady
* @since 10/4/2019
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
* along with Baritone. If not, see <https://www.gnu.org/licenses/>.
*/

package baritone.api.command.helpers.arguments;
package baritone.api.command.argument;

import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.exception.CommandTooManyArgumentsException;
import baritone.api.utils.Helper;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.argument.ICommandArgument;
import baritone.api.command.datatypes.IDatatype;
import baritone.api.command.datatypes.IDatatypeFor;
import baritone.api.command.datatypes.IDatatypePost;
Expand All @@ -35,7 +34,7 @@
import java.util.stream.Stream;

/**
* The {@link IArgConsumer} is how {@link Command}s read the arguments passed to them. This class has many benefits:
* The {@link IArgConsumer} is how {@link ICommand}s read the arguments passed to them. This class has many benefits:
*
* <ul>
* <li>Mutability. The whole concept of the {@link IArgConsumer}} is to let you gradually consume arguments in any way
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

package baritone.api.command.argument;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argparser.IArgParser;
import baritone.api.command.exception.CommandInvalidTypeException;
import net.minecraft.util.Direction;
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/baritone/api/command/datatypes/BlockById.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package baritone.api.command.datatypes;

import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.block.Block;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package baritone.api.command.datatypes;

import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.EntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException;
import net.minecraft.util.Direction;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import baritone.api.IBaritone;
import baritone.api.cache.IWaypoint;
import baritone.api.cache.IWaypointCollection;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.helpers.TabCompleteHelper;
import baritone.api.command.exception.CommandException;

import java.util.Comparator;
Expand Down
2 changes: 1 addition & 1 deletion src/api/java/baritone/api/command/datatypes/IDatatype.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package baritone.api.command.datatypes;

import baritone.api.command.argparser.IArgParser;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;

import java.util.stream.Stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
package baritone.api.command.datatypes;

import baritone.api.IBaritone;
import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;

/**
* Provides an {@link IDatatype} with contextual information so
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import baritone.api.IBaritone;
import baritone.api.command.exception.CommandException;
import baritone.api.command.helpers.tabcomplete.TabCompleteHelper;
import baritone.api.command.helpers.TabCompleteHelper;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.text.ITextComponent;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;

import java.util.regex.Matcher;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.command.exception.CommandException;

import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.Goal;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.pathing.goals.GoalXZ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalBlock;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalXZ;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.datatypes;

import baritone.api.command.helpers.arguments.IArgConsumer;
import baritone.api.command.argument.IArgConsumer;
import baritone.api.pathing.goals.GoalYLevel;
import baritone.api.utils.BetterBlockPos;
import baritone.api.command.exception.CommandException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.exception;

import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;

import java.util.List;
Expand All @@ -34,7 +34,7 @@ public CommandNotFoundException(String command) {
}

@Override
public void handle(Command command, List<ICommandArgument> args) {
public void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect(getMessage());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.exception;

import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;

Expand All @@ -36,7 +36,7 @@ public CommandUnhandledException(Throwable cause) {
}

@Override
public void handle(Command command, List<ICommandArgument> args) {
public void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect("An unhandled exception occurred." +
"The error is in your game's log, please report this at https://github.com/cabaletta/baritone/issues",
TextFormatting.RED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

package baritone.api.command.exception;

import baritone.api.command.Command;
import baritone.api.command.ICommand;
import baritone.api.command.argument.ICommandArgument;
import net.minecraft.util.text.TextFormatting;

Expand All @@ -27,7 +27,7 @@

/**
* The base for a Baritone Command Exception, checked or unchecked. Provides a
* {@link #handle(Command, List)} method that is used to provide useful output
* {@link #handle(ICommand, List)} method that is used to provide useful output
* to the user for diagnosing issues that may have occurred during execution.
* <p>
* Anything implementing this interface should be assignable to {@link Exception}.
Expand All @@ -49,7 +49,7 @@ public interface ICommandException {
* @param command The command that threw it.
* @param args The arguments the command was called with.
*/
default void handle(Command command, List<ICommandArgument> args) {
default void handle(ICommand command, List<ICommandArgument> args) {
HELPER.logDirect(this.getMessage(), TextFormatting.RED);
}
}
Loading

0 comments on commit 2b3a302

Please sign in to comment.