Search in sources :

Example 21 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.

the class ConfigurationUtils method replaceParameters.

@Nullable
public static ConfigurationSection replaceParameters(ConfigurationSection configuration, ConfigurationSection parameters) {
    if (configuration == null)
        return null;
    ConfigurationSection replaced = new MemoryConfiguration();
    Map<String, Object> map = NMSUtils.getMap(configuration);
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        Object value = entry.getValue();
        if (value == null)
            continue;
        Object replacement = replaceParameters(value, parameters);
        if (replacement != null) {
            replaced.set(entry.getKey(), replacement);
        }
    }
    return replaced;
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) HashMap(java.util.HashMap) Map(java.util.Map) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 22 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.

the class MultiplyAction method prepare.

@Override
public void prepare(CastContext context, ConfigurationSection parameters) {
    super.prepare(context, parameters);
    multiply = parameters.getInt("multiply", parameters.getInt("repeat", 2));
    multiplied = new ArrayList<>();
    ActionHandler base = getHandler("actions");
    if (base != null) {
        ConfigurationSection initialParameters = ConfigurationUtils.getConfigurationSection(parameters, "first");
        if (initialParameters != null) {
            ConfigurationSection combined = ConfigurationUtils.addConfigurations(new MemoryConfiguration(), parameters);
            initialParameters = ConfigurationUtils.addConfigurations(combined, initialParameters);
        }
        for (int i = 0; i < multiply; i++) {
            ActionHandler handler = (ActionHandler) base.clone();
            if (i == 0 && initialParameters != null) {
                handler.prepare(context, initialParameters);
            } else {
                handler.prepare(context, parameters);
            }
            multiplied.add(handler);
        }
    }
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ActionHandler(com.elmakers.mine.bukkit.action.ActionHandler) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 23 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.

the class MagicCitizensTrait method perform.

@Override
public boolean perform(net.citizensnpcs.api.event.NPCRightClickEvent event) {
    if (spellKey == null || spellKey.isEmpty())
        return false;
    CommandSender sender = event.getClicker();
    Entity entity = event.getClicker();
    ConfigurationSection config = this.parameters;
    if (npcCaster) {
        if (event.getNPC().isSpawned()) {
            entity = event.getNPC().getEntity();
            if (!messagePlayer) {
                sender = null;
            }
            if (targetPlayer) {
                config = new MemoryConfiguration();
                ConfigurationUtils.addConfigurations(config, parameters);
                config.set("player", event.getClicker().getName());
            }
        }
    }
    return api.cast(spellKey, config, sender, entity);
}
Also used : Entity(org.bukkit.entity.Entity) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) CommandSender(org.bukkit.command.CommandSender) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 24 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.

the class EffectLibManager method play.

@Nullable
public Effect play(ConfigurationSection configuration, EffectPlayer player, DynamicLocation origin, DynamicLocation target, Map<String, String> parameterMap) {
    if (parameterMap == null) {
        parameterMap = new HashMap<>();
    }
    Entity originEntity = origin == null ? null : origin.getEntity();
    if (originEntity != null && originEntity instanceof Player) {
        parameterMap.put("$name", ((Player) originEntity).getName());
    } else if (originEntity != null && originEntity instanceof LivingEntity) {
        parameterMap.put("$name", ((LivingEntity) originEntity).getCustomName());
    } else {
        parameterMap.put("$name", "Unknown");
    }
    Entity targetEntity = target == null ? null : target.getEntity();
    if (targetEntity != null && targetEntity instanceof Player) {
        parameterMap.put("$target", ((Player) targetEntity).getName());
    } else if (originEntity != null && targetEntity instanceof LivingEntity) {
        parameterMap.put("$target", ((LivingEntity) targetEntity).getCustomName());
    } else {
        parameterMap.put("$target", "Unknown");
    }
    Effect effect = null;
    String effectClass = configuration.getString("class");
    ParticleEffect particleEffect = player.overrideParticle(null);
    String effectOverride = player.getParticleOverrideName();
    if (effectOverride != null && effectOverride.isEmpty())
        effectOverride = null;
    String colorOverrideName = player.getColorOverrideName();
    if (colorOverrideName != null && colorOverrideName.isEmpty())
        colorOverrideName = null;
    ConfigurationSection parameters = configuration;
    Color colorOverride = player.getColor1();
    if ((colorOverrideName != null && colorOverride != null) || (effectOverride != null && particleEffect != null)) {
        parameters = new MemoryConfiguration();
        Collection<String> keys = configuration.getKeys(false);
        for (String key : keys) {
            parameters.set(key, configuration.get(key));
        }
        if (effectOverride != null && particleEffect != null) {
            parameters.set(effectOverride, particleEffect.name());
        }
        if (colorOverride != null && colorOverrideName != null) {
            String hexColor = Integer.toHexString(colorOverride.asRGB());
            parameters.set(colorOverrideName, hexColor);
        }
    }
    try {
        effect = effectManager.start(effectClass, parameters, origin, target, parameterMap);
        if (!parameters.contains("material")) {
            MaterialAndData mat = player.getWorkingMaterial();
            if (mat != null) {
                effect.material = mat.getMaterial();
                effect.materialData = mat.getBlockData();
            }
        }
    } catch (Throwable ex) {
        Bukkit.getLogger().warning("Error playing effects of class: " + effectClass);
        ex.printStackTrace();
    }
    return effect;
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Player(org.bukkit.entity.Player) Color(org.bukkit.Color) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) LivingEntity(org.bukkit.entity.LivingEntity) ParticleEffect(de.slikey.effectlib.util.ParticleEffect) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Effect(de.slikey.effectlib.Effect) ParticleEffect(de.slikey.effectlib.util.ParticleEffect) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 25 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project MagicPlugin by elBukkit.

the class BaseSpell method cast.

@Override
public boolean cast(String[] extraParameters, Location defaultLocation) {
    ConfigurationSection parameters = null;
    if (extraParameters != null && extraParameters.length > 0) {
        parameters = new MemoryConfiguration();
        ConfigurationUtils.addParameters(extraParameters, parameters);
    }
    return cast(parameters, defaultLocation);
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)29 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)26 Mage (com.elmakers.mine.bukkit.api.magic.Mage)5 ArrayList (java.util.ArrayList)5 Spell (com.elmakers.mine.bukkit.api.spell.Spell)4 HashMap (java.util.HashMap)4 Entity (org.bukkit.entity.Entity)4 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)3 EquationTransform (de.slikey.effectlib.math.EquationTransform)3 Map (java.util.Map)3 Location (org.bukkit.Location)3 ItemStack (org.bukkit.inventory.ItemStack)3 CastingCost (com.elmakers.mine.bukkit.api.spell.CastingCost)2 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)2 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)2 File (java.io.File)2 Nullable (javax.annotation.Nullable)2 Block (org.bukkit.block.Block)2 Player (org.bukkit.entity.Player)2 ActionHandler (com.elmakers.mine.bukkit.action.ActionHandler)1