Skip to content

Commit

Permalink
Add argument length limit.
Browse files Browse the repository at this point in the history
  • Loading branch information
toxicity188 committed Nov 9, 2024
1 parent 168d199 commit ebe11d3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ allprojects {
apply(plugin = "java")

group = "kr.toxicity.command"
version = "1.0"
version = "1.1"

repositories {
mavenCentral()
Expand Down
9 changes: 8 additions & 1 deletion core/src/main/java/kr/toxicity/command/CommandModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,15 @@ public final class CommandModule<W extends BetterCommandSource> implements Comma

@Override
public @NotNull Component usage(@NotNull W w) {
String args;
var size = arguments.size();
if (size <= 6) {
args = arguments.stream().map(CommandArgument::name).collect(Collectors.joining("\n"));
} else {
args = arguments.subList(0, 6).stream().map(CommandArgument::name).collect(Collectors.joining("\n")) + "\n+" + (size - 6);
}
return component(w, CHILDREN)
.hoverEvent(HoverEvent.showText(Component.text(arguments.stream().map(CommandArgument::name).collect(Collectors.joining(", ")))));
.hoverEvent(HoverEvent.showText(Component.text(args)));
}

public @NotNull CommandModule<W> executes(@NotNull CommandListener executor) {
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/kr/toxicity/command/MethodExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,16 @@ private record UsageGetter<T>(@NotNull CommandMessage message, @NotNull Function
var index = 0;
var last = usage.size() - 1;
for (UsageGetter<W> commandMessage : usage) {
var suggests = commandMessage.suggests.apply(w);
var size = suggests.size();
String args;
if (size <= 6) {
args = String.join("\n", suggests);
} else {
args = String.join("\n", suggests.subList(0, 6)) + "\n+" + (size - 6);
}
builder.append(root.registry.find(w, commandMessage.message)
.hoverEvent(HoverEvent.showText(Component.text(String.join(", ", commandMessage.suggests.apply(w))))));
.hoverEvent(HoverEvent.showText(Component.text(args))));
if (index++ < last) builder.append(Component.space());
}
return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public void die(@Source BetterCommandSource me) {
((Player) me.audience()).damage(9999);
me.audience().sendMessage(Component.text("Good bye!"));
}
@Command
@Description(key = "test.child.test", defaultValue = "Test command.")
@Permission("test.child.test")
public void test(@Source BetterCommandSource me, String sender, @Vararg @Option String argus) {
me.audience().sendMessage(Component.text(sender + ": " + argus));
}
}
));
for (LiteralArgumentBuilder<CommandSourceStack> builder : command.<CommandSourceStack>build(p -> {
Expand Down

0 comments on commit ebe11d3

Please sign in to comment.