Search in sources :

Example 1 with MaterialSetManager

use of com.elmakers.mine.bukkit.api.magic.MaterialSetManager in project MagicPlugin by elBukkit.

the class BaseSpell method processParameters.

public void processParameters(ConfigurationSection parameters) {
    fizzleChance = (float) parameters.getDouble("fizzle_chance", 0);
    backfireChance = (float) parameters.getDouble("backfire_chance", 0);
    Location defaultLocation = location == null ? mage.getLocation() : location;
    Location locationOverride = ConfigurationUtils.overrideLocation(parameters, "p", defaultLocation, controller.canCreateWorlds());
    if (locationOverride != null) {
        location = locationOverride;
    }
    costReduction = (float) parameters.getDouble("cost_reduction", 0);
    consumeReduction = (float) parameters.getDouble("consume_reduction", 0);
    cooldownReduction = (float) parameters.getDouble("cooldown_reduction", 0);
    if (parameters.getBoolean("free", false)) {
        costReduction = 2;
        consumeReduction = 2;
    }
    bypassMageCooldown = parameters.getBoolean("bypass_mage_cooldown", false);
    cancelOnDamage = parameters.getDouble("cancel_on_damage", 0);
    cancelOnCastOther = parameters.getBoolean("cancel_on_cast_other", false);
    cancelOnNoPermission = parameters.getBoolean("cancel_on_no_permission", false);
    cancelOnNoWand = parameters.getBoolean("cancel_on_no_wand", false);
    commandBlockAllowed = parameters.getBoolean("command_block_allowed", true);
    MaterialSetManager materials = controller.getMaterialSetManager();
    preventPassThroughMaterials = materials.getMaterialSetEmpty("indestructible");
    preventPassThroughMaterials = materials.fromConfig(parameters.getString("prevent_passthrough"), preventPassThroughMaterials);
    passthroughMaterials = materials.getMaterialSetEmpty("passthrough");
    passthroughMaterials = materials.fromConfig(parameters.getString("passthrough"), passthroughMaterials);
    unsafeMaterials = materials.getMaterialSetEmpty("unsafe");
    unsafeMaterials = materials.fromConfig(parameters.getString("unsafe"), unsafeMaterials);
    bypassDeactivate = parameters.getBoolean("bypass_deactivate", false);
    quiet = parameters.getBoolean("quiet", false);
    loud = parameters.getBoolean("loud", false);
    targetSelf = parameters.getBoolean("target_self", false);
    messageTargets = parameters.getBoolean("message_targets", true);
    verticalSearchDistance = parameters.getInt("vertical_range", 8);
    passive = parameters.getBoolean("passive", false);
    cooldown = parameters.getInt("cooldown", 0);
    cooldown = parameters.getInt("cool", cooldown);
    displayCooldown = parameters.getInt("display_cooldown", -1);
    warmup = parameters.getInt("warmup", 0);
    bypassPvpRestriction = parameters.getBoolean("bypass_pvp", false);
    bypassPvpRestriction = parameters.getBoolean("bp", bypassPvpRestriction);
    bypassPermissions = parameters.getBoolean("bypass_permissions", false);
    bypassBuildRestriction = parameters.getBoolean("bypass_build", false);
    bypassBuildRestriction = parameters.getBoolean("bb", bypassBuildRestriction);
    bypassBreakRestriction = parameters.getBoolean("bypass_break", false);
    bypassProtection = parameters.getBoolean("bypass_protection", false);
    bypassProtection = parameters.getBoolean("bp", bypassProtection);
    bypassAll = parameters.getBoolean("bypass", false);
    duration = parameters.getInt("duration", 0);
    totalDuration = parameters.getInt("total_duration", 0);
}
Also used : Location(org.bukkit.Location) MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager)

Example 2 with MaterialSetManager

use of com.elmakers.mine.bukkit.api.magic.MaterialSetManager in project MagicPlugin by elBukkit.

