下面列出了怎么用org.bukkit.plugin.IllegalPluginAccessException的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Queued database manager. Use queue to solve run SQL make server lagg issue.
*
* @param plugin plugin main class
* @param db database
*/
public DatabaseManager(@NotNull QuickShop plugin, @NotNull Database db) {
this.plugin = plugin;
this.warningSender = new WarningSender(plugin, 600000);
this.database = db;
this.useQueue = plugin.getConfig().getBoolean("database.queue");
if (!useQueue) {
return;
}
try {
task =
new BukkitRunnable() {
@Override
public void run() {
plugin.getDatabaseManager().runTask();
}
}.runTaskTimerAsynchronously(plugin, 1, plugin.getConfig().getLong("database.queue-commit-interval") * 20);
} catch (IllegalPluginAccessException e) {
Util.debugLog("Plugin is disabled but trying create database task, move to Main Thread...");
plugin.getDatabaseManager().runTask();
}
}
private Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) {
try {
clazz.getDeclaredMethod("getHandlerList");
return clazz;
} catch (NoSuchMethodException e) {
if ((clazz.getSuperclass() != null)
&& (!clazz.getSuperclass().equals(Event.class))
&& (Event.class.isAssignableFrom(clazz.getSuperclass()))) {
return getRegistrationClass(clazz.getSuperclass().asSubclass(
Event.class));
}
}
throw new IllegalPluginAccessException(
"Unable to find handler list for event " + clazz.getName());
}
static HandlerList getEventListeners(Class<? extends Event> type) {
try {
Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList");
method.setAccessible(true);
return (HandlerList) method.invoke(null);
} catch (Exception e) {
throw new IllegalPluginAccessException(e.toString());
}
}
static Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) {
try {
clazz.getDeclaredMethod("getHandlerList");
return clazz;
} catch (NoSuchMethodException e) {
if (clazz.getSuperclass() != null
&& !clazz.getSuperclass().equals(Event.class)
&& Event.class.isAssignableFrom(clazz.getSuperclass())) {
return getRegistrationClass(clazz.getSuperclass().asSubclass(Event.class));
} else {
throw new IllegalPluginAccessException(
"Unable to find handler list for event " + clazz.getName());
}
}
}
private static void validate(final Plugin plugin, final Object task) {
Validate.notNull(plugin, "Plugin cannot be null");
Validate.notNull(task, "Task cannot be null");
if (!plugin.isEnabled()) {
throw new IllegalPluginAccessException("Plugin attempted to register task while disabled");
}
}
private static Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) {
try {
clazz.getDeclaredMethod("getHandlerList");
return clazz;
} catch (NoSuchMethodException var2) {
if (clazz.getSuperclass() != null && !clazz.getSuperclass().equals(Event.class) && Event.class.isAssignableFrom(clazz.getSuperclass())) {
return getRegistrationClass(clazz.getSuperclass().asSubclass(Event.class));
} else {
throw new IllegalPluginAccessException("Unable to find handler list for event " + clazz.getName() + ".");
}
}
}
private HandlerList getEventListeners(Class<? extends Event> type) {
try {
Method method = getRegistrationClass(type).getDeclaredMethod("getHandlerList");
method.setAccessible(true);
return (HandlerList) method.invoke(null);
} catch (Exception e) {
throw new IllegalPluginAccessException(e.toString());
}
}
private static void validate(final Plugin plugin, final Object task) {
Validate.notNull(plugin, "Plugin cannot be null");
Validate.notNull(task, "Task cannot be null");
if (!plugin.isEnabled()) {
throw new IllegalPluginAccessException("Plugin attempted to register task while disabled");
}
}
/**
* Gets event listeners
*
* @param type event type
* @return handler list
*/
private HandlerList getEventListeners(Class<? extends Event> type) {
try {
Method method = Reflections.getMethod(type, "getHandlerList");
method.setAccessible(true);
return (HandlerList) method.invoke(null);
}
catch(Exception e) {
throw new IllegalPluginAccessException(e.toString());
}
}
/**
* Gets registration class
*
* @param clazz event class
* @return the class
*/
private Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) {
try {
clazz.getDeclaredMethod("getHandlerList");
return clazz;
}
catch(NoSuchMethodException e) {
if((clazz.getSuperclass() != null) && (!clazz.getSuperclass().equals(Event.class)) && (Event.class.isAssignableFrom(clazz.getSuperclass()))) {
return getRegistrationClass(clazz.getSuperclass().asSubclass(Event.class));
}
}
throw new IllegalPluginAccessException("Unable to find handler list for event " + clazz.getName());
}
/**
* Instead of ending the conversation it saves it to the database, from
* where it will be resumed after the player logs in again.
*/
public void suspend() {
if (inOut == null) {
LogUtils.getLogger().log(Level.WARNING, "Conversation IO is not loaded, conversation will end for player "
+ PlayerConverter.getName(playerID));
list.remove(playerID);
HandlerList.unregisterAll(this);
return;
}
inOut.end();
// save the conversation to the database
String loc = location.getX() + ";" + location.getY() + ";" + location.getZ() + ";"
+ location.getWorld().getName();
plugin.getSaver().add(new Record(UpdateType.UPDATE_CONVERSATION,
new String[]{convID + " " + option + " " + loc, playerID}));
// End interceptor
if (interceptor != null) {
interceptor.end();
}
// delete conversation
list.remove(playerID);
HandlerList.unregisterAll(this);
try {
new BukkitRunnable() {
@Override
public void run() {
Bukkit.getServer().getPluginManager().callEvent(new PlayerConversationEndEvent(player, Conversation.this));
}
}.runTask(BetonQuest.getInstance());
} catch (IllegalPluginAccessException e) {
LogUtils.logThrowableIgnore(e);
}
}