@EventHandler(priority = EventPriority.LOWEST)
  public void onChunkRegenerate(ChunkPopulateEvent event) {
    if (SpoutCraftChunk.replaceBukkitChunk(event.getChunk())) {
      // Update the reference to the chunk in the event
      try {
        Field chunk = ChunkEvent.class.getDeclaredField("chunk");
        chunk.setAccessible(true);
        chunk.set(
            event,
            event
                .getChunk()
                .getWorld()
                .getChunkAt(event.getChunk().getX(), event.getChunk().getZ()));
      } catch (Exception e) {
        e.printStackTrace();
      }

      SimpleChunkDataManager dm = (SimpleChunkDataManager) SpoutManager.getChunkDataManager();

      // Clear custom block data from generated chunks if it exists
      dm.clearCustomBlockIds(event.getWorld(), event.getChunk().getX(), event.getChunk().getZ());
      dm.clearCustomBlockData(event.getWorld(), event.getChunk().getX(), event.getChunk().getZ());

      dm.loadChunk(event.getChunk());
    }
  }
示例#2
0
  @Override
  public void run() {
    // counter++;
    Spout.getInstance().playerListener.manager.onServerTick();
    Player[] online = Bukkit.getServer().getOnlinePlayers();
    for (Player player : online) {
      if (player instanceof SpoutCraftPlayer) {
        ((SpoutCraftPlayer) player).onTick();
      }
    }
    SpoutCraftChunk.updateTicks();
    ((SimpleMaterialManager) SpoutManager.getMaterialManager()).onTick();
    Spout.getInstance().getEntityTrackingManager().onTick();
    ServerTickEvent event = new ServerTickEvent();
    Bukkit.getServer().getPluginManager().callEvent(event);

    // if (counter % 20 == 0) {
    //	for (World world : Bukkit.getServer().getWorlds()) {
    //		Chunk[] chunks = world.getLoadedChunks();
    //		for (Chunk chunk : chunks) {
    //			if (SpoutCraftChunk.replaceBukkitChunk(chunk)) {
    //				System.out.println("Bad Chunk at (" + chunk.getX() + ", " + chunk.getZ());
    //			}
    //		}
    //	}
    // }
    // if (counter % 1200 == 0) { //check every min
    //	(SimpleChunkDataManager)SpoutManager.getChunkDataManager()).testFileTimeouts();
    // }
  }
示例#3
0
  public boolean sendBlockOverrideToPlayers(Player[] players, Chunk chunk) {

    SpoutCraftChunk scc = getSpoutCraftChunk(chunk);
    if (scc == null) {
      return false;
    }

    BlockVector[] blocks = scc.getTaggedBlocks();

    if (blocks == null) {
      return false;
    }

    boolean success = true;
    for (BlockVector block : blocks) {
      correctBlockVector(block, scc);

      SpoutCraftBlock scb =
          getSpoutCraftBlock(
              chunk.getWorld().getBlockAt(block.getBlockX(), block.getBlockY(), block.getBlockZ()));

      if (scb == null) {
        success = false;
        continue;
      }

      Integer blockId = scb.getCustomBlockId();
      Integer metaData = scb.getCustomMetaData();

      if (blockId != null && metaData != null) {
        sendBlockOverrideToPlayers(players, block, blockId, metaData);
      }
    }

    return success;
  }
  @EventHandler(priority = EventPriority.LOWEST)
  public void onChunkLoad(ChunkLoadEvent event) {
    if (SpoutCraftChunk.replaceBukkitChunk(event.getChunk())) {
      // Update the reference to the chunk in the event
      try {
        Field chunk = ChunkEvent.class.getDeclaredField("chunk");
        chunk.setAccessible(true);
        chunk.set(
            event,
            event
                .getChunk()
                .getWorld()
                .getChunkAt(event.getChunk().getX(), event.getChunk().getZ()));
      } catch (Exception e) {
        e.printStackTrace();
      }

      SimpleChunkDataManager dm = (SimpleChunkDataManager) SpoutManager.getChunkDataManager();
      dm.loadChunk(event.getChunk());
    }
  }