the class AnimateSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    if (parameters.getString("animate", null) != null) {
        return super.onCast(parameters);
    }
    final Block targetBlock = getTargetBlock();
    if (targetBlock == null) {
        return SpellResult.NO_TARGET;
    }
    if (!hasBuildPermission(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    int seedRadius = parameters.getInt("seed_radius", 0);
    MaterialAndData targetMaterial = new MaterialAndData(targetBlock);
    List<String> materials = ConfigurationUtils.getStringList(parameters, "materials");
    if (seedRadius > 0 && materials != null && !materials.isEmpty()) {
        targetMaterial = new MaterialAndData(RandomUtils.getRandom(materials));
    } else if (parameters.contains("material")) {
        targetMaterial = ConfigurationUtils.getMaterialAndData(parameters, "material", targetMaterial);
        if (targetMaterial.isValid()) {
            addDestructible(targetMaterial);
        }
    }
    if (!mage.isSuperPowered() && seedRadius == 0) {
        MaterialSetManager materialSets = controller.getMaterialSetManager();
        MaterialSet restricted = materialSets.getMaterialSet("restricted");
        if (restricted != null && restricted.testMaterialAndData(targetMaterial)) {
            return SpellResult.FAIL;
        }
        if (parameters.contains("restricted")) {
            String customRestricted = parameters.getString("restricted");
            if (customRestricted != null && !customRestricted.equals("restricted")) {
                restricted = materialSets.fromConfigEmpty(customRestricted);
                if (restricted.testMaterialAndData(targetMaterial)) {
                    return SpellResult.FAIL;
                }
            }
        }
    }
    if (!isDestructible(targetBlock)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    registerForUndo(targetBlock);
    if (seedRadius > 0) {
        for (int dx = -seedRadius; dx < seedRadius; dx++) {
            for (int dz = -seedRadius; dz < seedRadius; dz++) {
                for (int dy = -seedRadius; dy < seedRadius; dy++) {
                    Block seedBlock = targetBlock.getRelative(dx, dy, dz);
                    if (isDestructible(seedBlock)) {
                        registerForUndo(seedBlock);
                        targetMaterial.modify(seedBlock);
                    }
                }
            }
        }
    }
    // Look for randomized levels
    int level = 0;
    if (parameters.contains("level")) {
        level = parameters.getInt("level", level);
    } else if (levelWeights != null) {
        level = RandomUtils.weightedRandom(levelWeights);
    }
    boolean simCheckDestructible = parameters.getBoolean("sim_check_destructible", true);
    simCheckDestructible = parameters.getBoolean("scd", simCheckDestructible);
    final ConfigurationSection automataParameters = new MemoryConfiguration();
    automataParameters.set("target", "self");
    automataParameters.set("cooldown", 0);
    automataParameters.set("m", targetMaterial.getKey());
    automataParameters.set("cd", (simCheckDestructible ? true : false));
    automataParameters.set("level", level);
    String automataName = parameters.getString("name", "Automata");
    Messages messages = controller.getMessages();
    String automataType = parameters.getString("message_type", "evil");
    List<String> prefixes = messages.getAll("automata." + automataType + ".prefixes");
    List<String> suffixes = messages.getAll("automata." + automataType + ".suffixes");
    automataName = prefixes.get(random.nextInt(prefixes.size())) + " " + automataName + " " + suffixes.get(random.nextInt(suffixes.size()));
    if (level > 1) {
        automataName += " " + escapeLevel(messages, "automata.level", level);
    }
    String message = getMessage("cast_broadcast").replace("$name", automataName);
    if (message.length() > 0) {
        controller.sendToMages(message, targetBlock.getLocation());
    }
    automataParameters.set("animate", automataName);
    String automataId = UUID.randomUUID().toString();
    final Mage mage = controller.getAutomaton(automataId, automataName);
    mage.setLocation(targetBlock.getLocation());
    mage.setQuiet(true);
    mage.addTag(getKey());
    final Spell spell = mage.getSpell(getKey());
    Bukkit.getScheduler().runTaskLater(controller.getPlugin(), new Runnable() {

        @Override
        public void run() {
            spell.cast(automataParameters);
        }
    }, 1);
    registerForUndo();
    return SpellResult.CAST;
}
Also used : Messages(com.elmakers.mine.bukkit.api.magic.Messages) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) Spell(com.elmakers.mine.bukkit.api.spell.Spell) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Block(org.bukkit.block.Block) MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 3 with MaterialSetManager

use of com.elmakers.mine.bukkit.api.magic.MaterialSetManager in project MagicPlugin by elBukkit.

the class TorchAction method initialize.

@Override
public void initialize(Spell spell, ConfigurationSection parameters) {
    super.initialize(spell, parameters);
    MaterialSetManager materialSetManager = spell.getController().getMaterialSetManager();
    slippery = materialSetManager.fromConfig(parameters.getString("not_attachable", "not_attachable"));
}
Also used : MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager)

