Ejemplo n.º 1
0
  @Listener
  public void onSpawnEntityEvent(SpawnEntityEvent event, @Root SpawnCause cause) {
    WorldSettings settings = WorldSettings.get(event.getTargetWorld());

    if (!settings.isVanillaSpawnerAllowed() && cause.getType().equals(SpawnTypes.MOB_SPAWNER)) {
      return;
    } else if (!settings.isModSpawnerAllowed() && cause.getType().equals(SpawnTypes.CUSTOM)) {
      return;
    } else if (!settings.isPluginSpawnerAllowed() && cause.getType().equals(SpawnTypes.PLUGIN)) {
      return;
    } else if (!settings.isEggSpawnerAllowed() && cause.getType().equals(SpawnTypes.SPAWN_EGG)) {
      return;
    }

    for (Entity entity : event.getEntities()) {
      entity.offer(Sponge.getDataManager().getManipulatorBuilder(MoneyData.class).get().create());
    }
  }
  public static SpawnEntityEvent callEntityJoinWorldEvent(Event event) {
    if (!(event instanceof SpawnEntityEvent)) {
      throw new IllegalArgumentException("Event is not a valiud SpawnEntityEvent.");
    }

    SpawnEntityEvent spongeEvent = (SpawnEntityEvent) event;
    Iterator<org.spongepowered.api.entity.Entity> iterator = spongeEvent.getEntities().iterator();
    while (iterator.hasNext()) {
      org.spongepowered.api.entity.Entity entity = iterator.next();
      EntityJoinWorldEvent forgeEvent =
          new EntityJoinWorldEvent(
              (net.minecraft.entity.Entity) entity,
              (net.minecraft.world.World) entity.getLocation().getExtent());

      ((IMixinEventBus) MinecraftForge.EVENT_BUS).post(forgeEvent, true);
      if (forgeEvent.isCanceled()) {
        iterator.remove();
      }
    }
    return spongeEvent;
  }