Search in sources :

Example 16 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class MessageFilePlaceholderTest method shouldHaveAllPlaceholders.

@Test
public void shouldHaveAllPlaceholders() {
    // given
    FileConfiguration configuration = YamlConfiguration.loadConfiguration(messagesFile);
    List<String> errors = new ArrayList<>();
    // when
    for (MessageKey key : MessageKey.values()) {
        List<String> missingTags = findMissingTags(key, configuration);
        if (!missingTags.isEmpty()) {
            errors.add("Message key '" + key + "' should have tags: " + String.join(", ", missingTags));
        }
    }
    // then
    if (!errors.isEmpty()) {
        fail("Errors while validating '" + messagesFilename + "':\n- " + String.join("\n- ", errors));
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 17 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class PermissionConsistencyTest method getPermissionsFromPluginYmlFile.

/**
     * Returns all permission entries from the plugin.yml file.
     *
     * @return map with the permission entries by permission node
     */
private static Map<String, PermissionDefinition> getPermissionsFromPluginYmlFile() {
    FileConfiguration pluginFile = YamlConfiguration.loadConfiguration(getJarFile("/plugin.yml"));
    MemorySection permsList = (MemorySection) pluginFile.get("permissions");
    Map<String, PermissionDefinition> permissions = new HashMap<>();
    addChildren(permsList, permissions);
    return ImmutableMap.copyOf(permissions);
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) MemorySection(org.bukkit.configuration.MemorySection) HashMap(java.util.HashMap)

Example 18 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project AuthMeReloaded by AuthMe.

the class RoyalAuthConverter method execute.

@Override
public void execute(CommandSender sender) {
    for (OfflinePlayer player : plugin.getServer().getOfflinePlayers()) {
        try {
            String name = player.getName().toLowerCase();
            File file = new File(makePath(".", "plugins", "RoyalAuth", "userdata", name + ".yml"));
            if (dataSource.isAuthAvailable(name) || !file.exists()) {
                continue;
            }
            FileConfiguration configuration = YamlConfiguration.loadConfiguration(file);
            PlayerAuth auth = PlayerAuth.builder().name(name).password(configuration.getString(PASSWORD_PATH), null).lastLogin(configuration.getLong(LAST_LOGIN_PATH)).realName(player.getName()).build();
            dataSource.saveAuth(auth);
        } catch (Exception e) {
            ConsoleLogger.logException("Error while trying to import " + player.getName() + " RoyalAuth data", e);
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) OfflinePlayer(org.bukkit.OfflinePlayer) PlayerAuth(fr.xephi.authme.data.auth.PlayerAuth) File(java.io.File)

Example 19 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project EliteMobs by MagmaGuy.

the class CustomConfigConstructor method reload.

/**
     * Reload configuration
     */
public void reload() {
    if (!file.exists()) {
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
        } catch (IOException exception) {
            exception.printStackTrace();
            plugin.getLogger().severe("Error while creating file " + file.getName());
        }
    }
    try {
        load(file);
        if (defaults != null) {
            InputStreamReader reader = new InputStreamReader(plugin.getResource(defaults));
            FileConfiguration defaultsConfig = YamlConfiguration.loadConfiguration(reader);
            setDefaults(defaultsConfig);
            options().copyDefaults(true);
            reader.close();
            save();
        }
    } catch (IOException exception) {
        exception.printStackTrace();
        plugin.getLogger().severe("Error while loading file " + file.getName());
    } catch (InvalidConfigurationException exception) {
        exception.printStackTrace();
        plugin.getLogger().severe("Error while loading file " + file.getName());
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) InputStreamReader(java.io.InputStreamReader) IOException(java.io.IOException) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 20 with FileConfiguration

use of org.bukkit.configuration.file.FileConfiguration in project MyPet by xXKeyleXx.

the class WorldListener method on.

@EventHandler
public void on(WorldInitEvent event) {
    if (WorldGroup.getGroupByWorld(event.getWorld().getName()) == null) {
        WorldGroup defaultGroup = WorldGroup.getGroupByName("default");
        if (defaultGroup == null) {
            defaultGroup = new WorldGroup("default");
            defaultGroup.registerGroup();
        }
        if (defaultGroup.addWorld(event.getWorld().getName())) {
            File groupsFile = new File(MyPetApi.getPlugin().getDataFolder().getPath() + File.separator + "worldgroups.yml");
            ConfigurationYAML yamlConfiguration = new ConfigurationYAML(groupsFile);
            FileConfiguration config = yamlConfiguration.getConfig();
            config.set("Groups.default", defaultGroup.getWorlds());
            yamlConfiguration.saveConfig();
            MyPetApi.getLogger().info("added " + ChatColor.YELLOW + event.getWorld().getName() + ChatColor.RESET + " to '" + ChatColor.YELLOW + "default" + ChatColor.RESET + "' group.");
        } else {
            MyPetApi.getLogger().warning("An error occured while adding " + ChatColor.YELLOW + event.getWorld().getName() + ChatColor.RESET + " to '" + ChatColor.YELLOW + "default" + ChatColor.RESET + "' group. Please restart the server.");
        }
    }
}
Also used : FileConfiguration(org.bukkit.configuration.file.FileConfiguration) WorldGroup(de.Keyle.MyPet.api.WorldGroup) ConfigurationYAML(de.Keyle.MyPet.api.util.configuration.ConfigurationYAML) File(java.io.File) EventHandler(org.bukkit.event.EventHandler)

Aggregations

FileConfiguration (org.bukkit.configuration.file.FileConfiguration)36 File (java.io.File)11 IOException (java.io.IOException)6 Test (org.junit.Test)6 ArrayList (java.util.ArrayList)5 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)5 MinigameSave (au.com.mineauz.minigames.MinigameSave)4 HashMap (java.util.HashMap)4 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)4 Map (java.util.Map)3 MemorySection (org.bukkit.configuration.MemorySection)3 Player (org.bukkit.entity.Player)3 RewardsFlag (au.com.mineauz.minigames.config.RewardsFlag)2 MenuItemString (au.com.mineauz.minigames.menu.MenuItemString)2 MinigameModule (au.com.mineauz.minigames.minigame.modules.MinigameModule)2 DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 ConfigurationYAML (de.Keyle.MyPet.api.util.configuration.ConfigurationYAML)2 InputStreamReader (java.io.InputStreamReader)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2