Example 4 with MaterialSetManager

use of com.elmakers.mine.bukkit.api.magic.MaterialSetManager in project MagicPlugin by elBukkit.

the class BlockSpell method processParameters.

@Override
public void processParameters(ConfigurationSection parameters) {
    super.processParameters(parameters);
    MaterialSetManager materials = controller.getMaterialSetManager();
    indestructible = MaterialSets.empty();
    // Legacy
    indestructible = materials.fromConfig(parameters.getString("id"), indestructible);
    indestructible = materials.fromConfig(parameters.getString("indestructible"), indestructible);
    destructible = materials.fromConfig(parameters.getString("destructible"));
    if (parameters.getBoolean("destructible_override", false)) {
        String destructibleKey = controller.getDestructibleMaterials(mage, mage.getLocation());
        destructibleOverride = destructibleKey == null ? null : materials.fromConfig(destructibleKey);
    } else {
        destructibleOverride = null;
    }
    checkDestructible = parameters.getBoolean("check_destructible", true);
    checkDestructible = parameters.getBoolean("cd", checkDestructible);
    destructibleDurability = (float) parameters.getDouble("destructible_durability", 0.0);
}
Also used : MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager)

Example 5 with MaterialSetManager

use of com.elmakers.mine.bukkit.api.magic.MaterialSetManager in project MagicPlugin by elBukkit.

the class TargetingSpell method processParameters.

