diff --git a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java index 634d6833..4a29fba9 100644 --- a/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java +++ b/core/src/main/java/com/sekwah/advancedportals/core/tags/activation/TriggerBlockTag.java @@ -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 { @@ -43,8 +45,22 @@ public String description() { @Override public List autoComplete(String argData) { + boolean endsWithComma = argData.endsWith(","); + String[] items = argData.split(","); + Set 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()); } }