Ejemplo n.º 1
0
  public boolean postBulk(
      Event spongeEvent, Class<? extends net.minecraftforge.fml.common.eventhandler.Event> clazz) {
    RegisteredListener.Cache listenerCache = getHandlerCache(spongeEvent);
    // Fire events to plugins before modifications
    for (Order order : Order.values()) {
      post(spongeEvent, listenerCache.getListenersByOrder(order), true, false);
    }

    StaticMixinHelper.processingInternalForgeEvent = true;
    spongeEvent = SpongeForgeEventFactory.callForgeEvent(spongeEvent, clazz);
    StaticMixinHelper.processingInternalForgeEvent = false;

    // Fire events to plugins after modifications (default)
    for (Order order : Order.values()) {
      post(spongeEvent, listenerCache.getListenersByOrder(order), false, false);
    }

    return spongeEvent instanceof Cancellable && ((Cancellable) spongeEvent).isCancelled();
  }
Ejemplo n.º 2
0
  @Override
  public boolean post(Event spongeEvent, boolean allowClientThread) {
    if (!allowClientThread & SpongeMod.instance.isClientThread()) {
      return false;
    }

    if (spongeEvent.getClass().getInterfaces().length > 0) {
      Class<? extends net.minecraftforge.fml.common.eventhandler.Event> clazz =
          this.eventMappings.get(spongeEvent.getClass().getInterfaces()[0]);
      if (clazz == null) {
        clazz = eventBulkMappings.get(spongeEvent.getClass().getInterfaces()[0]);
        if (clazz != null) {
          return postBulk(spongeEvent, clazz);
        }
      } else {
        StaticMixinHelper.processingInternalForgeEvent = true;
        net.minecraftforge.fml.common.eventhandler.Event forgeEvent =
            SpongeForgeEventFactory.findAndCreateForgeEvent(spongeEvent, clazz);
        StaticMixinHelper.processingInternalForgeEvent = false;
        if (forgeEvent != null) {
          // Avoid separate mappings for events defined as inner classes
          Class<?> enclosingClass = forgeEvent.getClass().getEnclosingClass();
          EventBus bus =
              this.busMappings.get(enclosingClass == null ? forgeEvent.getClass() : enclosingClass);
          if (bus == null) {
            bus = MinecraftForge.EVENT_BUS;
          }

          return post(
              spongeEvent,
              forgeEvent,
              forgeEvent.getListenerList().getListeners(((IMixinEventBus) bus).getBusID()));
        }
      }
    }
    return post(
        spongeEvent,
        getHandlerCache(spongeEvent).getListeners(),
        false,
        true); // no checking for modifications required
  }