mirror of
https://github.com/sekwah41/Advanced-Portals.git
synced 2025-03-11 06:14:29 +01:00
fix: improve auto complete for triggerblock
This commit is contained in:
parent
81e8876079
commit
12923480fc
@ -9,7 +9,9 @@ import com.sekwah.advancedportals.core.util.Lang;
|
||||
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 {
|
||||
@ -43,8 +45,22 @@ public class TriggerBlockTag implements Tag.AutoComplete {
|
||||
|
||||
@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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user