From 8232518abbe8adffd11e0892dfaeb8f16b3916d3 Mon Sep 17 00:00:00 2001 From: Shevchik Date: Sun, 23 Mar 2014 01:49:12 +0400 Subject: [PATCH] Properly disable plugin, throw custom exception when plugin is incompatible --- src/com/cnaude/chairs/core/Chairs.java | 13 +++++++------ src/com/cnaude/chairs/vehiclearrow/NMSAccess.java | 4 ++-- .../chairs/vehiclearrow/NMSAccessException.java | 11 +++++++++++ 3 files changed, 20 insertions(+), 8 deletions(-) create mode 100644 src/com/cnaude/chairs/vehiclearrow/NMSAccessException.java diff --git a/src/com/cnaude/chairs/core/Chairs.java b/src/com/cnaude/chairs/core/Chairs.java index a3cbd0f..8507c6f 100644 --- a/src/com/cnaude/chairs/core/Chairs.java +++ b/src/com/cnaude/chairs/core/Chairs.java @@ -64,7 +64,6 @@ public class Chairs extends JavaPlugin { nmsaccess.setupVehicleArrow(); } catch (Exception e) { e.printStackTrace(); - log.severe("Failed to generate VehicleArrow class, exiting"); getServer().getPluginManager().disablePlugin(this); return; } @@ -91,11 +90,13 @@ public class Chairs extends JavaPlugin { @Override public void onDisable() { - for (Player player : getServer().getOnlinePlayers()) { - if (psitdata.isSitting(player)) { - PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); - Bukkit.getPluginManager().callEvent(playerunsitevent); - psitdata.unsitPlayerNow(player); + if (psitdata != null) { + for (Player player : getServer().getOnlinePlayers()) { + if (psitdata.isSitting(player)) { + PlayerChairUnsitEvent playerunsitevent = new PlayerChairUnsitEvent(player, false); + Bukkit.getPluginManager().callEvent(playerunsitevent); + psitdata.unsitPlayerNow(player); + } } } if (ignoreList != null) { diff --git a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java index 217f441..bdb9562 100644 --- a/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java +++ b/src/com/cnaude/chairs/vehiclearrow/NMSAccess.java @@ -12,7 +12,7 @@ public class NMSAccess { private Class nmsArrowClass; - public void setupVehicleArrow() throws Exception { + public void setupVehicleArrow() throws NMSAccessException, ClassNotFoundException { String pkgname = getClass().getPackage().getName(); String packageName = Bukkit.getServer().getClass().getPackage().getName(); String nmspackageversion = packageName.substring(packageName.lastIndexOf('.') + 1); @@ -26,7 +26,7 @@ public class NMSAccess { return; } } - throw new Exception("ChairsReloaded is not compatible with your server version"); + throw new NMSAccessException("ChairsReloaded is not compatible with your server version"); } public Arrow spawnArrow(Location location) throws NoSuchMethodException, SecurityException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { diff --git a/src/com/cnaude/chairs/vehiclearrow/NMSAccessException.java b/src/com/cnaude/chairs/vehiclearrow/NMSAccessException.java new file mode 100644 index 0000000..defaa99 --- /dev/null +++ b/src/com/cnaude/chairs/vehiclearrow/NMSAccessException.java @@ -0,0 +1,11 @@ +package com.cnaude.chairs.vehiclearrow; + +public class NMSAccessException extends Exception { + + private static final long serialVersionUID = -839103433400420225L; + + public NMSAccessException(String message) { + super(message); + } + +}