Search in sources :

Example 6 with BlockResult

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

the class MagicBlockPopulator method populate.

@Override
public BlockResult populate(Block block, Random random) {
    if (replace != null && !replace.testBlock(block)) {
        return BlockResult.SKIP;
    }
    String templateKey = RandomUtils.weightedRandom(templateProbability);
    if (templateKey.equalsIgnoreCase("none")) {
        return BlockResult.SKIP;
    }
    try {
        BlockResult result = BlockResult.valueOf(templateKey.toUpperCase());
        return result;
    } catch (Exception ignore) {
    }
    Location location = block.getLocation();
    MagicBlock automaton = controller.addMagicBlock(location, templateKey, null, null, parameters);
    String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
    if (automaton == null) {
        message = "Failed to create" + message;
    } else {
        message = "Created" + message;
    }
    controller.info(message);
    return automaton == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
Also used : MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) BlockResult(com.elmakers.mine.bukkit.world.BlockResult) Location(org.bukkit.Location)

Example 7 with BlockResult

use of com.elmakers.mine.bukkit.world.BlockResult 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

BlockResult (com.elmakers.mine.bukkit.world.BlockResult)7 Block (org.bukkit.block.Block)3 MagicBlock (com.elmakers.mine.bukkit.api.block.magic.MagicBlock)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 MagicWorld (com.elmakers.mine.bukkit.world.MagicWorld)2 Nonnull (javax.annotation.Nonnull)2 Location (org.bukkit.Location)2 EventHandler (org.bukkit.event.EventHandler)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 CastSpell (com.elmakers.mine.bukkit.world.CastSpell)1 Random (java.util.Random)1