Skip to content
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
5b040f3
Create PatternConflictsTest.java
Absolutionism Aug 17, 2025
0d6d12e
Draft
Absolutionism Aug 18, 2025
0ddb78a
Update
Absolutionism Aug 19, 2025
8fbcbe9
Update PatternParserTest.java
Absolutionism Aug 19, 2025
448fcc4
Merge remote-tracking branch 'upstream/dev/feature' into dev/PatternP…
Absolutionism Aug 19, 2025
7bc6f2d
Revert
Absolutionism Aug 19, 2025
a8ac3bd
Update PatternParserTest.java
Absolutionism Aug 19, 2025
52f9c4a
Update PatternParserTest.java
Absolutionism Aug 19, 2025
cec0b25
Filtering + Exclusions
Absolutionism Aug 19, 2025
c94941d
PatternElement Usage
Absolutionism Aug 20, 2025
733f838
Fix TypePatternElement
Absolutionism Aug 20, 2025
d275fe9
Partial Changes
Absolutionism Aug 20, 2025
aab610f
Update PatternConflictsTest.java
Absolutionism Aug 20, 2025
2fbb59b
Update PatternConflictsTest.java
Absolutionism Aug 20, 2025
cce1e19
Update PatternConflictsTest.java
Absolutionism Aug 21, 2025
13a79e7
Update PatternConflictsTest.java
Absolutionism Aug 21, 2025
78c18ce
Requested Changes
Absolutionism Aug 22, 2025
6470ac7
Merge branch 'dev/feature' into dev/PatternParser
Absolutionism Sep 1, 2025
1865c41
Pickles Changes
Absolutionism Sep 9, 2025
5950f61
Merge branch 'dev/feature' into dev/PatternParser
Absolutionism Sep 17, 2025
c4ca576
Merge branch 'dev/feature' into dev/PatternParser
Absolutionism Sep 17, 2025
8c6e558
Merge branch 'dev/feature' into dev/PatternParser
Absolutionism Sep 18, 2025
f6518d2
Merge branch 'dev/feature' into dev/PatternParser
Absolutionism Sep 18, 2025
0ddd3b2
Merge branch 'dev/feature' into dev/PatternParser
Efnilite Sep 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/ch/njol/skript/patterns/ChoicePatternElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -55,4 +57,12 @@ public String toString() {
.map(PatternElement::toFullString)
.collect(Collectors.joining("|"));
}

@Override
public Set<String> getCombinations(boolean clean) {
Set<String> combinations = new HashSet<>();
patternElements.forEach(patternElement -> combinations.addAll(patternElement.getAllCombinations(clean)));
return combinations;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.jetbrains.annotations.Nullable;

import java.util.Set;

/**
* A {@link PatternElement} that represents a group, for example {@code (test)}.
*/
Expand Down Expand Up @@ -34,4 +36,9 @@ public String toString() {
return "(" + patternElement + ")";
}

@Override
public Set<String> getCombinations(boolean clean) {
return patternElement.getAllCombinations(clean);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Locale;
import java.util.Set;

/**
* A {@link PatternElement} that contains a literal string to be matched, for example {@code hello world}.
Expand Down Expand Up @@ -52,4 +54,9 @@ public String toString() {
return new String(literal);
}

@Override
public Set<String> getCombinations(boolean clean) {
return new HashSet<>(Set.of(toString()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.jetbrains.annotations.Nullable;

import java.util.Set;

/**
* A {@link PatternElement} that contains an optional part, for example {@code [hello world]}.
*/
Expand Down Expand Up @@ -37,4 +39,11 @@ public String toString() {
return "[" + patternElement.toFullString() + "]";
}

@Override
public Set<String> getCombinations(boolean clean) {
Set<String> combinations = patternElement.getAllCombinations(clean);
combinations.add("");
return combinations;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* A {@link PatternElement} that applies a parse mark when matched.
Expand Down Expand Up @@ -82,4 +84,16 @@ public String toString() {
}
}

/**
* {@inheritDoc}
* @param clean Whether the parse mark/tag should be excluded.
*/
@Override
public Set<String> getCombinations(boolean clean) {
Set<String> combinations = new HashSet<>();
if (!clean)
combinations.add(toString());
return combinations;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static SkriptPattern compile(String pattern) throws MalformedPatternExcep
* {@link TypePatternElement} should be initiated with.
* @return The first link of the {@link PatternElement} chain
*/
private static PatternElement compile(String pattern, AtomicInteger expressionOffset) {
static PatternElement compile(String pattern, AtomicInteger expressionOffset) {
StringBuilder literalBuilder = new StringBuilder();
PatternElement first = null;

Expand Down
50 changes: 50 additions & 0 deletions src/main/java/ch/njol/skript/patterns/PatternElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;

public abstract class PatternElement {

@Nullable
Expand Down Expand Up @@ -48,4 +51,51 @@ public String toFullString() {
return stringBuilder.toString();
}

/**
* Gets the combinations available to this {@link PatternElement}.
* @param clean Whether unnecessary data, determined by each implementation, should be excluded from the combinations.
* @return The combinations.
*/
public abstract Set<String> getCombinations(boolean clean);

/**
* Gets all combinations available to this {@link PatternElement} and linked {@link PatternElement}s.
* @param clean Whether unnecessary data, determined by each implementation, should be excluded from the combinations.
* @return The combinations.
*/
public final Set<String> getAllCombinations(boolean clean) {
Set<String> combinations = getCombinations(clean);
if (combinations.isEmpty())
combinations.add("");
PatternElement next = this;
while ((next = next.originalNext) != null) {
Set<String> newCombinations = new HashSet<>();
Set<String> nextCombinations = next.getCombinations(clean);
if (nextCombinations.isEmpty())
continue;
for (String base : combinations) {
for (String add : nextCombinations) {
newCombinations.add(combineCombination(base, add));
}
}
combinations = newCombinations;
}
return combinations;
}

/**
* Helper method for appropriately combining two strings together.
* @return The resulting string.
*/
private static String combineCombination(String first, String second) {
if (first.isBlank()) {
return second.stripLeading();
} else if (second.isEmpty()) {
return first.stripTrailing();
} else if (first.endsWith(" ") && second.startsWith(" ")) {
return first + second.stripLeading();
}
return first + second;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import ch.njol.skript.log.SkriptLogger;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -58,4 +60,9 @@ public String toString() {
return "<" + pattern + ">";
}

@Override
public Set<String> getCombinations(boolean clean) {
return new HashSet<>(Set.of(toString()));
}

}
18 changes: 18 additions & 0 deletions src/main/java/ch/njol/skript/patterns/TypePatternElement.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import ch.njol.util.NonNullPair;
import org.jetbrains.annotations.Nullable;

import java.util.HashSet;
import java.util.Set;

/**
* A {@link PatternElement} that contains a type to be matched with an expressions, for example {@code %number%}.
*/
Expand Down Expand Up @@ -263,4 +266,19 @@ public ExprInfo getExprInfo() {
return exprInfo;
}

/**
* {@inheritDoc}
* @param clean Whether this type should be replaced with {@code %*%} if it's not literal.
*/
@Override
public Set<String> getCombinations(boolean clean) {
Set<String> combinations = new HashSet<>();
if (!clean || flagMask == 2) {
combinations.add(toString());
} else {
combinations.add("%*%");
}
return combinations;
}

}
Loading