Search in sources :

Example 31 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class PhaseSpell method tryPhase.

protected void tryPhase(final LivingEntity entity, final Location targetLocation) {
    Chunk chunk = targetLocation.getBlock().getChunk();
    if (!chunk.isLoaded()) {
        chunk.load(true);
        if (retryCount < MAX_RETRY_COUNT) {
            Plugin plugin = controller.getPlugin();
            final PhaseSpell me = this;
            Bukkit.getScheduler().scheduleSyncDelayedTask(plugin, new Runnable() {

                @Override
                public void run() {
                    me.tryPhase(entity, targetLocation);
                }
            }, RETRY_INTERVAL);
            return;
        }
    }
    Location playerLocation = entity.getLocation();
    targetLocation.setYaw(playerLocation.getYaw());
    targetLocation.setPitch(playerLocation.getPitch());
    Location destination = tryFindPlaceToStand(targetLocation);
    // TODO : Failure notification? Sounds at least? The async nature is difficult.
    if (destination != null) {
        targetWorldName = destination.getWorld().getName();
        entity.teleport(destination);
    }
}
Also used : Chunk(org.bukkit.Chunk) Plugin(org.bukkit.plugin.Plugin) Location(org.bukkit.Location)

Example 32 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class TileEntitiesAction method addTiles.

public void addTiles(CastContext context, List<BlockState> tiles) {
    Location sourceLocation = context.getLocation();
    if (sourceLocation == null && !targetAllWorlds) {
        return;
    }
    List<World> worlds;
    if (targetAllWorlds) {
        worlds = Bukkit.getWorlds();
    } else {
        worlds = new ArrayList<>();
        worlds.add(sourceLocation.getWorld());
    }
    for (World world : worlds) {
        Chunk[] chunks = world.getLoadedChunks();
        for (Chunk chunk : chunks) {
            tiles.addAll(Arrays.asList(chunk.getTileEntities()));
        }
    }
}
Also used : World(org.bukkit.World) Chunk(org.bukkit.Chunk) Location(org.bukkit.Location)

Example 33 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class BlockData method undo.

@Override
public boolean undo(ModifyType modifyType) {
    Block block = getBlock();
    if (block == null) {
        return true;
    }
    Chunk chunk = block.getChunk();
    if (!chunk.isLoaded()) {
        chunk.load();
        return false;
    }
    // Otherwise, state will be pushed up in unlink
    if (nextState == null && isDifferent(block)) {
        undoing = true;
        try {
            modify(block, modifyType);
        } finally {
            undoing = false;
        }
    }
    unlink();
    return true;
}
Also used : Block(org.bukkit.block.Block) Chunk(org.bukkit.Chunk)

Example 34 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class MobController method onChunkUnload.

@EventHandler
public void onChunkUnload(ChunkUnloadEvent event) {
    Chunk chunk = event.getChunk();
    Collection<Mage> magicMobs = controller.getMobMages();
    for (Mage mage : magicMobs) {
        Entity entity = mage.getEntity();
        if (entity == null)
            continue;
        Location location = entity.getLocation();
        if (!chunk.getWorld().getName().equals(location.getWorld().getName()))
            continue;
        int chunkX = chunk.getX();
        int chunkZ = chunk.getZ();
        if (chunkZ != location.getBlockZ() >> 4 || chunkX != location.getBlockX() >> 4)
            continue;
        mage.sendDebugMessage(ChatColor.RED + "Despawned", 4);
        entity.remove();
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Chunk(org.bukkit.Chunk) Location(org.bukkit.Location) EventHandler(org.bukkit.event.EventHandler)

Example 35 with Chunk

use of org.bukkit.Chunk in project MagicPlugin by elBukkit.

the class ExplosionController method onEntityExplode.

@EventHandler(priority = EventPriority.LOWEST)
public void onEntityExplode(EntityExplodeEvent event) {
    Entity explodingEntity = event.getEntity();
    if (explodingEntity == null)
        return;
    UndoList blockList = getExplosionUndo(explodingEntity);
    boolean cancel = event.isCancelled();
    cancel = cancel || explodingEntity.hasMetadata("cancel_explosion");
    if (blockList != null) {
        com.elmakers.mine.bukkit.api.action.CastContext context = blockList.getContext();
        if (!cancel && context != null && !context.hasBreakPermission(explodingEntity.getLocation().getBlock())) {
            cancel = true;
        }
    }
    if (cancel) {
        event.setCancelled(true);
    } else if (maxTNTPerChunk > 0 && explodingEntity.getType() == EntityType.PRIMED_TNT) {
        Chunk chunk = explodingEntity.getLocation().getChunk();
        if (chunk == null || !chunk.isLoaded())
            return;
        int tntCount = 0;
        Entity[] entities = chunk.getEntities();
        for (Entity entity : entities) {
            if (entity != null && entity.getType() == EntityType.PRIMED_TNT) {
                tntCount++;
            }
        }
        if (tntCount > maxTNTPerChunk) {
            event.setCancelled(true);
        } else {
            if (blockList != null) {
                blockList.explode(explodingEntity, event.blockList());
            }
        }
    } else if (blockList != null) {
        blockList.explode(explodingEntity, event.blockList());
        blockList.getOwner().registerForUndo(blockList);
    }
}
Also used : Entity(org.bukkit.entity.Entity) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) Chunk(org.bukkit.Chunk) EventHandler(org.bukkit.event.EventHandler)

Aggregations

Chunk (org.bukkit.Chunk)52 Location (org.bukkit.Location)16 World (org.bukkit.World)10 OwnedLand (biz.princeps.landlord.util.OwnedLand)9 Entity (org.bukkit.entity.Entity)9 ArrayList (java.util.ArrayList)6 IntVector2 (com.bergerkiller.bukkit.common.bases.IntVector2)5 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)5 Block (org.bukkit.block.Block)5 BlockState (org.bukkit.block.BlockState)5 Player (org.bukkit.entity.Player)5 Offers (biz.princeps.landlord.persistent.Offers)4 HashSet (java.util.HashSet)4 EventHandler (org.bukkit.event.EventHandler)3 Plugin (org.bukkit.plugin.Plugin)3 LPlayer (biz.princeps.landlord.persistent.LPlayer)2 DurationTag (com.denizenscript.denizencore.objects.core.DurationTag)2 ElementTag (com.denizenscript.denizencore.objects.core.ElementTag)2 ListTag (com.denizenscript.denizencore.objects.core.ListTag)2 Mob (com.earth2me.essentials.Mob)2