Search in sources :

Example 1 with CastSpell

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

the class CastRule method finalizeLoad.

@Override
public void finalizeLoad(String worldName) {
    yOffset = parameters.getInt("y_offset", 0);
    Collection<String> spells = parameters.getStringList("spells");
    if (spells == null || spells.size() == 0) {
        ConfigurationSection spellMap = parameters.getConfigurationSection("spells");
        spellProbability = new ArrayDeque<>();
        RandomUtils.populateProbabilityMap(CastSpellParser.getInstance(), spellProbability, spellMap);
        if (spellProbability.isEmpty()) {
            return;
        }
        logSpawnRule("Casting one of " + StringUtils.join(this.spellProbability, ",") + " on " + getTargetEntityTypeName() + " in " + worldName);
    } else {
        this.spells = new ArrayList<>();
        for (String spellName : spells) {
            this.spells.add(new CastSpell(spellName));
        }
        logSpawnRule("Casting " + StringUtils.join(this.spells, ",") + " on " + getTargetEntityTypeName() + " in " + worldName);
    }
}
Also used : CastSpell(com.elmakers.mine.bukkit.world.CastSpell) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 2 with CastSpell

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

the class CastRule method onProcess.

@Override
@Nonnull
public SpawnResult onProcess(Plugin plugin, LivingEntity entity) {
    int y = entity.getLocation().getBlockY() + yOffset;
    if (y > 250)
        y = 250;
    if (entity.getWorld().getEnvironment() == Environment.NETHER && y > 118) {
        y = 118;
    }
    String[] standardParameters = { "pworld", entity.getLocation().getWorld().getName(), "px", Integer.toString(entity.getLocation().getBlockX()), "py", Integer.toString(y), "pz", Integer.toString(entity.getLocation().getBlockZ()), "quiet", "true" };
    if (spells == null) {
        spells = new ArrayList<>();
    }
    if (spellProbability != null) {
        CastSpell spell = RandomUtils.weightedRandom(spellProbability);
        spells.clear();
        spells.add(spell);
    }
    boolean casted = false;
    for (CastSpell spell : spells) {
        if (spell == null || spell.isEmpty()) {
            SpawnResult result = spell.getSpawnResult();
            if (result != SpawnResult.SKIP) {
                return result;
            }
            continue;
        }
        String[] fullParameters = new String[spell.getParameters().length + standardParameters.length];
        for (int index = 0; index < standardParameters.length; index++) {
            fullParameters[index] = standardParameters[index];
        }
        for (int index = 0; index < spell.getParameters().length; index++) {
            fullParameters[index + standardParameters.length] = spell.getParameters()[index];
        }
        casted = controller.cast(spell.getName(), fullParameters) || casted;
        controller.info("Spawn rule casting: " + spell.getName() + " " + StringUtils.join(fullParameters, ' ') + " at " + entity.getLocation().toVector());
    }
    return casted ? SpawnResult.REPLACE : SpawnResult.REMOVE;
}
Also used : CastSpell(com.elmakers.mine.bukkit.world.CastSpell) SpawnResult(com.elmakers.mine.bukkit.world.spawn.SpawnResult) Nonnull(javax.annotation.Nonnull)

Example 3 with CastSpell

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

Example 4 with CastSpell

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

the class CastRule method onLoad.

@Override
public boolean onLoad(ConfigurationSection parameters) {
    Collection<String> spells = parameters.getStringList("spells");
    if (spells == null || spells.size() == 0) {
        ConfigurationSection spellMap = parameters.getConfigurationSection("spells");
        spellProbability = new ArrayDeque<>();
        RandomUtils.populateProbabilityMap(CastSpellParser.getInstance(), spellProbability, spellMap);
        if (spellProbability.isEmpty()) {
            return false;
        }
        logBlockRule("Casting one of " + StringUtils.join(this.spellProbability, ","));
    } else {
        this.spells = new ArrayList<>();
        for (String spellName : spells) {
            this.spells.add(new CastSpell(spellName));
        }
        logBlockRule("Casting " + StringUtils.join(this.spells, ","));
    }
    return !spells.isEmpty() || !spellProbability.isEmpty();
}
Also used : CastSpell(com.elmakers.mine.bukkit.world.CastSpell) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

CastSpell (com.elmakers.mine.bukkit.world.CastSpell)4 Nonnull (javax.annotation.Nonnull)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 BlockResult (com.elmakers.mine.bukkit.world.BlockResult)1 SpawnResult (com.elmakers.mine.bukkit.world.spawn.SpawnResult)1