Skip to content

Commit a8d481a

Browse files
authored
Merge pull request #583 from zyxkad/patch-3
Fix NullPointerException when server ticking
2 parents 8ecadb3 + 7891e93 commit a8d481a

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/java/de/srendi/advancedperipherals/common/util/ServerWorker.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,28 @@
55
import net.minecraftforge.eventbus.api.SubscribeEvent;
66
import net.minecraftforge.fml.common.Mod;
77

8-
import java.util.ArrayDeque;
98
import java.util.Queue;
9+
import java.util.concurrent.ConcurrentLinkedQueue;
1010

1111
@Mod.EventBusSubscriber(modid = AdvancedPeripherals.MOD_ID)
1212
public class ServerWorker {
1313

14-
private static final Queue<Runnable> callQueue = new ArrayDeque<>();
14+
private static final Queue<Runnable> callQueue = new ConcurrentLinkedQueue<>();
1515

1616
public static void add(final Runnable call) {
17-
callQueue.add(call);
17+
if (call != null) {
18+
callQueue.add(call);
19+
}
1820
}
1921

2022
@SubscribeEvent
2123
public static void serverTick(TickEvent.ServerTickEvent event) {
2224
if (event.phase == TickEvent.Phase.END) {
23-
while (!callQueue.isEmpty()) {
25+
while (true) {
2426
final Runnable runnable = callQueue.poll();
27+
if (runnable == null) {
28+
return;
29+
}
2530
AdvancedPeripherals.debug("Running queued server worker call: " + runnable);
2631
runnable.run();
2732
}

0 commit comments

Comments
 (0)