當前位置: 首頁>>代碼示例>>Java>>正文


Java Listener類代碼示例

本文整理匯總了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);
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:8,代碼來源:Timings.java

示例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;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:9,代碼來源:RegisteredListener.java

示例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);
    }
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:13,代碼來源:PluginManager.java

示例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);
    }
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:10,代碼來源:StaticMethodHandleEventExecutor.java

示例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);
    }
}
 
開發者ID:CoreXDevelopment,項目名稱:CoreX,代碼行數:10,代碼來源:MethodHandleEventExecutor.java

示例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);
    }
}
 
開發者ID:Creeperface01,項目名稱:NukkitGT,代碼行數:11,代碼來源:MethodEventExecutor.java

示例7: getListener

import cn.nukkit.event.Listener; //導入依賴的package包/類
public Listener getListener() {
    return listener;
}
 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:4,代碼來源:RegisteredListener.java

示例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());
    }
}
 
開發者ID:JupiterDevelopmentTeam,項目名稱:Jupiter,代碼行數:46,代碼來源:PluginManager.java

示例9: execute

import cn.nukkit.event.Listener; //導入依賴的package包/類
void execute(Listener listener, Event event) throws EventException; 
開發者ID:Rsplwe,項目名稱:Nukkit-Java9,代碼行數:2,代碼來源:EventExecutor.java


注:本文中的cn.nukkit.event.Listener類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。