Improved modifier help

This commit is contained in:
Jesse Boyd 2017-08-02 14:32:44 +10:00
parent fb3c8cc5e1
commit 914165b428
No known key found for this signature in database
GPG Key ID: 59F1DE6293AF6E1F
4 changed files with 29 additions and 33 deletions

View File

@ -6,7 +6,6 @@ import com.boydti.fawe.util.MainUtil;
import com.boydti.fawe.util.StringMan;
import com.sk89q.minecraft.util.commands.CommandLocals;
import com.sk89q.minecraft.util.commands.Link;
import com.sk89q.worldedit.WorldEdit;
import com.sk89q.worldedit.extension.platform.CommandManager;
import com.sk89q.worldedit.util.command.CommandCallable;
import com.sk89q.worldedit.util.command.CommandMapping;
@ -70,6 +69,10 @@ public class UsageMessage extends Message {
}
}
public String separateArg(String arg) {
return " " + arg;
}
private void attachCommandUsage(Description description, String commandString) {
List<Parameter> params = description.getParameters();
String[] usage;
@ -96,12 +99,11 @@ public class UsageMessage extends Message {
prefix();
text("&cUsage: ");
commandString = (WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/") + commandString;
text("&7" + commandString);
suggestTip(commandString + " ");
for (int i = 0; i < usage.length; i++) {
String argStr = usage[i];
text(" " + argStr.replaceAll("[\\[|\\]|<|>]", "&8$0&7"));
text(separateArg(argStr.replaceAll("[\\[|\\]|<|>]", "&0$0&7")));
if (params.isEmpty()) continue;
Parameter param = params.get(i);

View File

@ -31,6 +31,7 @@ import com.boydti.fawe.object.io.FastByteArrayOutputStream;
import com.boydti.fawe.object.schematic.Schematic;
import com.boydti.fawe.util.ImgurUtility;
import com.boydti.fawe.util.MaskTraverser;
import com.boydti.fawe.util.chat.Message;
import com.sk89q.minecraft.util.commands.Command;
import com.sk89q.minecraft.util.commands.CommandContext;
import com.sk89q.minecraft.util.commands.CommandException;
@ -315,7 +316,7 @@ public class ClipboardCommands extends MethodCommands {
if (url == null) {
BBC.GENERATING_LINK_FAILED.send(player);
} else {
BBC.DOWNLOAD_LINK.send(player, url.toString());
new Message(BBC.DOWNLOAD_LINK, url).link(url.getPath()).send(player);
}
}

View File

@ -19,7 +19,6 @@
package com.sk89q.worldedit.command;
import com.boydti.fawe.Fawe;
import com.boydti.fawe.FaweAPI;
import com.boydti.fawe.config.BBC;
import com.boydti.fawe.config.Commands;
@ -47,8 +46,6 @@ import com.sk89q.worldedit.command.util.CreatureButcher;
import com.sk89q.worldedit.command.util.EntityRemover;
import com.sk89q.worldedit.entity.Entity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.extension.factory.DefaultMaskParser;
import com.sk89q.worldedit.extension.factory.DefaultTransformParser;
import com.sk89q.worldedit.extension.factory.HashTagPatternParser;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extension.platform.Capability;
@ -118,16 +115,7 @@ public class UtilityCommands extends MethodCommands {
"More Info: https://git.io/vSPmA"
)
public void patterns(Player player, LocalSession session, CommandContext args) throws WorldEditException {
if (args.argsLength() == 0) {
String base = getCommand().aliases()[0];
UsageMessage msg = new UsageMessage(getCallable(), base, args.getLocals());
msg.newline().paginate(base, 0, 1).send(player);
return;
}
HashTagPatternParser parser = FaweAPI.getParser(HashTagPatternParser.class);
if (parser != null) {
UtilityCommands.help(args, worldEdit, player, getCommand().aliases()[0] + " ", parser.getDispatcher());
}
displayModifierHelp(player, args);
}
@Command(
@ -142,16 +130,7 @@ public class UtilityCommands extends MethodCommands {
"More Info: https://git.io/v9r4K"
)
public void masks(Player player, LocalSession session, CommandContext args) throws WorldEditException {
if (args.argsLength() == 0) {
String base = getCommand().aliases()[0];
UsageMessage msg = new UsageMessage(getCallable(), base, args.getLocals());
msg.newline().paginate(base, 0, 1).send(player);
return;
}
DefaultMaskParser parser = FaweAPI.getParser(DefaultMaskParser.class);
if (parser != null) {
UtilityCommands.help(args, worldEdit, player, getCommand().aliases()[0] + " ", parser.getDispatcher());
}
displayModifierHelp(player, args);
}
@Command(
@ -165,15 +144,29 @@ public class UtilityCommands extends MethodCommands {
"More Info: https://git.io/v9KHO"
)
public void transforms(Player player, LocalSession session, CommandContext args) throws WorldEditException {
displayModifierHelp(player, args);
}
private void displayModifierHelp(Player player, CommandContext args) {
if (args.argsLength() == 0) {
String base = getCommand().aliases()[0];
UsageMessage msg = new UsageMessage(getCallable(), base, args.getLocals());
UsageMessage msg = new UsageMessage(getCallable(), (WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/") + base, args.getLocals());
msg.newline().paginate(base, 0, 1).send(player);
return;
}
DefaultTransformParser parser = Fawe.get().getTransformParser();
HashTagPatternParser parser = FaweAPI.getParser(HashTagPatternParser.class);
if (parser != null) {
UtilityCommands.help(args, worldEdit, player, getCommand().aliases()[0] + " ", parser.getDispatcher());
CommandMapping mapping = parser.getDispatcher().get(args.getString(0));
if (mapping != null) {
new UsageMessage(mapping.getCallable(), args.getString(0), args.getLocals()) {
@Override
public String separateArg(String arg) {
return "&7[" + arg + "&7]";
}
}.send(player);
} else {
UtilityCommands.help(args, worldEdit, player, getCommand().aliases()[0] + " ", parser.getDispatcher());
}
}
}
@ -935,7 +928,7 @@ public class UtilityCommands extends MethodCommands {
}
if (!(callable instanceof Dispatcher)) {
// TODO interactive box
new UsageMessage(callable, Joiner.on(" ").join(visited)).send(actor);
new UsageMessage(callable, (WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/") + Joiner.on(" ").join(visited)).send(actor);
return;
}
dispatcher = (Dispatcher) callable;
@ -1018,7 +1011,7 @@ public class UtilityCommands extends MethodCommands {
msg.send(actor);
}
} else {
new UsageMessage(callable, Joiner.on(" ").join(visited)).send(actor);
new UsageMessage(callable, (WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/") + Joiner.on(" ").join(visited)).send(actor);
}
} catch (Throwable e) {
e.printStackTrace();

View File

@ -393,7 +393,7 @@ public final class CommandManager {
BBC.NO_PERM.send(finalActor, StringMan.join(failedPermissions, " "));
} catch (InvalidUsageException e) {
if (e.isFullHelpSuggested()) {
UsageMessage usage = new UsageMessage(e.getCommand(), e.getCommandUsed("", ""), locals);
UsageMessage usage = new UsageMessage(e.getCommand(), e.getCommandUsed((WorldEdit.getInstance().getConfiguration().noDoubleSlash ? "" : "/"), ""), locals);
usage.send(fp);
String message = e.getMessage();
if (message != null) {