Search in sources :

Example 11 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration 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 12 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project NoCheatPlus by NoCheatPlus.

the class PathUtils method getWorldsDefaultConfig.

/**
 * A config file only containing the entries that are not set as global only.
 * @param defaultConfig
 * @return
 */
public static MemoryConfiguration getWorldsDefaultConfig(final MemoryConfiguration defaultConfig) {
    final char sep = defaultConfig.options().pathSeparator();
    final MemoryConfiguration config = new ConfigFile();
    config.options().pathSeparator(sep);
    final Map<String, Object> defaults = defaultConfig.getValues(false);
    for (final Entry<String, Object> entry : defaults.entrySet()) {
        final String part = entry.getKey();
        if (!part.isEmpty() && !mayBeInWorldConfig(part)) {
            continue;
        }
        final Object value = entry.getValue();
        if (value instanceof ConfigurationSection) {
            addWorldConfigSection(config, (ConfigurationSection) value, part, sep);
        } else {
            config.set(part, value);
        }
    }
    return config;
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 13 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project Essentials by EssentialsX.

the class Commandcreatekit method run.

// /createkit <name> <delay>
@Override
public void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
    if (args.length != 2) {
        throw new NotEnoughArgumentsException();
    }
    // Command handler will auto fail if this fails.
    long delay = Long.valueOf(args[1]);
    String kitname = args[0];
    ItemStack[] items = user.getBase().getInventory().getContents();
    List<String> list = new ArrayList<>();
    for (ItemStack is : items) {
        if (is != null && is.getType() != null && is.getType() != Material.AIR) {
            String serialized = ess.getItemDb().serialize(is);
            list.add(serialized);
        }
    }
    // Some users might want to directly write to config knowing the consequences. *shrug*
    if (!ess.getSettings().isPastebinCreateKit()) {
        ess.getKits().addKit(kitname, list, delay);
        user.sendMessage(tl("createdKit", kitname, list.size(), delay));
    } else {
        ConfigurationSection config = new MemoryConfiguration();
        config.set("kits." + kitname + ".delay", delay);
        config.set("kits." + kitname + ".items", list);
        final Yaml yaml = new Yaml(yamlConstructor, yamlRepresenter, yamlOptions);
        String fileContents = "# Copy the kit code below into the kits section in your config.yml file\n";
        fileContents += yaml.dump(config.getValues(false));
        uploadPaste(user.getSource(), kitname, delay, fileContents);
    }
}
Also used : ArrayList(java.util.ArrayList) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ItemStack(org.bukkit.inventory.ItemStack) Yaml(org.yaml.snakeyaml.Yaml) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 14 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project Essentials by drtshock.

the class Kits method _getKits.

private ConfigurationSection _getKits() {
    if (config.isConfigurationSection("kits")) {
        final ConfigurationSection section = config.getConfigurationSection("kits");
        final ConfigurationSection newSection = new MemoryConfiguration();
        for (String kitItem : section.getKeys(false)) {
            if (section.isConfigurationSection(kitItem)) {
                newSection.set(kitItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(kitItem));
            }
        }
        return newSection;
    }
    return null;
}
Also used : MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 15 with MemoryConfiguration

use of org.bukkit.configuration.MemoryConfiguration in project Essentials by drtshock.

the class Settings method _getKits.

private ConfigurationSection _getKits() {
    if (config.isConfigurationSection("kits")) {
        final ConfigurationSection section = config.getConfigurationSection("kits");
        final ConfigurationSection newSection = new MemoryConfiguration();
        for (String kitItem : section.getKeys(false)) {
            if (section.isConfigurationSection(kitItem)) {
                newSection.set(kitItem.toLowerCase(Locale.ENGLISH), section.getConfigurationSection(kitItem));
            }
        }
        return newSection;
    }
    return null;
}
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