Skip to content

Commit 9e45fc4

Browse files
committed
Fix potion effect removing on death (#1374)
1 parent 972207b commit 9e45fc4

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

arclight-common/src/main/java/io/izzel/arclight/common/util/IteratorUtil.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package io.izzel.arclight.common.util;
22

33
import java.util.Iterator;
4+
import java.util.NoSuchElementException;
45
import java.util.function.Predicate;
56

67
public class IteratorUtil {
@@ -14,30 +15,40 @@ private static class FilterIterator<T> implements Iterator<T> {
1415
private final Iterator<T> iterator;
1516
private final Predicate<T> predicate;
1617

18+
private boolean nextComputed = false;
1719
private boolean hasNext = false;
1820
private T next;
1921

2022
private FilterIterator(Iterator<T> iterator, Predicate<T> predicate) {
2123
this.iterator = iterator;
2224
this.predicate = predicate;
23-
this.computeNext();
2425
}
2526

2627
@Override
2728
public boolean hasNext() {
29+
if (!nextComputed) {
30+
this.computeNext();
31+
}
2832
return hasNext;
2933
}
3034

3135
@Override
3236
public T next() {
37+
if (!nextComputed) {
38+
this.computeNext();
39+
}
40+
if (!hasNext) {
41+
throw new NoSuchElementException();
42+
}
3343
try {
3444
return this.next;
3545
} finally {
36-
computeNext();
46+
nextComputed = false;
3747
}
3848
}
3949

4050
private void computeNext() {
51+
nextComputed = true;
4152
while (iterator.hasNext()) {
4253
T next = iterator.next();
4354
if (predicate.test(next)) {

0 commit comments

Comments
 (0)