diff --git a/src/main/java/net/earthcomputer/clientcommands/command/SignSearchCommand.java b/src/main/java/net/earthcomputer/clientcommands/command/SignSearchCommand.java index af08775e..9054e9c0 100644 --- a/src/main/java/net/earthcomputer/clientcommands/command/SignSearchCommand.java +++ b/src/main/java/net/earthcomputer/clientcommands/command/SignSearchCommand.java @@ -18,6 +18,8 @@ import net.minecraft.world.level.block.state.BlockState; import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import static com.mojang.brigadier.arguments.StringArgumentType.*; import static net.earthcomputer.clientcommands.command.arguments.RegexArgument.*; @@ -55,15 +57,12 @@ public boolean test(HolderLookup.Provider holderLookupProvider, BlockGetter bloc return false; } - SignText frontText = sign.getFrontText(); - SignText backText = sign.getBackText(); - for (int i = 0; i < SignText.LINES; i++) { - String line = frontText.getMessage(i, Minecraft.getInstance().isTextFilteringEnabled()).getString(); - if (linePredicate.test(line)) { - return true; - } - line = backText.getMessage(i, Minecraft.getInstance().isTextFilteringEnabled()).getString(); - if (linePredicate.test(line)) { + boolean textFilteringEnabled = Minecraft.getInstance().isTextFilteringEnabled(); + for (SignText text : new SignText[]{sign.getFrontText(), sign.getBackText()}) { + String string = IntStream.range(0, SignText.LINES) + .mapToObj(i -> text.getMessage(i, textFilteringEnabled).getString()) + .collect(Collectors.joining("\n")); + if (linePredicate.test(string)) { return true; } } @@ -77,5 +76,4 @@ public boolean canEverMatch(BlockState state) { } }; } - }