Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix command error output #148

Merged
merged 3 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont

if (ex instanceof ArgumentParseException.WithUsage) {
// This indicates a previous child failed, so we just prepend our child
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage()));
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage().asUnformattedString()));
}

throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source)));
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source).asUnformattedString()));
}
} else {
// Not a child, so let's continue with the fallback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean canComplete() {
*/
public String peek() throws ArgumentParseException {
if (!this.hasNext()) {
throw this.createError(new LiteralText("Not enough arguments"));
throw this.createError(new LiteralText("Not enough arguments!"));
}

return this.args.get(this.index + 1).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont
* @return The formatted usage
*/
public Text getUsage(PermissibleCommandSource src) {
return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey() + ">");
return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey().asUnformattedString() + ">");
}

public MinecraftServer getServer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ public Optional<Text> getHelp(PermissibleCommandSource source) {
Preconditions.checkNotNull(source, "source");
StringBuilder builder = new StringBuilder();
this.getShortDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n"));
builder.append(this.getUsage(source));
builder.append(this.getUsage(source).asUnformattedString());
this.getExtendedDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n"));
return Optional.of(new LiteralText(builder.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public CommandResult process(PermissibleCommandSource source, String command) {
usage = mapping.get().getCallable().getUsage(source);
}

source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage))));
source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage.asUnformattedString()))));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void method_3279(MinecraftServer minecraftServer, CommandSource source, S
usage = this.mapping.getCallable().getUsage((PermissibleCommandSource) source);
}

source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage))));
source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage.asUnformattedString()))));
}
}
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont

if (ex instanceof ArgumentParseException.WithUsage) {
// This indicates a previous child failed, so we just prepend our child
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage()));
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + ((ArgumentParseException.WithUsage) ex).getUsage().asUnformattedString()));
}

throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source)));
throw new ArgumentParseException.WithUsage(ex, new LiteralText(key + " " + mapping.getCallable().getUsage(source).asUnformattedString()));
}
} else {
// Not a child, so let's continue with the fallback.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public boolean canComplete() {
*/
public String peek() throws ArgumentParseException {
if (!this.hasNext()) {
throw this.createError(new LiteralText("Not enough arguments"));
throw this.createError(new LiteralText("Not enough arguments!"));
}

return this.args.get(this.index + 1).getValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,6 @@ public void parse(PermissibleCommandSource source, CommandArgs args, CommandCont
* @return The formatted usage
*/
public Text getUsage(PermissibleCommandSource src) {
return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey() + ">");
return this.getKey() == null ? new LiteralText("") : new LiteralText("<" + this.getKey().asUnformattedString() + ">");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ public Optional<Text> getHelp(PermissibleCommandSource source) {
Preconditions.checkNotNull(source, "source");
StringBuilder builder = new StringBuilder();
this.getShortDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n"));
builder.append(this.getUsage(source));
builder.append(this.getUsage(source).asUnformattedString());
this.getExtendedDescription(source).ifPresent((a) -> builder.append(a.asUnformattedString()).append("\n"));
return Optional.of(new LiteralText(builder.toString()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public CommandResult process(PermissibleCommandSource source, String command) {
usage = mapping.get().getCallable().getUsage(source);
}

source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage))));
source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", argSplit[0], usage.asUnformattedString()))));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void execute(CommandSource source, String[] args) {
usage = this.mapping.getCallable().getUsage((PermissibleCommandSource) source);
}

source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage))));
source.sendMessage(CommandMessageFormatting.error(new LiteralText(String.format("Usage: /%s %s", this.getCommandName(), usage.asUnformattedString()))));
}
}
} catch (Throwable t) {
Expand Down