Search in sources :

Example 6 with MagicWorld

use of com.elmakers.mine.bukkit.world.MagicWorld in project MagicPlugin by elBukkit.

the class WorldSpawnListener method onEntitiesLoaded.

@Override
public void onEntitiesLoaded(Chunk chunk, List<Entity> entities) {
    MagicWorld magicWorld = controller.getWorld(chunk.getWorld().getName());
    if (magicWorld == null)
        return;
    Plugin plugin = controller.getPlugin();
    controller.setDisableSpawnReplacement(true);
    for (Entity testEntity : entities) {
        if (!(testEntity instanceof LivingEntity))
            continue;
        if (testEntity instanceof Player)
            continue;
        LivingEntity entity = (LivingEntity) testEntity;
        try {
            if (magicWorld.processEntitySpawn(plugin, entity)) {
                processedChunkSpawns++;
                entity.remove();
            }
        } catch (Exception ex) {
            controller.getLogger().log(Level.SEVERE, "Error replacing mob", ex);
        }
    }
    controller.setDisableSpawnReplacement(false);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) MagicWorld(com.elmakers.mine.bukkit.world.MagicWorld) Plugin(org.bukkit.plugin.Plugin)

Example 7 with MagicWorld

use of com.elmakers.mine.bukkit.world.MagicWorld in project MagicPlugin by elBukkit.

the class WorldSpawnListener method onEntitySpawn.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntitySpawn(CreatureSpawnEvent event) {
    if (controller.isDisableSpawnReplacement() || ignoreReasons.contains(event.getSpawnReason())) {
        return;
    }
    MagicWorld magicWorld = controller.getWorld(event.getLocation().getWorld().getName());
    if (magicWorld == null)
        return;
    LivingEntity entity = event.getEntity();
    Plugin plugin = controller.getPlugin();
    controller.setDisableSpawnReplacement(true);
    try {
        if (magicWorld.processEntitySpawn(plugin, entity)) {
            entity.remove();
            event.setCancelled(true);
            processedSpawns++;
        }
    } catch (Exception ex) {
        controller.getLogger().log(Level.SEVERE, "Error replacing mob", ex);
    }
    controller.setDisableSpawnReplacement(false);
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) MagicWorld(com.elmakers.mine.bukkit.world.MagicWorld) Plugin(org.bukkit.plugin.Plugin) EventHandler(org.bukkit.event.EventHandler)

Example 8 with MagicWorld

use of com.elmakers.mine.bukkit.world.MagicWorld in project MagicPlugin by elBukkit.

the class WorldPlayerListener method onBlockBreak.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
    Block block = event.getBlock();
    MagicWorld magicWorld = controller.getWorld(block.getWorld().getName());
    if (magicWorld == null)
        return;
    BlockResult result = magicWorld.processBlockBreak(block, event.getPlayer());
    if (result == BlockResult.CANCEL) {
        event.setCancelled(true);
    }
    if (result == BlockResult.REMOVE_DROPS) {
        event.setCancelled(true);
        block.setType(Material.AIR);
    }
}
Also used : BlockResult(com.elmakers.mine.bukkit.world.BlockResult) Block(org.bukkit.block.Block) MagicWorld(com.elmakers.mine.bukkit.world.MagicWorld) EventHandler(org.bukkit.event.EventHandler)

Aggregations

MagicWorld (com.elmakers.mine.bukkit.world.MagicWorld)8 EventHandler (org.bukkit.event.EventHandler)5 Player (org.bukkit.entity.Player)3 BlockResult (com.elmakers.mine.bukkit.world.BlockResult)2 Block (org.bukkit.block.Block)2 LivingEntity (org.bukkit.entity.LivingEntity)2 Plugin (org.bukkit.plugin.Plugin)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 Mage (com.elmakers.mine.bukkit.magic.Mage)1 World (org.bukkit.World)1 Entity (org.bukkit.entity.Entity)1