Search in sources :

Example 86 with ConfigurationSection

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

the class WandUpgradePath method upgradeTo.

protected void upgradeTo(com.elmakers.mine.bukkit.api.wand.Wand wand) {
    wand.setPath(getKey());
    boolean addedProperties = false;
    ConfigurationSection wandProperties = new MemoryConfiguration();
    int manaRegeneration = wand.getManaRegeneration();
    if (this.manaRegeneration > 0 && maxManaRegeneration == 0 && this.manaRegeneration > manaRegeneration) {
        addedProperties = true;
        wandProperties.set("mana_regeneration", this.manaRegeneration);
    }
    int manaMax = wand.getManaMax();
    if (this.maxMana > 0 && maxMaxMana == 0 && this.maxMana > manaMax) {
        addedProperties = true;
        wandProperties.set("mana_max", this.maxMana);
    }
    if (addedProperties) {
        wand.upgrade(wandProperties);
    }
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 87 with ConfigurationSection

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

the class PhaseSpell method onCast.

@Override
public SpellResult onCast(ConfigurationSection parameters) {
    Location targetLocation = null;
    Target target = getTarget();
    Entity e = target.getEntity();
    LivingEntity entity = e != null && e instanceof LivingEntity ? (LivingEntity) e : null;
    if (entity == null) {
        return SpellResult.NO_TARGET;
    }
    if (entity != mage.getEntity() && controller.isMage(entity)) {
        Mage mage = controller.getMage(entity);
        if (mage.isSuperProtected()) {
            return SpellResult.NO_TARGET;
        }
    }
    Location playerLocation = entity.getLocation();
    String worldName = playerLocation.getWorld().getName();
    if (parameters.contains("target_world")) {
        World targetWorld = getWorld(parameters.getString("target_world"), parameters.getBoolean("load", true));
        if (targetWorld == null) {
            return SpellResult.INVALID_WORLD;
        }
        float scale = (float) parameters.getDouble("scale", 1.0f);
        if (targetWorld.getEnvironment() == World.Environment.THE_END) {
            targetLocation = targetWorld.getSpawnLocation();
        } else {
            targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
        }
    } else if (parameters.contains("worlds")) {
        ConfigurationSection worldMap = parameters.getConfigurationSection("worlds");
        if (!worldMap.contains(worldName)) {
            return SpellResult.NO_TARGET;
        }
        ConfigurationSection worldNode = worldMap.getConfigurationSection(worldName);
        World targetWorld = getWorld(worldNode.getString("target"), worldNode.getBoolean("load", true));
        float scale = (float) worldNode.getDouble("scale", 1.0f);
        if (targetWorld != null) {
            targetLocation = new Location(targetWorld, playerLocation.getX() * scale, playerLocation.getY(), playerLocation.getZ() * scale);
        }
    } else {
        if (worldName.contains("_the_end")) {
            worldName = worldName.replace("_the_end", "");
            World targetWorld = Bukkit.getWorld(worldName);
            if (targetWorld != null) {
                // No scaling here?
                // Just send them to spawn... this is kind of to fix players finding the real spawn
                // on my own server, but I'm not just sure how best to handle this anyway.
                targetLocation = targetWorld.getSpawnLocation();
            }
        } else if (worldName.contains("_nether")) {
            worldName = worldName.replace("_nether", "");
            World targetWorld = Bukkit.getWorld(worldName);
            if (targetWorld != null) {
                targetLocation = new Location(targetWorld, playerLocation.getX() * 8, playerLocation.getY(), playerLocation.getZ() * 8);
            }
        } else {
            worldName = worldName + "_nether";
            World targetWorld = Bukkit.getWorld(worldName);
            if (targetWorld != null) {
                targetLocation = new Location(targetWorld, playerLocation.getX() / 8, Math.min(125, playerLocation.getY()), playerLocation.getZ() / 8);
            }
        }
    }
    if (targetLocation == null) {
        return SpellResult.NO_TARGET;
    }
    retryCount = 0;
    tryPhase(entity, targetLocation);
    return SpellResult.CAST;
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage) World(org.bukkit.World) Location(org.bukkit.Location) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 88 with ConfigurationSection

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

the class SimulateSpell method loadTemplate.

@Override
protected void loadTemplate(ConfigurationSection template) {
    super.loadTemplate(template);
    if (template.contains("levels")) {
        ConfigurationSection levelTemplate = template.getConfigurationSection("levels");
        Collection<String> levelKeys = levelTemplate.getKeys(false);
        List<Integer> levels = new ArrayList<>(levelKeys.size());
        for (String levelString : levelKeys) {
            levels.add(Integer.parseInt(levelString));
        }
        if (levels.size() == 0)
            return;
        levelMap = new TreeMap<>();
        Collections.sort(levels);
        Integer[] levelsArray = levels.toArray(emptyList);
        for (int level = 1; level <= levelsArray[levelsArray.length - 1]; level++) {
            levelMap.put(level, new AutomatonLevel(level, levelsArray, template));
        }
    } else {
        levelMap = new TreeMap<>();
        levelMap.put(1, new AutomatonLevel(1, null, template));
    }
}
Also used : ArrayList(java.util.ArrayList) AutomatonLevel(com.elmakers.mine.bukkit.block.AutomatonLevel) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 89 with ConfigurationSection

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

the class Messages method load.

public void load(ConfigurationSection messages) {
    configuration = messages;
    Collection<String> keys = messages.getKeys(true);
    for (String key : keys) {
        if (key.equals("randomized")) {
            ConfigurationSection randomSection = messages.getConfigurationSection(key);
            Set<String> randomKeys = randomSection.getKeys(false);
            for (String randomKey : randomKeys) {
                randomized.put(randomKey, randomSection.getStringList(randomKey));
            }
        } else if (messages.isString(key)) {
            String value = messages.getString(key);
            value = ChatColor.translateAlternateColorCodes('&', StringEscapeUtils.unescapeHtml(value));
            messageMap.put(key, value);
        }
    }
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 90 with ConfigurationSection

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

the class ActionHandler method load.

public void load(Spell spell, ConfigurationSection root, String key) {
    undoable = false;
    usesBrush = false;
    requiresBuildPermission = false;
    requiresBreakPermission = false;
    ConfigurationSection handlerConfiguration = (spell != null) ? spell.getHandlerParameters(key) : null;
    Collection<ConfigurationSection> actionNodes = ConfigurationUtils.getNodeList(root, key);
    if (actionNodes == null) {
        return;
    }
    for (ConfigurationSection actionConfiguration : actionNodes) {
        if (!actionConfiguration.contains("class")) {
            continue;
        }
        String actionClassName = actionConfiguration.getString("class");
        try {
            BaseSpellAction action = ActionFactory.construct(actionClassName);
            actionConfiguration.set("class", null);
            if (handlerConfiguration != null) {
                ConfigurationUtils.addConfigurations(actionConfiguration, handlerConfiguration, false);
            }
            if (actionConfiguration.getKeys(false).size() == 0) {
                actionConfiguration = null;
            }
            loadAction(action, actionConfiguration);
        } catch (Exception ex) {
            Bukkit.getLogger().warning("Error loading class " + actionClassName + " for spell " + spell.getName() + ": " + ex.getMessage());
        }
    }
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)263 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)29 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)27 ItemStack (org.bukkit.inventory.ItemStack)26 File (java.io.File)22 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)22 IOException (java.io.IOException)21 Map (java.util.Map)18 Mage (com.elmakers.mine.bukkit.api.magic.Mage)17 Material (org.bukkit.Material)16 Nullable (javax.annotation.Nullable)14 Location (org.bukkit.Location)13 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)11 MaterialAndData (com.elmakers.mine.bukkit.block.MaterialAndData)10 Player (org.bukkit.entity.Player)10 EntityType (org.bukkit.entity.EntityType)9 List (java.util.List)8 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)7 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)7