Search in sources :

Example 41 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project TotalFreedomMod by TotalFreedom.

the class ConfigConverter method convertSuperadmins.

private void convertSuperadmins(File oldFile) {
    if (!oldFile.exists() || !oldFile.isFile()) {
        logger.warning("No old superadmin list found!");
        return;
    }
    // Convert old admin list
    YamlConfig oldYaml = new YamlConfig(plugin, oldFile, false);
    oldYaml.load();
    ConfigurationSection admins = oldYaml.getConfigurationSection("admins");
    if (admins == null) {
        logger.warning("No admin section in superadmin list!");
        return;
    }
    List<Admin> conversions = Lists.newArrayList();
    for (String uuid : admins.getKeys(false)) {
        ConfigurationSection asec = admins.getConfigurationSection(uuid);
        if (asec == null) {
            logger.warning("Invalid superadmin format for admin: " + uuid);
            continue;
        }
        String username = asec.getString("last_login_name");
        Rank rank;
        if (asec.getBoolean("is_senior_admin")) {
            rank = Rank.SENIOR_ADMIN;
        } else if (asec.getBoolean("is_telnet_admin")) {
            rank = Rank.TELNET_ADMIN;
        } else {
            rank = Rank.SUPER_ADMIN;
        }
        List<String> ips = asec.getStringList("ips");
        String loginMessage = asec.getString("custom_login_message");
        boolean active = asec.getBoolean("is_activated");
        Admin admin = new Admin(username);
        admin.setName(username);
        admin.setRank(rank);
        admin.addIps(ips);
        admin.setLoginMessage(loginMessage);
        admin.setActive(active);
        admin.setLastLogin(new Date());
        conversions.add(admin);
    }
    YamlConfig newYaml = new YamlConfig(plugin, AdminList.CONFIG_FILENAME);
    for (Admin admin : conversions) {
        admin.saveTo(newYaml.createSection(admin.getName().toLowerCase()));
    }
    newYaml.save();
    logger.info("Converted " + conversions.size() + " admins");
}
Also used : YamlConfig(net.pravian.aero.config.YamlConfig) Rank(me.totalfreedom.totalfreedommod.rank.Rank) Admin(me.totalfreedom.totalfreedommod.admin.Admin) Date(java.util.Date) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 42 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection in project TotalFreedomMod by TotalFreedom.

the class AdminList method load.

public void load() {
    config.load();
    allAdmins.clear();
    for (String key : config.getKeys(false)) {
        ConfigurationSection section = config.getConfigurationSection(key);
        if (section == null) {
            logger.warning("Invalid admin list format: " + key);
            continue;
        }
        Admin admin = new Admin(key);
        admin.loadFrom(section);
        if (!admin.isValid()) {
            FLog.warning("Could not load admin: " + key + ". Missing details!");
            continue;
        }
        allAdmins.put(key, admin);
    }
    updateTables();
    FLog.info("Loaded " + allAdmins.size() + " admins (" + nameTable.size() + " active,  " + ipTable.size() + " IPs)");
}
Also used : ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 43 with ConfigurationSection

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

the class Settings method _getCommandCooldowns.

private Map<Pattern, Long> _getCommandCooldowns() {
    if (!config.isConfigurationSection("command-cooldowns")) {
        return null;
    }
    ConfigurationSection section = config.getConfigurationSection("command-cooldowns");
    Map<Pattern, Long> result = new LinkedHashMap<>();
    for (String cmdEntry : section.getKeys(false)) {
        Pattern pattern = null;
        /* ================================
             * >> Regex
             * ================================ */
        if (cmdEntry.startsWith("^")) {
            try {
                pattern = Pattern.compile(cmdEntry.substring(1));
            } catch (PatternSyntaxException e) {
                ess.getLogger().warning("Command cooldown error: " + e.getMessage());
            }
        } else {
            // Escape above Regex
            if (cmdEntry.startsWith("\\^")) {
                cmdEntry = cmdEntry.substring(1);
            }
            String cmd = cmdEntry.replaceAll("\\*", // Wildcards are accepted as asterisk * as known universally.
            ".*");
            // This matches arguments, if present, to "ignore" them from the feature.
            pattern = Pattern.compile(cmd + "( .*)?");
        }
        /* ================================
             * >> Process cooldown value
             * ================================ */
        Object value = section.get(cmdEntry);
        if (!(value instanceof Number) && value instanceof String) {
            try {
                value = Double.parseDouble(value.toString());
            } catch (NumberFormatException ignored) {
            }
        }
        if (!(value instanceof Number)) {
            ess.getLogger().warning("Command cooldown error: '" + value + "' is not a valid cooldown");
            continue;
        }
        double cooldown = ((Number) value).doubleValue();
        if (cooldown < 1) {
            ess.getLogger().warning("Command cooldown with very short " + cooldown + " cooldown.");
        }
        // convert to milliseconds
        result.put(pattern, (long) cooldown * 1000);
    }
    return result;
}
Also used : Pattern(java.util.regex.Pattern) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 44 with ConfigurationSection

use of org.bukkit.configuration.ConfigurationSection 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)

Example 45 with ConfigurationSection

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

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.getSettings().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));
        gist(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)

Aggregations

ConfigurationSection (org.bukkit.configuration.ConfigurationSection)49 ItemStack (org.bukkit.inventory.ItemStack)7 IOException (java.io.IOException)6 Material (org.bukkit.Material)6 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)6 File (java.io.File)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)3 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)3 EntityType (org.bukkit.entity.EntityType)3 Rewards (au.com.mineauz.minigames.minigame.reward.Rewards)2 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)2 BigDecimal (java.math.BigDecimal)2 Enchantment (org.bukkit.enchantments.Enchantment)2 SQLiteBackend (au.com.mineauz.minigames.backend.sqlite.SQLiteBackend)1 MenuItemRewardGroup (au.com.mineauz.minigames.menu.MenuItemRewardGroup)1 LoadoutAddon (au.com.mineauz.minigames.minigame.modules.LoadoutModule.LoadoutAddon)1 StandardRewardScheme (au.com.mineauz.minigames.minigame.reward.scheme.StandardRewardScheme)1 NoChargeException (com.earth2me.essentials.commands.NoChargeException)1