diff options
3 files changed, 23 insertions, 2 deletions
diff --git a/src/main/java/com/notnite/gloppers/GlobUtil.java b/src/main/java/com/notnite/gloppers/GlobUtil.java index 38d0e44..2ae051c 100644 --- a/src/main/java/com/notnite/gloppers/GlobUtil.java +++ b/src/main/java/com/notnite/gloppers/GlobUtil.java @@ -4,6 +4,16 @@ import java.util.BitSet; public class GlobUtil { + public static boolean matchGlobSequence(String name, String globs) { + int nextSplit, lastSplit = 0; + while ((nextSplit = globs.indexOf(',', lastSplit)) > 0) { + if (matchGlob(name, globs.substring(lastSplit, nextSplit))) + return true; + lastSplit = nextSplit + 1; + } + return matchGlob(name, globs.substring(lastSplit)); + } + /** * Match a string against a glob. */ diff --git a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java index 06eb93e..52cbdcc 100644 --- a/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java +++ b/src/main/java/com/notnite/gloppers/mixin/HopperBlockEntityMixin.java @@ -44,7 +44,7 @@ public abstract class HopperBlockEntityMixin { var itemName = itemRegistryEntry.get().getValue().getPath(); // Check if itemstack matches glob - if (!GlobUtil.matchGlob(itemName, glob)) return false; + if (!GlobUtil.matchGlobSequence(itemName, glob)) return false; return true; } diff --git a/src/test/java/com/notnite/gloppers/GlobUtilTest.java b/src/test/java/com/notnite/gloppers/GlobUtilTest.java index 064ced1..1ceed6a 100644 --- a/src/test/java/com/notnite/gloppers/GlobUtilTest.java +++ b/src/test/java/com/notnite/gloppers/GlobUtilTest.java @@ -6,6 +6,17 @@ import static org.junit.jupiter.api.Assertions.*; class GlobUtilTest { @Test + public void multiGlobPattern() { + assertTrue(GlobUtil.matchGlobSequence("test", "test,foo")); + assertTrue(GlobUtil.matchGlobSequence("foo", "test,foo")); + assertTrue(GlobUtil.matchGlobSequence("foo", "foo")); + assertTrue(GlobUtil.matchGlobSequence("foo", "test,f*")); + assertTrue(GlobUtil.matchGlobSequence("foo", "*o,f*")); + assertFalse(GlobUtil.matchGlobSequence("baa", "*o,f*")); + } + + + @Test public void testGlobBeginning() { assertTrue(GlobUtil.matchGlob("test_id", "*_id")); assertTrue(GlobUtil.matchGlob("test__id", "*_id")); @@ -28,7 +39,7 @@ class GlobUtilTest { } @Test - public void testSinglePlaceholder() { + public void testSingleGlobPlaceholder() { assertTrue(GlobUtil.matchGlob("test_id", "tes?_i?")); } } |