Search in sources :

Example 1 with BlockResult

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

the class MagicBlockHandler method handleBlock.

public BlockResult handleBlock(Block block, Player player) {
    Random random = getRandom(block.getWorld());
    for (BlockRule blockRule : globalBlockRules) {
        BlockResult result = blockRule.handle(block, random, player);
        if (result != BlockResult.SKIP) {
            return result;
        }
    }
    List<BlockRule> rules = blockRules.get(block.getType());
    if (rules != null) {
        for (BlockRule blockRule : rules) {
            BlockResult result = blockRule.handle(block, random, player);
            if (result != BlockResult.SKIP) {
                return result;
            }
        }
    }
    return BlockResult.SKIP;
}
Also used : Random(java.util.Random) BlockResult(com.elmakers.mine.bukkit.world.BlockResult)

Example 2 with BlockResult

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

the class MagicBlockRule method onHandle.

@Override
@Nonnull
public BlockResult onHandle(Block block, Random random, Player cause) {
    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) {
    }
    Mage mage = controller.getMage(cause);
    Location location = block.getLocation();
    MagicBlock magicBlock = controller.addMagicBlock(location, templateKey, mage.getId(), mage.getName(), parameters);
    String message = " magic block: " + templateKey + " at " + location.getWorld().getName() + "," + location.toVector();
    if (magicBlock == null) {
        message = "Failed to create" + message;
    } else {
        message = "Created" + message;
    }
    controller.info(message);
    return magicBlock == null ? BlockResult.SKIP : BlockResult.REMOVE_DROPS;
}
Also used : MagicBlock(com.elmakers.mine.bukkit.api.block.magic.MagicBlock) BlockResult(com.elmakers.mine.bukkit.world.BlockResult) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Location(org.bukkit.Location) Nonnull(javax.annotation.Nonnull)

Example 3 with BlockResult

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

the class WorldPlayerListener method onBlockPlace.

@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onBlockPlace(BlockPlaceEvent event) {
    Block block = event.getBlock();
    MagicWorld magicWorld = controller.getWorld(block.getWorld().getName());
    if (magicWorld == null)
        return;
    BlockResult result = magicWorld.processBlockPlace(block, event.getPlayer());
    if (result == BlockResult.CANCEL) {
        event.setCancelled(true);
    }
}
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)

Example 4 with BlockResult

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

the class BaseBlockPopulator method populate.

@Override
public void populate(World world, Random random, Chunk chunk) {
    for (int x = 0; x <= 15; x++) {
        for (int z = 0; z <= 15; z++) {
            for (int y = minY; y <= maxY; y++) {
                Block block = chunk.getBlock(x, y, z);
                if (y > maxAirY && block.getType() == Material.AIR) {
                    break;
                }
                if (biomes != null && !biomes.contains(block.getBiome()))
                    continue;
                if (notBiomes != null && notBiomes.contains(block.getBiome()))
                    continue;
                long now = System.currentTimeMillis();
                if (cooldown > 0 && now < lastPopulate + cooldown)
                    continue;
                BlockResult result = populate(block, random);
                if (result != BlockResult.SKIP) {
                    lastPopulate = now;
                }
            }
        }
    }
}
Also used : BlockResult(com.elmakers.mine.bukkit.world.BlockResult) Block(org.bukkit.block.Block)

Example 5 with BlockResult

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

the class CastRule method onHandle.

@Override
@Nonnull
public BlockResult onHandle(Block block, Random random, Player cause) {
    String[] standardParameters = { "tworld", block.getLocation().getWorld().getName(), "tx", Integer.toString(block.getLocation().getBlockX()), "ty", Integer.toString(block.getLocation().getBlockY()), "tz", Integer.toString(block.getLocation().getBlockZ()), "quiet", "true" };
    if (spells == null) {
        spells = new ArrayList<>();
    }
    if (spellProbability != null) {
        CastSpell spell = RandomUtils.weightedRandom(spellProbability);
        spells.clear();
        spells.add(spell);
    }
    Mage mage = controller.getMage(cause);
    boolean casted = false;
    for (CastSpell castSpell : spells) {
        if (castSpell.isEmpty()) {
            BlockResult result = castSpell.getBlockResult();
            if (result != BlockResult.SKIP) {
                return result;
            }
            continue;
        }
        Spell spell = mage.getSpell(castSpell.getName());
        if (spell == null)
            continue;
        String[] fullParameters = new String[castSpell.getParameters().length + standardParameters.length];
        for (int index = 0; index < standardParameters.length; index++) {
            fullParameters[index] = standardParameters[index];
        }
        for (int index = 0; index < castSpell.getParameters().length; index++) {
            fullParameters[index + standardParameters.length] = castSpell.getParameters()[index];
        }
        casted = spell.cast(fullParameters) || casted;
    }
    return casted ? BlockResult.REPLACED_DROPS : BlockResult.REMOVE_DROPS;
}
Also used : BlockResult(com.elmakers.mine.bukkit.world.BlockResult) CastSpell(com.elmakers.mine.bukkit.world.CastSpell) Mage(com.elmakers.mine.bukkit.api.magic.Mage) CastSpell(com.elmakers.mine.bukkit.world.CastSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) Nonnull(javax.annotation.Nonnull)

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