Skip to content

Commit 1cbd3ae

Browse files
authored
GH-253 Update suggestion service for case-insensitive matching. Release 3.0.2 (#268)
* Update suggestion service for case-insensitive matching. * Release 3.0.2
1 parent cd3f913 commit 1cbd3ae

File tree

10 files changed

+32
-11
lines changed

10 files changed

+32
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ maven("https://repo.panda-lang.org/releases")
3434

3535
### Dependency
3636
```kts
37-
implementation("dev.rollczi:{artifact}:3.0.2-SNAPSHOT")
37+
implementation("dev.rollczi:{artifact}:3.0.2")
3838
```
3939
```xml
4040
<dependency>
4141
<groupId>dev.rollczi</groupId>
4242
<artifactId>{artifact}</artifactId>
43-
<version>3.0.2-SNAPSHOT</version>
43+
<version>3.0.2</version>
4444
</dependency>
4545
```
4646
`{artifact}` replace with [platform artifact](https://github.com/Rollczi/LiteCommands#platform-artifacts)

buildSrc/src/main/kotlin/litecommands-publish.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ plugins {
44
}
55

66
group = "dev.rollczi"
7-
version = "3.0.2-SNAPSHOT"
7+
version = "3.0.2"
88

99
java {
1010
withSourcesJar()

examples/bukkit-adventure-platform/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ repositories {
1818
dependencies {
1919
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")
2020

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

examples/bukkit-chatgpt/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ repositories {
1818
dependencies {
1919
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")
2020

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

examples/bukkit/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repositories {
1818
dependencies {
1919
compileOnly("org.spigotmc:spigot-api:1.20.2-R0.1-SNAPSHOT")
2020

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

examples/velocity/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ dependencies {
1919
compileOnly("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
2020
annotationProcessor("com.velocitypowered:velocity-api:3.2.0-SNAPSHOT")
2121

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

litecommands-annotations/test/dev/rollczi/litecommands/annotations/suggestion/CustomSuggestionTest.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,16 @@ void testDefault() {
2929
.assertSuggest("default-suggestion");
3030
}
3131

32+
@Test
33+
@DisplayName("should suggest default suggestion with ignore case")
34+
void testIgnoreCase() {
35+
platform.suggest("test D")
36+
.assertSuggest("default-suggestion");
37+
38+
platform.suggest("test DEFAULT-SUGGESTION")
39+
.assertSuggest("default-suggestion");
40+
}
41+
3242
@Test
3343
@DisplayName("should suggest custom suggestion")
3444
void testCustom() {

litecommands-core/src/dev/rollczi/litecommands/suggestion/SuggestionResult.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dev.rollczi.litecommands.suggestion;
22

33
import dev.rollczi.litecommands.shared.IterableMutableArray;
4+
import dev.rollczi.litecommands.util.StringUtil;
45

56
import java.util.Collection;
67
import java.util.Collections;
@@ -32,7 +33,7 @@ public void addAll(SuggestionResult result) {
3233
public SuggestionResult filterBy(Suggestion suggestion) {
3334
String multilevel = suggestion.multilevel();
3435
Set<Suggestion> filtered = this.suggestions.stream()
35-
.filter(suggestion1 -> suggestion1.multilevel().startsWith(multilevel))
36+
.filter(current -> StringUtil.startsWithIgnoreCase(current.multilevel(), multilevel))
3637
.map(suggestion1 -> suggestion1.slashLevel(suggestion.lengthMultilevel() - 1))
3738
.collect(Collectors.toSet());
3839

litecommands-core/src/dev/rollczi/litecommands/suggestion/SuggestionService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import dev.rollczi.litecommands.command.CommandRoute;
1212
import dev.rollczi.litecommands.flow.Flow;
1313
import dev.rollczi.litecommands.invocation.Invocation;
14+
import dev.rollczi.litecommands.util.StringUtil;
1415
import dev.rollczi.litecommands.validator.ValidatorService;
1516

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

6566
for (CommandRoute<SENDER> child : commandRoute.getChildren()) {
6667
for (String name : child.names()) {
67-
if (!name.startsWith(current)) {
68+
if (!StringUtil.startsWithIgnoreCase(name, current)) {
6869
continue;
6970
}
7071

litecommands-core/src/dev/rollczi/litecommands/util/StringUtil.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,13 @@ public static String repeat(String text, int length) {
1616
return builder.toString();
1717
}
1818

19+
public static boolean startsWithIgnoreCase(String text, String prefix) {
20+
return text.regionMatches(true, 0, prefix, 0, prefix.length());
21+
}
22+
23+
public static boolean endsWithIgnoreCase(String str, String suffix) {
24+
int suffixLength = suffix.length();
25+
return str.regionMatches(true, str.length() - suffixLength, suffix, 0, suffixLength);
26+
}
27+
1928
}

0 commit comments

Comments
 (0)