Skip to content

Commit 550eb31

Browse files
committed
fix TreeUtil.findParent()
1 parent ffd36a2 commit 550eb31

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

src/main/java/com/cleanroommc/modularui/utils/TreeUtil.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.cleanroommc.modularui.ModularUI;
44
import com.cleanroommc.modularui.api.ITreeNode;
55
import com.cleanroommc.modularui.api.widget.IWidget;
6-
import com.cleanroommc.modularui.screen.ModularPanel;
76
import com.cleanroommc.modularui.widget.sizer.ResizeNode;
87

98
import com.google.common.collect.AbstractIterator;
@@ -289,6 +288,7 @@ public static <T extends ITreeNode<T>, R extends ITreeNode<T>> List<R> flatListB
289288
* @param test test which the widget has to pass
290289
* @return the first matching widget
291290
*/
291+
@Nullable
292292
public static <T extends ITreeNode<T>> T findFirst(T parent, @NotNull Predicate<T> test) {
293293
return foreachChildWithResult(parent, w -> {
294294
if (test.test(w)) {
@@ -306,6 +306,7 @@ public static <T extends ITreeNode<T>> T findFirst(T parent, @NotNull Predicate<
306306
* @param test test which the widget has to pass
307307
* @return the first matching widget
308308
*/
309+
@Nullable
309310
@SuppressWarnings("unchecked")
310311
public static <T extends ITreeNode<T>, R extends ITreeNode<T>> R findFirst(T parent, Class<R> type, @Nullable Predicate<R> test) {
311312
return foreachChildWithResult(parent, t -> {
@@ -318,15 +319,15 @@ public static <T extends ITreeNode<T>, R extends ITreeNode<T>> R findFirst(T par
318319
}, true);
319320
}
320321

322+
@Nullable
321323
public static <T extends ITreeNode<T>> T findParent(T parent, Predicate<T> filter) {
322-
if (parent == null) return null;
323-
while (!(parent instanceof ModularPanel)) {
324+
while (parent != null) {
324325
if (filter.test(parent)) {
325326
return parent;
326327
}
327328
parent = parent.getParent();
328329
}
329-
return filter.test(parent) ? parent : null;
330+
return null;
330331
}
331332

332333
@Nullable

0 commit comments

Comments
 (0)