Java Code Examples for org.bukkit.Chunk#load()

The following examples show how to use org.bukkit.Chunk#load() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SchematicHandler.java    From UhcCore with GNU General Public License v3.0 6 votes vote down vote up
public static ArrayList<Integer> pasteSchematic(Location loc, File schematicFile, int loadingArea) throws Exception{
    if (loadingArea > 0){
        for (int x = (loc.getBlockX()/16)-loadingArea; x < (loc.getBlockX()/16)+loadingArea; x++) {
            for (int z = (loc.getBlockZ()/16)-loadingArea; z < (loc.getBlockZ()/16)+loadingArea; z++) {
                Chunk chunk = loc.getWorld().getChunkAt(x,z);
                chunk.load(true);
                chunk.unload(true);
            }
        }
    }

    if (UhcCore.getVersion() < 13){
        return SchematicHandler8.pasteSchematic(loc, schematicFile.getPath());
    }else {
        return SchematicHandler13.pasteSchematic(loc, schematicFile.getPath());
    }
}
 
Example 2
Source File: RecalculateTask.java    From factions-top with MIT License 6 votes vote down vote up
@Override
public void run() {
    int counter = plugin.getSettings().getRecalculateChunksPerTick();

    while (isRunning()) {
        if (counter-- <= 0) {
            break;
        }

        ChunkPos pos = toRecalculate.pop();
        Chunk chunk = pos.getChunk(plugin.getServer());
        if (chunk != null && chunk.load()) {
            plugin.getWorthManager().recalculate(chunk, RecalculateReason.COMMAND);
        }
    }

    if (!isRunning()) {
        plugin.getWorthManager().updateAllFactions();
        plugin.getServer().getScheduler().cancelTask(taskId);
        plugin.getServer().broadcastMessage(plugin.getSettings().getRecalculationFinishMessage());
    }
}
 
Example 3
Source File: WorldGuardSevenCommunicator.java    From WorldGuardExtraFlagsPlugin with MIT License 6 votes vote down vote up
@Override
public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) 
{
	for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16), BlockVector3.at(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15))))
	{
		if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY)
		{
			if (WorldGuardSevenCommunicator.supportsForceLoad)
			{
				chunk.setForceLoaded(true);
				chunk.load(true);
				
				return true;
			}
			
			return false;
		}
	}
	
	return true;
}
 
Example 4
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 6 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_8_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (chunk == null) {
            try {
                chunk = new CraftChunk(nmsChunk);
            } catch (NullPointerException e) {
                throw new HologramEntitySpawnException("Attempted to spawn hologram entity in invalid chunk", e);
            }
        }

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 5
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 6 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_8_R2.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (chunk == null) {
            try {
                chunk = new CraftChunk(nmsChunk);
            } catch (NullPointerException e) {
                throw new HologramEntitySpawnException("Attempted to spawn hologram entity in invalid chunk", e);
            }
        }

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 6
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_11_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 7
Source File: ChunkGenerateTask.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {

	int maxgen = 10;
	int i = 0;

	for (int x = startX; x <= stopX; x++) {
		for (int z = startZ; z <= stopZ; z++) {
			i++;
			
			Chunk chunk = Bukkit.getWorld("world").getChunkAt(x, z);
			if (!chunk.load(true)) {
			}
			
			if (!chunk.unload(true, false)) {
			}
			
			if (i > maxgen) {
				TaskMaster.syncTask(new ChunkGenerateTask(x, z, stopX, stopZ));
				return;
			}
			
		}
	}
	
	
}
 
Example 8
Source File: SyncLoadChunk.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void run() {
	
	if (lock.tryLock()) {
		try {
			for (int i = 0; i < UPDATE_LIMIT; i++) {
				LoadChunkRequest request = requestQueue.poll();
				if (request == null) {
					return;
				}
				
				Chunk chunk = Bukkit.getWorld(request.worldName).getChunkAt(request.x, request.z);
				if (!chunk.isLoaded()) {
					if (!chunk.load()) {
						CivLog.error("Couldn't load chunk at "+request.x+","+request.z);
						continue;
					}
				}
				
				request.finished = true;
				request.condition.signalAll();					
			}
		} finally {
			lock.unlock();
		}
		
	} else {
		//CivLog.warning("SyncLoadChunk: lock was busy, try again next tick.");
	}
}
 
