基于Essentials插件的插件二次开发(第二期)
-
本帖最后由 noname 于 2014-8-1 11:55 编辑
这期主要讲的就是Essentials插件和你开发的插件之间的加载顺序,在调用ESS的接口的时候,如果在没有加载ESS插件前调用的话,服务端是会报错的。而且这就是关于优先级的问题了。
this.sm = getServer().getServicesManager();
this.sm.register(Economy.class, perms, this, priority);
上面2段代码为注册类, Economy econ = (Economy) hookClass.getConstructor(new Class[]{Plugin.class}).newInstance(new Object[]{this});Economy.class是一个自己写的一个抽象类。而hookClass是一个继承了Economy的类。perms为优先级。其中有ServicePriority.Low,ServicePriority.High, ServicePriority.Highest,ServicePriority.Normal,ServicePriority.Lowest。剩下的就是注册监听器来实现加载了。
可以参考下面的代码:
public class EconomyServerListener
implements Listener
{
Economy_Essentials economy = null;
public EconomyServerListener(Economy_Essentials economy) {
this.economy = economy;
}
@EventHandler(priority=EventPriority.MONITOR)
public void onPluginEnable(PluginEnableEvent event) {
if (this.economy.ess == null) {
Plugin essentials = event.getPlugin(); if (essentials.getDescription().getName().equals("Essentials")) {
this.economy.ess = ((Essentials)essentials);
Economy_Essentials.log.info(String.format("[%s] %s hooked.", new Object[] { Economy_Essentials.this.plugin.getDescription().getName(), "Essentials Economy" }));
}
}
} @EventHandler(priority=EventPriority.MONITOR)
public void onPluginDisable(PluginDisableEvent event) {
if ((this.economy.ess != null) &&
(event.getPlugin().getDescription().getName().equals("Essentials"))) {
this.economy.ess = null;
Economy_Essentials.log.info(String.format("[%s] %s unhooked.", new Object[] { Economy_Essentials.this.plugin.getDescription().getName(), "Essentials Economy" }));
}
}
} -
-
-
-
-
-
-
-
-
-
-
-
gggggjfdsa
-
近期可能用得到
-
感谢你
-
-
-
这什么玩意,看不懂
-
好人~
-
