public static ChunkEvent.Load createChunkLoadEvent(Event event) {
    if (!(event instanceof LoadChunkEvent)) {
      throw new IllegalArgumentException("Event is not a valid LoadChunkEvent.");
    }

    LoadChunkEvent spongeEvent = (LoadChunkEvent) event;
    ChunkEvent.Load forgeEvent = new ChunkEvent.Load(((Chunk) spongeEvent.getTargetChunk()));
    return forgeEvent;
  }
Exemplo n.º 2
0
  @Listener
  public void onChunkLoad(LoadChunkEvent event) {
    Chunk chunk = event.getTargetChunk();
    UUID worldId = chunk.getWorld().getUniqueId();
    Vector3i position = chunk.getPosition();

    WorldFallbackContext context = worldContexts.get(worldId);
    if (context == null) {
      IllegalStateException exception =
          new IllegalStateException(
              "Failed to find the world context for the world " + chunk.getWorld().getName());
      logger.error(
          "An error happened while loading the chunk " + chunk.getWorld().getName() + position,
          exception);
      Sponge.getServer().shutdown();
      throw exception;
    }

    try {
      dataStorage
          .loadChunk(worldId, position)
          .ifPresent(
              claimedChunk -> {
                logger.info("Chunk loaded: " + chunk.getWorld().getName() + position);
                getChunkMap(worldId)
                    .orElseThrow(IllegalStateException::new)
                    .put(position, claimedChunk);
              });
    } catch (DataStorageException e) {
      logger.error(
          "Failed to load chunk information on " + chunk.getWorld().getName() + position, e);
      getChunkMap(worldId)
          .orElseThrow(IllegalStateException::new)
          .put(position, new ClaimedChunk(context, position));
    }
  }