• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java EventListener类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.spongepowered.api.event.EventListener的典型用法代码示例。如果您正苦于以下问题:Java EventListener类的具体用法?Java EventListener怎么用?Java EventListener使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



EventListener类属于org.spongepowered.api.event包,在下文中一共展示了EventListener类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getEventClass

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T extends Event> Class<T> getEventClass(EventListener<? super T> listener) {
    Class<? extends EventListener> listenerClass = listener.getClass();
    // We can't just do this:
    // Method handleMethod = listenerClass.getMethod(EVENT_LISTENER_HANDLE_METHOD_NAME, Event.class);
    // so we do this:
    Method[] methods = listenerClass.getMethods();
    List<Method> handleMethods = Arrays.asList(methods).stream()
            .filter(m -> !m.getDeclaringClass().equals(EventListener.class))
            .filter(m -> m.getName().equals(EVENT_LISTENER_HANDLE_METHOD_NAME))
            .collect(Collectors.toList());
    if (handleMethods.size() == 2) {
        if (handleMethods.get(0).getParameterTypes()[0].equals(Event.class)) {
            return (Class<T>) handleMethods.get(1).getParameterTypes()[0];
        } else {
            return (Class<T>) handleMethods.get(0).getParameterTypes()[0];
        }
    } if (handleMethods.size() == 1) {
        return (Class<T>) handleMethods.get(0).getParameterTypes()[0];
    } else if (handleMethods.size() > 2) {
        throw new IllegalStateException("Finding best matching Event not yet implemented: " + handleMethods);
    } else {
        throw new IllegalArgumentException("Failed to obtain 'handle' Method from listener: " + listener);
    }
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:26,代码来源:EventListenerUtil.java


示例2: start

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
    // System.out.println("STDOUT started!");
    LOG.info("starting and registering command..");
    try {
        // new CommandsSetUp().register();
        // TODO remove this when switching to annotation-based declarative services..
        context.registerService(CommandRegistration.class, new HelloWorldCommand(), null);
        // TODO un-comment when https://github.com/SpongePowered/SpongeCommon/pull/1090 is merged
        // context.registerService(Listeners.class, new ExampleListeners(), null);
        context.registerService(EventListener.class, new ExampleEventListener(), null);
    } catch (Throwable t) {
        // we MUST catch and log, because Felix itself does not, and this gets lost..
        LOG.error("boum", t);
        // we rethrow, to fail the Bundle start
        throw t;
    }
    LOG.info("started!");
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:20,代码来源:Activator.java


示例3: start

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
    ServiceReference<BundleManager> ref = context.getServiceReference(BundleManager.class);
    if (ref != null) {
        bundleManager = context.getService(ref);
        PlayerJoinListener playerJoinListener = new PlayerJoinListener(bundleManager);
        context.registerService(EventListener.class, playerJoinListener, null);
    } else {
        throw new IllegalStateException("SourceInstallService not found (yet, change start order; DS SCR later)");
    }
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:12,代码来源:Activator.java


示例4: start

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
public void start(BundleContext bundleContext, PluginContainer pluginContainer) {
    listenersTracker = CommandRegistrationTrackerCustomizer.setUp(bundleContext, Listeners.class,
            new ListenersTrackerCustomizer(bundleContext, pluginContainer));
    eventListenerTracker = CommandRegistrationTrackerCustomizer.setUp(bundleContext, EventListener.class,
            new EventListenerTrackerCustomizer(bundleContext, pluginContainer));
    commandRegistrationTracker = CommandRegistrationTrackerCustomizer.setUp(bundleContext, CommandRegistration.class,
            new CommandRegistrationTrackerCustomizer(bundleContext, pluginContainer));
    LOG.info("started tracking Minecraft services for CommandRegistration, EventListener & Listeners");
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:10,代码来源:ApiImplBootstrap.java


示例5: getRegistration

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
// protected Optional<EventListener<? extends Event>> getRegistration(EventListener<? extends Event> service) {
protected Optional<EventListener> getRegistration(EventListener service) {
    Class eventClass = EventListenerUtil.getEventClass(service);
    Sponge.getEventManager().registerListener(pluginContainer, eventClass, service);
    LOG.info("EventListener registered for event class {} : {}", eventClass.getName(), service);
    return Optional.of(service);
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:9,代码来源:EventListenerTrackerCustomizer.java


示例6: start

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
public void start(BundleContext context) throws Exception {
    // TODO make directory of File("news.txt") more configurable ...
    NewsRepository newsRepository = new FileNewsRepository(new File("config/news/news.txt"),
            TextSerializers.JSON, Sponge.getServer(),
            Sponge.getServiceManager().provideUnchecked(UserStorageService.class));
    NewsService newsService = new NewsServiceImpl(newsRepository);
    context.registerService(EventListener.class, new PlayerJoinListener(newsRepository), null);
    context.registerService(CommandRegistration.class, new NewsCommand(newsService), null);
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:11,代码来源:Activator.java


示例7: slotFilter

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
private <T extends ClickInventoryEvent> EventListener<T> slotFilter(Predicate<Slot> filter,
        BiConsumer<SlotTransaction, Transaction<ItemStackSnapshot>> fn) {
    return event -> {
        Transaction<ItemStackSnapshot> cursor = event.getCursorTransaction();
        this.wasChange = false;
        this.ignoreChange = true;
        for (SlotTransaction tr : event.getTransactions()) {
            if (!tr.isValid() || !filter.test(tr.getSlot())) {
                continue;
            }
            // Ignore the crap where output slot changes even when not clicking on it
            if (ImplUtil.slotNumber(tr.getSlot()) == 0) {
                if (!tr.getOriginal().createStack().equalTo(cursor.getFinal().createStack())) {
                    System.out.println("ignore");
                    continue;
                }
            }
            fn.accept(tr, cursor);
            // cursor = new Transaction<>(cursor.getCustom().orElse(cursor.getOriginal()),
            // cursor.getFinal());
        }
        if (this.wasChange) {
            onGridChange();
        }
        this.ignoreChange = false;
        this.wasChange = false;
        checkZero();
    };
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:30,代码来源:TileAutoCrafting.java


示例8: registerEvent

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
public <E extends DataHolder> void registerEvent(Class<E> holderFilter,
        EventListener<ChangeDataHolderEvent.ValueChange> listener) {
    checkNotNull(holderFilter, "holderFilter");
    checkNotNull(listener, "listener");
    final KeyEventListener keyEventListener = new KeyEventListener(listener, holderFilter::isInstance, this);
    final PluginContainer plugin = CauseStack.current().first(PluginContainer.class).get();
    final RegisteredListener<ChangeDataHolderEvent.ValueChange> registeredListener = Lantern.getGame().getEventManager().register(
            plugin, valueChangeEventTypeToken, Order.DEFAULT, keyEventListener);
    this.listeners.add(registeredListener);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:12,代码来源:LanternKey.java


示例9: register

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
public <T extends Event> RegisteredListener<T> register(Object plugin, TypeToken<T> eventType, Order order, EventListener<? super T> listener) {
    final PluginContainer pluginContainer = checkPlugin(plugin, "plugin");
    checkNotNull(eventType, "eventType");
    checkNotNull(order, "order");
    checkNotNull(listener, "listener");
    registerListenerInstance(pluginContainer, listener);
    final RegisteredListener<T> registeredListener = createRegistration(pluginContainer, eventType, order, listener);
    register(Collections.singletonList(registeredListener));
    return registeredListener;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:11,代码来源:LanternEventManager.java


示例10: createRegistration

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
private static <T extends Event> RegisteredListener<T> createRegistration(PluginContainer plugin, TypeToken<T> eventType,
        Order order, EventListener<? super T> handler) {
    TypeToken<?> genericType = null;
    if (GenericEvent.class.isAssignableFrom(eventType.getRawType())) {
        genericType = eventType.resolveType(GENERIC_EVENT_TYPE);
    }
    return new RegisteredListener(plugin, new EventType(eventType.getRawType(), genericType), order, handler);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:9,代码来源:LanternEventManager.java


示例11: removeRegistration

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
// protected void removeRegistration(EventListener<? extends Event> registration) {
protected void removeRegistration(EventListener registration) {
    Sponge.getEventManager().unregisterListeners(registration);
}
 
开发者ID:vorburger,项目名称:ch.vorburger.minecraft.osgi,代码行数:6,代码来源:EventListenerTrackerCustomizer.java


示例12: on

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T extends TargetInventoryEvent> void on(Class<T> eventClass, EventListener<T> handler) {
    this.handlers.put(eventClass, (EventListener<Event>) (Object) handler);
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:5,代码来源:InventoryTracker.java


示例13: KeyEventListener

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
KeyEventListener(EventListener<ChangeDataHolderEvent.ValueChange> listener,
        Predicate<DataHolder> dataHolderPredicate, Key<?> key) {
    this.dataHolderPredicate = dataHolderPredicate;
    this.listener = listener;
    this.key = key;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:KeyEventListener.java


示例14: RegisteredListener

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
RegisteredListener(PluginContainer plugin, EventType<T> eventType, Order order, EventListener<? super T> handler) {
    this.plugin = plugin;
    this.eventType = eventType;
    this.order = order;
    this.handler = handler;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:RegisteredListener.java


示例15: getHandler

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
public EventListener<? super T> getHandler() {
    return this.handler;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:4,代码来源:RegisteredListener.java


示例16: registerListener

import org.spongepowered.api.event.EventListener; //导入依赖的package包/类
@Override
public <T extends Event> void registerListener(Object plugin, Class<T> eventClass, Order order, boolean beforeModifications,
        EventListener<? super T> listener) {
    // Ignore the "beforeModifications" property, this is only used in combination with mods
    registerListener(plugin, eventClass, order, listener);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:7,代码来源:LanternEventManager.java



注:本文中的org.spongepowered.api.event.EventListener类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ListenableFutureAdapter类代码示例发布时间:2022-05-23
下一篇:
Java ServiceBuilder类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap