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 Dec 18, 2023
1 parent fd0f011 commit f7c5dac
Showing 1 changed file with 14 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,19 @@ 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))
.filter(s -> !existingItems.contains(s))
.filter(s -> s.startsWith(partialInput))
.map(s -> baseString + s)
.collect(Collectors.toList());
}
}

0 comments on commit f7c5dac

Please sign in to comment.