本文整理汇总了Java中cn.nukkit.event.Event类的典型用法代码示例。如果您正苦于以下问题:Java Event类的具体用法?Java Event怎么用?Java Event使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Event类属于cn.nukkit.event包,在下文中一共展示了Event类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPluginEventTiming
import cn.nukkit.event.Event; //导入依赖的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: callEvent
import cn.nukkit.event.Event; //导入依赖的package包/类
public void callEvent(Event event) throws EventException {
if (event instanceof Cancellable) {
if (event.isCancelled() && isIgnoringCancelled()) {
return;
}
}
this.timing.startTiming();
executor.execute(listener, event);
this.timing.stopTiming();
}
示例3: registerEvent
import cn.nukkit.event.Event; //导入依赖的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: getEventListeners
import cn.nukkit.event.Event; //导入依赖的package包/类
private HandlerList getEventListeners(Class<? extends Event> type) throws IllegalAccessException {
try {
Method method = getRegistrationClass(type).getDeclaredMethod("getHandlers");
method.setAccessible(true);
return (HandlerList) method.invoke(null);
} catch (Exception e) {
throw new IllegalAccessException(Utils.getExceptionMessage(e));
}
}
示例5: getRegistrationClass
import cn.nukkit.event.Event; //导入依赖的package包/类
private Class<? extends Event> getRegistrationClass(Class<? extends Event> clazz) throws IllegalAccessException {
try {
clazz.getDeclaredMethod("getHandlers");
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 IllegalAccessException("Unable to find handler list for event " + clazz.getName() + ". Static getHandlers method required!");
}
}
}
示例6: StaticMethodHandleEventExecutor
import cn.nukkit.event.Event; //导入依赖的package包/类
public StaticMethodHandleEventExecutor(Class<? extends Event> eventClass, Method m) {
Preconditions.checkArgument(Modifier.isStatic(m.getModifiers()), "Not a static method: %s", m);
this.eventClass = eventClass;
try {
m.setAccessible(true);
this.handle = MethodHandles.lookup().unreflect(m);
} catch (IllegalAccessException e) {
throw new AssertionError("Unable to set accessible", e);
}
}
示例7: execute
import cn.nukkit.event.Event; //导入依赖的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);
}
}
示例8: MethodHandleEventExecutor
import cn.nukkit.event.Event; //导入依赖的package包/类
public MethodHandleEventExecutor(Class<? extends Event> eventClass, Method m) {
this.eventClass = eventClass;
try {
m.setAccessible(true);
this.handle = MethodHandles.lookup().unreflect(m);
} catch (IllegalAccessException e) {
throw new AssertionError("Unable to set accessible", e);
}
}
示例9: execute
import cn.nukkit.event.Event; //导入依赖的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);
}
}
示例10: execute
import cn.nukkit.event.Event; //导入依赖的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);
}
}
示例11: registerEvents
import cn.nukkit.event.Event; //导入依赖的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());
}
}
示例12: callEvent
import cn.nukkit.event.Event; //导入依赖的package包/类
public boolean callEvent(Event event) {
plugin.getServer().getPluginManager().callEvent(event);
return !(event instanceof Cancellable) || !event.isCancelled();
}
示例13: kill
import cn.nukkit.event.Event; //导入依赖的package包/类
private void kill(Entity entity, Event event) {
if (event instanceof Cancellable) {
event.setCancelled(true);
}
entity.kill();
}
示例14: execute
import cn.nukkit.event.Event; //导入依赖的package包/类
void execute(Listener listener, Event event) throws EventException;