use of org.bukkit.Chunk in project Towny by ElgarL.
the class TeleportWarmupTimerTask method run.
@Override
public void run() {
long currentTime = System.currentTimeMillis();
while (true) {
Resident resident = teleportQueue.peek();
if (resident == null)
break;
if (currentTime > resident.getTeleportRequestTime() + (TownySettings.getTeleportWarmupTime() * 1000)) {
resident.clearTeleportRequest();
try {
// Make sure the chunk we teleport to is loaded.
Chunk chunk = resident.getTeleportDestination().getWorld().getChunkAt(resident.getTeleportDestination().getBlock());
if (!chunk.isLoaded())
chunk.load();
TownyUniverse.getPlayer(resident).teleport(resident.getTeleportDestination());
} catch (TownyException ignore) {
}
teleportQueue.poll();
} else {
break;
}
}
}
use of org.bukkit.Chunk in project TotalFreedomMod by TotalFreedom.
the class EntityWiper method wipeEntities.
public int wipeEntities(World world, boolean force) {
int removed = 0;
boolean wipeExpl = ConfigEntry.ALLOW_EXPLOSIONS.getBoolean();
Iterator<Entity> entities = world.getEntities().iterator();
// Organise the entities in the world
Map<Chunk, List<Entity>> cem = new HashMap<>();
while (entities.hasNext()) {
final Entity entity = entities.next();
// Explosives
if (wipeExpl && Explosive.class.isAssignableFrom(entity.getClass())) {
entity.remove();
removed++;
}
// Only wipeable entities can be wiped (duh!)
if (!isWipeable(entity)) {
continue;
}
Chunk c = entity.getLocation().getChunk();
List<Entity> cel = cem.get(c);
if (cel == null) {
cem.put(c, new ArrayList<>(Arrays.asList(entity)));
} else {
cel.add(entity);
}
}
// Now purge the entities if necessary
for (Chunk c : cem.keySet()) {
List<Entity> cel = cem.get(c);
if (!force && cel.size() < CHUNK_ENTITY_MAX) {
continue;
}
// Too many entities in this chunk, wipe them all
for (Entity e : cel) {
e.remove();
}
}
return removed;
}
Aggregations