@Override
public void processParameters(ConfigurationSection parameters) {
    super.processParameters(parameters);
    targeting.processParameters(parameters);
    processTemplateParameters(parameters);
    allowMaxRange = parameters.getBoolean("allow_max_range", false);
    checkProtection = parameters.getBoolean("check_protection", false);
    damageResistanceProtection = parameters.getInt("damage_resistance_protection", 0);
    targetBreakables = parameters.getDouble("target_breakables", 1);
    reverseTargeting = parameters.getBoolean("reverse_targeting", false);
    instantBlockEffects = parameters.getBoolean("instant_block_effects", false);
    MaterialSetManager materials = controller.getMaterialSetManager();
    targetThroughMaterials = MaterialSets.empty();
    targetThroughMaterials = materials.getMaterialSet("transparent", targetThroughMaterials);
    targetThroughMaterials = materials.fromConfig(parameters.getString("transparent"), targetThroughMaterials);
    targetableMaterials = MaterialSets.wildcard();
    targetableMaterials = materials.fromConfig(parameters.getString("targetable"), targetableMaterials);
    reflectiveMaterials = MaterialSets.empty();
    reflectiveMaterials = materials.fromConfig(parameters.getString("reflective"), reflectiveMaterials);
    if (parameters.getBoolean("reflective_override", true)) {
        String reflectiveKey = controller.getReflectiveMaterials(mage, mage.getLocation());
        if (reflectiveKey != null) {
            reflectiveMaterials = MaterialSets.union(materials.fromConfigEmpty(reflectiveKey), reflectiveMaterials);
        }
    }
    targetNPCs = parameters.getBoolean("target_npc", false);
    targetArmorStands = parameters.getBoolean("target_armor_stand", false);
    targetInvisible = parameters.getBoolean("target_invisible", true);
    targetVanished = parameters.getBoolean("target_vanished", false);
    targetUnknown = parameters.getBoolean("target_unknown", true);
    targetTamed = parameters.getBoolean("target_tamed", true);
    if (parameters.contains("target_type")) {
        String entityTypeName = parameters.getString("target_type");
        try {
            targetEntityType = Class.forName("org.bukkit.entity." + entityTypeName);
        } catch (Throwable ex) {
            controller.getLogger().warning("Unknown entity type in target_type of " + getKey() + ": " + entityTypeName);
            targetEntityType = null;
        }
    } else if (parameters.contains("target_types")) {
        targetEntityType = null;
        targetEntityTypes = new HashSet<>();
        Collection<String> typeKeys = ConfigurationUtils.getStringList(parameters, "target_types");
        for (String typeKey : typeKeys) {
            try {
                EntityType entityType = EntityType.valueOf(typeKey.toUpperCase());
                targetEntityTypes.add(entityType);
            } catch (Throwable ex) {
                controller.getLogger().warning("Unknown entity type in target_types of " + getKey() + ": " + typeKey);
            }
        }
    } else {
        targetEntityType = null;
        targetEntityTypes = null;
    }
    if (parameters.contains("ignore_types")) {
        ignoreEntityTypes = new HashSet<>();
        Collection<String> typeKeys = ConfigurationUtils.getStringList(parameters, "ignore_types");
        for (String typeKey : typeKeys) {
            try {
                EntityType entityType = EntityType.valueOf(typeKey.toUpperCase());
                ignoreEntityTypes.add(entityType);
            } catch (Throwable ex) {
                controller.getLogger().warning("Unknown entity type in ignore_types of " + getKey() + ": " + typeKey);
            }
        }
    } else {
        ignoreEntityTypes = null;
    }
    targetDisplayName = parameters.getString("target_name", null);
    targetContents = ConfigurationUtils.getMaterial(parameters, "target_contents", null);
    originAtTarget = parameters.getBoolean("origin_at_target", false);
    Location defaultLocation = getLocation();
    targetLocation = ConfigurationUtils.overrideLocation(parameters, "t", defaultLocation, controller.canCreateWorlds());
    // For two-click construction spells
    defaultLocation = targetLocation == null ? defaultLocation : targetLocation;
    targetLocation2 = ConfigurationUtils.overrideLocation(parameters, "t2", defaultLocation, controller.canCreateWorlds());
    if (parameters.contains("entity") && mage != null) {
        Entity mageEntity = mage.getEntity();
        if (mageEntity != null) {
            Entity entity = CompatibilityUtils.getEntity(mageEntity.getWorld(), UUID.fromString(parameters.getString("entity")));
            if (entity != null) {
                targetLocation = entity.getLocation();
                targetEntity = entity;
            }
        }
    } else if (parameters.contains("player")) {
        Player player = DeprecatedUtils.getPlayer(parameters.getString("player"));
        if (player != null) {
            targetLocation = player.getLocation();
            targetEntity = player;
        }
    } else {
        targetEntity = null;
    }
    // Special hack that should work well in most casts.
    boolean targetUnderwater = parameters.getBoolean("target_underwater", true);
    if (targetUnderwater && isUnderwater()) {
        targetThroughMaterials = MaterialSets.union(targetThroughMaterials, Material.WATER, Material.STATIONARY_WATER);
    }
}
Also used : EntityType(org.bukkit.entity.EntityType) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Collection(java.util.Collection) MaterialSetManager(com.elmakers.mine.bukkit.api.magic.MaterialSetManager) HashSet(java.util.HashSet) Location(org.bukkit.Location)

Aggregations

MaterialSetManager (com.elmakers.mine.bukkit.api.magic.MaterialSetManager)5 Location (org.bukkit.Location)2 Mage (com.elmakers.mine.bukkit.api.magic.Mage)1 MaterialSet (com.elmakers.mine.bukkit.api.magic.MaterialSet)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 Spell (com.elmakers.mine.bukkit.api.spell.Spell)1 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Block (org.bukkit.block.Block)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)1 Entity (org.bukkit.entity.Entity)1 EntityType (org.bukkit.entity.EntityType)1 LivingEntity (org.bukkit.entity.LivingEntity)1 Player (org.bukkit.entity.Player)1