summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsk89q <the.sk89q@gmail.com>2011-04-18 23:47:49 -0700
committersk89q <the.sk89q@gmail.com>2011-04-18 23:48:16 -0700
commita450dcbb83e1c0172634c4cc6928d40641dedc85 (patch)
treec94b85400ba4c49e037f65f90e7957eef8786a3c
parent0048b22e4411024d614f1c94d4c38b3919954d99 (diff)
downloadcraftbukkit-a450dcbb83e1c0172634c4cc6928d40641dedc85.tar
craftbukkit-a450dcbb83e1c0172634c4cc6928d40641dedc85.tar.gz
craftbukkit-a450dcbb83e1c0172634c4cc6928d40641dedc85.tar.lz
craftbukkit-a450dcbb83e1c0172634c4cc6928d40641dedc85.tar.xz
craftbukkit-a450dcbb83e1c0172634c4cc6928d40641dedc85.zip
Fixed CraftScheduler to catch exceptions thrown by tasks, rather than crash the server.
-rw-r--r--src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java25
1 files changed, 20 insertions, 5 deletions
diff --git a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
index 334013a1..664fe81d 100644
--- a/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
+++ b/src/main/java/org/bukkit/craftbukkit/scheduler/CraftScheduler.java
@@ -8,6 +8,8 @@ import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
+import java.util.logging.Level;
+import java.util.logging.Logger;
import org.bukkit.scheduler.BukkitScheduler;
import org.bukkit.plugin.Plugin;
@@ -17,12 +19,14 @@ import org.bukkit.craftbukkit.scheduler.CraftTask;
public class CraftScheduler implements BukkitScheduler, Runnable {
+ private static final Logger logger = Logger.getLogger("Minecraft");
+
private final CraftServer server;
private final CraftThreadManager craftThreadManager = new CraftThreadManager();
- private final LinkedList<Runnable> mainThreadQueue = new LinkedList<Runnable>();
- private final LinkedList<Runnable> syncedTasks = new LinkedList<Runnable>();
+ private final LinkedList<CraftTask> mainThreadQueue = new LinkedList<CraftTask>();
+ private final LinkedList<CraftTask> syncedTasks = new LinkedList<CraftTask>();
private final TreeMap<CraftTask,Boolean> schedulerQueue = new TreeMap<CraftTask,Boolean>();
@@ -93,7 +97,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
void processTask(CraftTask task) {
if (task.isSync()) {
- addToMainThreadQueue(task.getTask());
+ addToMainThreadQueue(task);
} else {
craftThreadManager.executeTask(task.getTask(), task.getOwner(), task.getIdNumber());
}
@@ -119,7 +123,18 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
mainThreadLock.unlock();
}
while(!syncedTasks.isEmpty()) {
- syncedTasks.removeFirst().run();
+ CraftTask task = syncedTasks.removeFirst();
+ try {
+ task.getTask().run();
+ } catch (Throwable t) {
+ // Bad plugin!
+ logger.log(Level.WARNING,
+ "Task of '" + task.getOwner().getDescription().getName()
+ + "' generated an exception", t);
+ synchronized (schedulerQueue) {
+ schedulerQueue.remove(task);
+ }
+ }
}
}
}
@@ -135,7 +150,7 @@ public class CraftScheduler implements BukkitScheduler, Runnable {
return tempTick;
}
- void addToMainThreadQueue(Runnable task) {
+ void addToMainThreadQueue(CraftTask task) {
mainThreadLock.lock();
try {
mainThreadQueue.addLast(task);