Search in sources :

Example 1 with SpawnResult

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

Aggregations

CastSpell (com.elmakers.mine.bukkit.world.CastSpell)1 SpawnResult (com.elmakers.mine.bukkit.world.spawn.SpawnResult)1 Nonnull (javax.annotation.Nonnull)1