SwitchCraftCC / issues

Report general bugs for the SwitchCraft 3 server here. This tracker is NOT for exploits - please disclose those responsibly and privately to a member of staff.
1 stars 0 forks source link

Claimkit command autocomplete does not work properly #104

Closed znepb closed 8 months ago

znepb commented 1 year ago

Describe the bug

When trusting a user (or any other ClaimKit command that involves "autocomplete",) the command will not properly autocomplete the message Example: Notice ".public" is selected, though "HerrKatzeGaming" should be

applies to other autocomplete brigadier things

To reproduce

  1. Create a claim
  2. Try to /trust someone in it
  3. Notice that their username is not suggested when typing the first few characters

Expected behavior

Intended behavior, in which /w will suggest the username you are typing intended behavior

Relevant log output

No response

Please confirm

Lemmmy commented 10 months ago

(internal ref)

Should be a trivial fix. ClaimKit isn't doing it's own startsWith check when adding suggestions to the SuggestionsBuilder, here: https://github.com/SwitchCraftCC/ClaimKit/blob/da28c414856499fb42a2cfa7a8ffd8c8fdaae058/src/main/java/com/kotahu/claimkit/commands/Trust.java#L40-L46

ClaimKit code:

    private static CompletableFuture<Suggestions> suggestPlayers(CommandContext<ServerCommandSource> context, SuggestionsBuilder builder) {
            ArrayList<String> l = UUIDs.getOnlinePlayerNames();
            l.add(".public");
            for (String a : l)
                builder.suggest(a);
            return builder.buildFuture();
    }

I don't have a clue what's going on in lines 30-32 from the same file, but it probably has the same issue.

Example code doing it correctly from sc-essentials:

fun warpArgument(name: String = "name"): RequiredArgumentBuilder<ServerCommandSource, String>
  = argument(name, word())
    .suggests { _, builder ->
      val remaining = builder.remainingLowerCase

      Warps.warps()
        .map { it.name }
        .filter { it.lowercase().startsWith(remaining) }
        .forEach { builder.suggest(it) }

      builder.buildFuture()
    }

And another correct example from CC:

    public static <T> CompletableFuture<Suggestions> suggest(SuggestionsBuilder builder, Iterable<T> candidates, Function<T, String> toString) {
        var remaining = builder.getRemaining().toLowerCase(Locale.ROOT);
        for (var choice : candidates) {
            var name = toString.apply(choice);
            if (!name.toLowerCase(Locale.ROOT).startsWith(remaining)) continue;
            builder.suggest(name);
        }

        return builder.buildFuture();
    }
Lemmmy commented 8 months ago

Fixed on 2024-03-02.