Example 9
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_9_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 10
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_13_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 11
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_10_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 12
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_13_R2.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 13
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_9_R2.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 14
Source File: GameStore.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return killed entity
 */
public LivingEntity kill() {
    final LivingEntity livingEntity = entity;
    if (entity != null) {
        final Chunk chunk = entity.getLocation().getChunk();

        if (!chunk.isLoaded()) {
            chunk.load();
        }
        entity.remove();
        entity = null;
    }
    return livingEntity;
}
 
Example 15
Source File: HologramEntityControllerImpl.java    From Holograms with MIT License 5 votes vote down vote up
private boolean addEntityToWorld(WorldServer nmsWorld, Entity nmsEntity) {
    net.minecraft.server.v1_12_R1.Chunk nmsChunk = nmsWorld.getChunkAtWorldCoords(nmsEntity.getChunkCoordinates());

    if (nmsChunk != null) {
        Chunk chunk = nmsChunk.bukkitChunk;

        if (!chunk.isLoaded()) {
            chunk.load();
            plugin.getLogger().info("Loaded chunk (x:" + chunk.getX() + " z:" + chunk.getZ() + ") to spawn a Hologram");
        }
    }

    return nmsWorld.addEntity(nmsEntity, CreatureSpawnEvent.SpawnReason.CUSTOM);
}
 
Example 16
Source File: Game.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public void updateSigns() {
  boolean removedItem = false;

  Iterator<GameJoinSign> iterator = Game.this.joinSigns.values().iterator();
  while (iterator.hasNext()) {
    GameJoinSign sign = iterator.next();

    Chunk signChunk = sign.getSign().getLocation().getChunk();
    if (!signChunk.isLoaded()) {
      signChunk.load(true);
    }

    if (sign.getSign() == null) {
      iterator.remove();
      removedItem = true;
      continue;
    }

    Block signBlock = sign.getSign().getLocation().getBlock();
    if (!(signBlock.getState() instanceof Sign)) {
      iterator.remove();
      removedItem = true;
      continue;
    }
    sign.updateSign();
  }

  if (removedItem) {
    Game.this.updateSignConfig();
  }
}
 
Example 17
Source File: Region.java    From BedwarsRel with GNU General Public License v3.0 5 votes vote down vote up
public void loadChunks() {
  int minX = (int) Math.floor(this.minCorner.getX());
  int maxX = (int) Math.ceil(this.maxCorner.getX());
  int minZ = (int) Math.floor(this.minCorner.getZ());
  int maxZ = (int) Math.ceil(this.maxCorner.getZ());

  for (int x = minX; x <= maxX; x += Region.CHUNK_SIZE) {
    for (int z = minZ; z <= maxZ; z += Region.CHUNK_SIZE) {
      Chunk chunk = this.world.getChunkAt(x, z);
      if (!chunk.isLoaded()) {
        chunk.load();
      }
    }
  }
}
 
Example 18
Source File: UnloadedInventoryHandler.java    From Civs with GNU General Public License v3.0 5 votes vote down vote up
public void loadChunks() {
    for (Map.Entry<String, HashMap<String, CVInventory>> outerEntry : unloadedChestInventories.entrySet()) {
        for (Map.Entry<String, CVInventory> entry : outerEntry.getValue().entrySet()) {
            CVInventory cvInventory = entry.getValue();
            if (cvInventory.getLastUnloadedModification() != -1 &&
                    System.currentTimeMillis() > ConfigManager.getInstance().getUnloadedChestRefreshRate() +
                            cvInventory.getLastUnloadedModification()) {
                Chunk chunk = cvInventory.getLocation().getChunk();
                if (!chunk.isLoaded()) {
                    chunk.load();
                }
            }
        }
    }
}
 
Example 19
Source File: GameStore.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return killed entity
 */
public LivingEntity kill() {
    final LivingEntity livingEntity = entity;
    if (entity != null) {
        final Chunk chunk = entity.getLocation().getChunk();

        if (!chunk.isLoaded()) {
            chunk.load();
        }
        entity.remove();
        entity = null;
    }
    return livingEntity;
}
 
Example 20
Source File: BukkitQueue_All.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public ChunkSnapshot loadChunk(World world, int x, int z, boolean generate) {
    Chunk chunk = world.getChunkAt(x, z);
    chunk.load(generate);
    return chunk.isLoaded() ? getAndCacheChunk(chunk) : null;
}