Update to latest Piston changes

This commit is contained in:
Kenzie Togami
2019-04-27 03:33:13 -07:00
parent 7dcf8f5a45
commit 0960f70e6b
5 changed files with 77 additions and 55 deletions

View File

@ -39,6 +39,7 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter;
import com.sk89q.worldedit.function.operation.Operations;
import com.sk89q.worldedit.math.transform.Transform;
import com.sk89q.worldedit.session.ClipboardHolder;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
import com.sk89q.worldedit.util.io.Closer;
import com.sk89q.worldedit.util.io.file.FilenameException;
import org.enginehub.piston.annotation.Command;
@ -159,7 +160,7 @@ public class SchematicCommands {
boolean overwrite = f.exists();
if (overwrite) {
if (!player.hasPermission("worldedit.schematic.delete")) {
throw new StopExecutionException("That schematic already exists!");
throw new StopExecutionException(TextComponent.of("That schematic already exists!"));
}
if (!allowOverwrite) {
player.printError("That schematic already exists. Use the -f flag to overwrite it.");
@ -186,7 +187,8 @@ public class SchematicCommands {
File parent = f.getParentFile();
if (parent != null && !parent.exists()) {
if (!parent.mkdirs()) {
throw new StopExecutionException("Could not create folder for schematics!");
throw new StopExecutionException(TextComponent.of(
"Could not create folder for schematics!"));
}
}
@ -277,7 +279,7 @@ public class SchematicCommands {
@Switch(name = 'n', desc = "Sort by date, newest first")
boolean newFirst) {
if (oldFirst && newFirst) {
throw new StopExecutionException("Cannot sort by oldest and newest.");
throw new StopExecutionException(TextComponent.of("Cannot sort by oldest and newest."));
}
File dir = worldEdit.getWorkingDirectoryFile(worldEdit.getConfiguration().saveDir);
List<File> fileList = allFiles(dir);

View File

@ -83,13 +83,13 @@ public class PrintCommandHelp {
return;
}
List<String> visited = new ArrayList<>();
List<Command> visited = new ArrayList<>();
Command currentCommand = detectCommand(manager, commandPath.get(0));
if (currentCommand == null) {
actor.printError(String.format("The command '%s' could not be found.", commandPath.get(0)));
return;
}
visited.add(commandPath.get(0));
visited.add(currentCommand);
// Drill down to the command
for (int i = 1; i < commandPath.size(); i++) {
@ -103,8 +103,8 @@ public class PrintCommandHelp {
}
if (subCommands.containsKey(subCommand)) {
visited.add(subCommand);
currentCommand = subCommands.get(subCommand);
visited.add(currentCommand);
} else {
actor.printError(String.format("The sub-command '%s' under '%s' could not be found.",
subCommand, Joiner.on(" ").join(visited)));
@ -116,7 +116,8 @@ public class PrintCommandHelp {
if (subCommands.isEmpty()) {
// Create the message
CommandUsageBox box = new CommandUsageBox(currentCommand, String.join(" ", visited));
CommandUsageBox box = new CommandUsageBox(visited, visited.stream()
.map(Command::getName).collect(Collectors.joining(" ")));
actor.print(box.create());
} else {
printAllCommands(page, perPage, subCommands.values().stream(), actor, visited);
@ -124,7 +125,7 @@ public class PrintCommandHelp {
}
private static void printAllCommands(int page, int perPage, Stream<Command> commandStream, Actor actor,
List<String> commandList) {
List<Command> commandList) {
// Get a list of aliases
List<Command> commands = commandStream
.sorted(byCleanName())
@ -151,7 +152,8 @@ public class PrintCommandHelp {
// Add each command
for (Command mapping : list) {
String alias = (commandList.isEmpty() ? "/" : "") + mapping.getName();
String command = Stream.concat(commandList.stream(), Stream.of(mapping.getName()))
String command = Stream.concat(commandList.stream(), Stream.of(mapping))
.map(Command::getName)
.collect(Collectors.joining(" ", "/", ""));
box.appendCommand(alias, mapping.getDescription(), command);
}