本文整理匯總了Java中cn.nukkit.event.Listener類的典型用法代碼示例。如果您正苦於以下問題:Java Listener類的具體用法?Java Listener怎麽用?Java Listener使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Listener類屬於cn.nukkit.event包,在下文中一共展示了Listener類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getPluginEventTiming
import cn.nukkit.event.Listener; //導入依賴的package包/類
public static Timing getPluginEventTiming(Class<? extends Event> event, Listener listener, EventExecutor executor, Plugin plugin) {
Timing group = TimingsManager.getTiming(plugin.getName(), "Combined Total", pluginEventTimer);
return TimingsManager.getTiming(plugin.getName(), "Event: " + listener.getClass().getName() + "."
+ (executor instanceof MethodEventExecutor ? ((MethodEventExecutor) executor).getMethod().getName() : "???")
+ " (" + event.getSimpleName() + ")", group);
}
示例2: RegisteredListener
import cn.nukkit.event.Listener; //導入依賴的package包/類
public RegisteredListener(Listener listener, EventExecutor executor, EventPriority priority, Plugin plugin, boolean ignoreCancelled, Timing timing) {
this.listener = listener;
this.priority = priority;
this.plugin = plugin;
this.executor = executor;
this.ignoreCancelled = ignoreCancelled;
this.timing = timing;
}
示例3: registerEvent
import cn.nukkit.event.Listener; //導入依賴的package包/類
public void registerEvent(Class<? extends Event> event, Listener listener, EventPriority priority, EventExecutor executor, Plugin plugin, boolean ignoreCancelled) throws PluginException {
if (!plugin.isEnabled()) {
throw new PluginException("Plugin attempted to register " + event + " while not enabled");
}
try {
Timing timing = Timings.getPluginEventTiming(event, listener, executor, plugin);
this.getEventListeners(event).register(new RegisteredListener(listener, executor, priority, plugin, ignoreCancelled, timing));
} catch (IllegalAccessException e) {
Server.getInstance().getLogger().logException(e);
}
}
示例4: execute
import cn.nukkit.event.Listener; //導入依賴的package包/類
@Override
public void execute(Listener listener, Event event) throws EventException {
if (!eventClass.isInstance(event)) return;
try {
handle.invoke(event);
} catch (Throwable t) {
throw new EventException(t);
}
}
示例5: execute
import cn.nukkit.event.Listener; //導入依賴的package包/類
@Override
public void execute(Listener listener, Event event) throws EventException {
if (!eventClass.isInstance(event)) return;
try {
handle.invoke(listener, event);
} catch (Throwable t) {
throw new EventException(t);
}
}
示例6: execute
import cn.nukkit.event.Listener; //導入依賴的package包/類
@Override
public void execute(Listener listener, Event event) throws EventException {
try {
method.invoke(listener, event);
} catch (InvocationTargetException ex) {
throw new EventException(ex.getCause());
} catch (Throwable t) {
throw new EventException(t);
}
}
示例7: getListener
import cn.nukkit.event.Listener; //導入依賴的package包/類
public Listener getListener() {
return listener;
}
示例8: registerEvents
import cn.nukkit.event.Listener; //導入依賴的package包/類
public void registerEvents(Listener listener, Plugin plugin) {
if (!plugin.isEnabled()) {
throw new PluginException("Plugin attempted to register " + listener.getClass().getName() + " while not enabled");
}
Set<Method> methods;
try {
Method[] publicMethods = listener.getClass().getMethods();
Method[] privateMethods = listener.getClass().getDeclaredMethods();
methods = new HashSet<>(publicMethods.length + privateMethods.length, 1.0f);
Collections.addAll(methods, publicMethods);
Collections.addAll(methods, privateMethods);
} catch (NoClassDefFoundError e) {
plugin.getLogger().error("Plugin " + plugin.getDescription().getFullName() + " has failed to register events for " + listener.getClass() + " because " + e.getMessage() + " does not exist.");
return;
}
for (final Method method : methods) {
final EventHandler eh = method.getAnnotation(EventHandler.class);
if (eh == null) continue;
if (method.isBridge() || method.isSynthetic()) {
continue;
}
final Class<?> checkClass;
if (method.getParameterTypes().length != 1 || !Event.class.isAssignableFrom(checkClass = method.getParameterTypes()[0])) {
plugin.getLogger().error(plugin.getDescription().getFullName() + " attempted to register an invalid EventHandler method signature \"" + method.toGenericString() + "\" in " + listener.getClass());
continue;
}
final Class<? extends Event> eventClass = checkClass.asSubclass(Event.class);
method.setAccessible(true);
for (Class<?> clazz = eventClass; Event.class.isAssignableFrom(clazz); clazz = clazz.getSuperclass()) {
// This loop checks for extending deprecated events
if (clazz.getAnnotation(Deprecated.class) != null) {
if (Boolean.valueOf(String.valueOf(this.server.getConfig("settings.deprecated-verbpse", true)))) {
this.server.getLogger().warning(this.server.getLanguage().translateString("nukkit.plugin.deprecatedEvent", plugin.getName(), clazz.getName(), listener.getClass().getName() + "." + method.getName() + "()"));
}
break;
}
}
this.registerEvent(eventClass, listener, eh.priority(), new MethodEventExecutor(method), plugin, eh.ignoreCancelled());
}
}
示例9: execute
import cn.nukkit.event.Listener; //導入依賴的package包/類
void execute(Listener listener, Event event) throws EventException;