Skip to content

Commit

Permalink
fix: improve auto complete for triggerblock
Browse files Browse the repository at this point in the history
  • Loading branch information
sekwah41 committed Nov 18, 2024
1 parent 81e8876 commit 1292348
Showing 1 changed file with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import com.sekwah.advancedportals.core.warphandler.ActivationData;
import com.sekwah.advancedportals.core.warphandler.Tag;

import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

public class TriggerBlockTag implements Tag.AutoComplete {
Expand Down Expand Up @@ -43,8 +45,22 @@ public String description() {

@Override
public List<String> autoComplete(String argData) {
boolean endsWithComma = argData.endsWith(",");
String[] items = argData.split(",");
Set<String> existingItems = Arrays.stream(items, 0, endsWithComma ? items.length : items.length - 1)
.map(String::trim)
.collect(Collectors.toSet());

String partialInput = endsWithComma ? "" : items[items.length - 1].trim();
String baseString = endsWithComma ? argData : argData.substring(0, argData.lastIndexOf(",") + 1);

return serverContainer.getTriggerBlocks().stream()
.filter(s -> s.startsWith(argData))
// Remove already listed items
.filter(s -> !existingItems.contains(s))
// Remove items that don't match the currently typed input
.filter(s -> s.startsWith(partialInput))
// Remap so the auto completes actually show
.map(s -> baseString + s)
.collect(Collectors.toList());
}
}

0 comments on commit 1292348

Please sign in to comment.