Skip to content

Commit

Permalink
GH-253 Update suggestion service for case-insensitive matching. Relea…
Browse files Browse the repository at this point in the history
…se 3.0.2 (#268)

* Update suggestion service for case-insensitive matching.

* Release 3.0.2
  • Loading branch information
Rollczi authored Oct 29, 2023
1 parent cd3f913 commit 1cbd3ae
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 11 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ maven("https://repo.panda-lang.org/releases")

### Dependency
```kts
implementation("dev.rollczi:{artifact}:3.0.2-SNAPSHOT")
implementation("dev.rollczi:{artifact}:3.0.2")
```
```xml
<dependency>
<groupId>dev.rollczi</groupId>
<artifactId>{artifact}</artifactId>
<version>3.0.2-SNAPSHOT</version>
<version>3.0.2</version>
</dependency>
```
`{artifact}` replace with [platform artifact](https://github.com/Rollczi/LiteCommands#platform-artifacts)
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/litecommands-publish.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ plugins {
}

group = "dev.rollczi"
version = "3.0.2-SNAPSHOT"
version = "3.0.2"

java {
withSourcesJar()
Expand Down
4 changes: 2 additions & 2 deletions examples/bukkit-adventure-platform/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ repositories {
dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")

// implementation("dev.rollczi:litecommands-bukkit:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-adventure-platform:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-bukkit:3.0.2") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-adventure-platform:3.0.2") // <-- uncomment in your project
implementation("net.kyori:adventure-platform-bukkit:4.3.0")
implementation("net.kyori:adventure-text-minimessage:4.14.0")

Expand Down
4 changes: 2 additions & 2 deletions examples/bukkit-chatgpt/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ repositories {
dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")

// implementation("dev.rollczi:litecommands-bukkit:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-chatgpt:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-bukkit:3.0.2") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-chatgpt:3.0.2") // <-- uncomment in your project
implementation(project(":litecommands-bukkit")) // don't use this line in your build.gradle
implementation(project(":litecommands-chatgpt")) // don't use this line in your build.gradle
}
Expand Down
2 changes: 1 addition & 1 deletion examples/bukkit/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ repositories {
dependencies {
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")

// implementation("dev.rollczi:litecommands-bukkit:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-bukkit:3.0.2") // <-- uncomment in your project
implementation(project(":litecommands-bukkit")) // don't use this line in your build.gradle
}

Expand Down
2 changes: 1 addition & 1 deletion examples/velocity/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dependencies {
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")

// implementation("dev.rollczi:litecommands-velocity:3.0.2-SNAPSHOT") // <-- uncomment in your project
// implementation("dev.rollczi:litecommands-velocity:3.0.2") // <-- uncomment in your project
implementation(project(":litecommands-velocity")) // don't use this line in your build.gradle
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,16 @@ void testDefault() {
.assertSuggest("default-suggestion");
}

@Test
@DisplayName("should suggest default suggestion with ignore case")
void testIgnoreCase() {
platform.suggest("test D")
.assertSuggest("default-suggestion");

platform.suggest("test DEFAULT-SUGGESTION")
.assertSuggest("default-suggestion");
}

@Test
@DisplayName("should suggest custom suggestion")
void testCustom() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.rollczi.litecommands.suggestion;

import dev.rollczi.litecommands.shared.IterableMutableArray;
import dev.rollczi.litecommands.util.StringUtil;

import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -32,7 +33,7 @@ public void addAll(SuggestionResult result) {
public SuggestionResult filterBy(Suggestion suggestion) {
String multilevel = suggestion.multilevel();
Set<Suggestion> filtered = this.suggestions.stream()
.filter(suggestion1 -> suggestion1.multilevel().startsWith(multilevel))
.filter(current -> StringUtil.startsWithIgnoreCase(current.multilevel(), multilevel))
.map(suggestion1 -> suggestion1.slashLevel(suggestion.lengthMultilevel() - 1))
.collect(Collectors.toSet());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import dev.rollczi.litecommands.command.CommandRoute;
import dev.rollczi.litecommands.flow.Flow;
import dev.rollczi.litecommands.invocation.Invocation;
import dev.rollczi.litecommands.util.StringUtil;
import dev.rollczi.litecommands.validator.ValidatorService;

public class SuggestionService<SENDER> {
Expand Down Expand Up @@ -64,7 +65,7 @@ private <MATCHER extends SuggestionInputMatcher<MATCHER>> SuggestionResult sugge

for (CommandRoute<SENDER> child : commandRoute.getChildren()) {
for (String name : child.names()) {
if (!name.startsWith(current)) {
if (!StringUtil.startsWithIgnoreCase(name, current)) {
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ public static String repeat(String text, int length) {
return builder.toString();
}

public static boolean startsWithIgnoreCase(String text, String prefix) {
return text.regionMatches(true, 0, prefix, 0, prefix.length());
}

public static boolean endsWithIgnoreCase(String str, String suffix) {
int suffixLength = suffix.length();
return str.regionMatches(true, str.length() - suffixLength, suffix, 0, suffixLength);
}

}

0 comments on commit 1cbd3ae

Please sign in to comment.