Broken plugins no longer crash the server

By: Dinnerbone <dinnerbone@dinnerbone.com>
This commit is contained in:
Bukkit/Spigot 2010-12-30 18:54:04 +00:00
parent 9e1f814646
commit 5ca171b422
3 changed files with 15 additions and 1 deletions

View file

@ -6,6 +6,7 @@ import org.bukkit.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerEvent;
import org.bukkit.event.player.PlayerListener;
import org.bukkit.event.player.PlayerMoveEvent;
/**
* Handle events for all Player related events
@ -55,4 +56,12 @@ public class SamplePlayerListener extends PlayerListener {
event.setCancelled(true);
}
}
@Override
public void onPlayerMove(PlayerMoveEvent event) {
Location from = event.getFrom();
Location to = event.getTo();
System.out.println(String.format("From %2$f,%2$f,%2$f to %2$f,%2$f,%2$f", from.getX(), from.getY(), from.getZ(), to.getX(), to.getY(), to.getZ()));
}
}

View file

@ -37,5 +37,6 @@ public class SamplePlugin extends JavaPlugin {
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_JOIN, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_QUIT, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_COMMAND, playerListener, Priority.Normal, this);
getServer().getPluginManager().registerEvent(Event.Type.PLAYER_MOVE, playerListener, Priority.Normal, this);
}
}

View file

@ -176,7 +176,11 @@ public final class SimplePluginManager implements PluginManager {
PluginLoader loader = plugin.getPluginLoader();
if (plugin.isEnabled()) {
loader.callEvent(registration, event);
try {
loader.callEvent(registration, event);
} catch (Throwable ex) {
Logger.getLogger(SimplePluginManager.class.getName()).log(Level.SEVERE, "Could not pass event " + event.getType() + " to " + plugin.getDescription().getName(), ex);
}
}
}
}