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);
}
}
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()));
}
}
}
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;
}
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();
}
}
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);
}
}
Aggregations