Search in sources :

Example 11 with Chunk

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;
        }
    }
}
Also used : Resident(com.palmergames.bukkit.towny.object.Resident) Chunk(org.bukkit.Chunk) TownyException(com.palmergames.bukkit.towny.exceptions.TownyException)

Example 12 with Chunk

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;
}
Also used : Entity(org.bukkit.entity.Entity) Explosive(org.bukkit.entity.Explosive) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) Chunk(org.bukkit.Chunk)

Aggregations

Chunk (org.bukkit.Chunk)12 Location (org.bukkit.Location)4 World (org.bukkit.World)3 Player (org.bukkit.entity.Player)3 Teleport (com.earth2me.essentials.Teleport)2 User (com.earth2me.essentials.User)2 NotRegisteredException (com.palmergames.bukkit.towny.exceptions.NotRegisteredException)2 TownyException (com.palmergames.bukkit.towny.exceptions.TownyException)2 Resident (com.palmergames.bukkit.towny.object.Resident)2 BlockInventoryHolder (com.palmergames.bukkit.towny.regen.block.BlockInventoryHolder)2 BlockMobSpawner (com.palmergames.bukkit.towny.regen.block.BlockMobSpawner)2 BlockObject (com.palmergames.bukkit.towny.regen.block.BlockObject)2 BlockSign (com.palmergames.bukkit.towny.regen.block.BlockSign)2 ArrayList (java.util.ArrayList)2 BlockState (org.bukkit.block.BlockState)2 Sign (org.bukkit.block.Sign)2 InventoryHolder (org.bukkit.inventory.InventoryHolder)2 TreasureHuntModule (au.com.mineauz.minigames.minigame.modules.TreasureHuntModule)1 Mob (com.earth2me.essentials.Mob)1 AlreadyRegisteredException (com.palmergames.bukkit.towny.exceptions.AlreadyRegisteredException)1