Search in sources :

Example 21 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Jobs by GamingMesh.

the class JobsConfiguration method loadGeneralSettings.

/**
     * Method to load the general configuration
     * 
     * loads from Jobs/generalConfig.yml
     */
private synchronized void loadGeneralSettings() {
    File f = new File(plugin.getDataFolder(), "generalConfig.yml");
    YamlConfiguration config = YamlConfiguration.loadConfiguration(f);
    CommentedYamlConfiguration writer = new CommentedYamlConfiguration();
    StringBuilder header = new StringBuilder();
    header.append("General configuration.");
    header.append(System.getProperty("line.separator"));
    header.append("  The general configuration for the jobs plugin mostly includes how often the plugin");
    header.append(System.getProperty("line.separator"));
    header.append("saves user data (when the user is in the game), the storage method, whether");
    header.append(System.getProperty("line.separator"));
    header.append("to broadcast a message to the server when a user goes up a skill level.");
    header.append(System.getProperty("line.separator"));
    header.append("  It also allows admins to set the maximum number of jobs a player can have at");
    header.append(System.getProperty("line.separator"));
    header.append("any one time.");
    header.append(System.getProperty("line.separator"));
    config.options().copyDefaults(true);
    writer.options().header(header.toString());
    writer.addComment("locale-language", "Default language.  Use your languages two digit ISO 639-1 code, and optionally followed by the ISO-3166-1 country code.", "Example: en, en_US");
    config.addDefault("locale-language", Locale.getDefault().getLanguage());
    writer.addComment("storage-method", "storage method, can be MySQL, sqlite");
    config.addDefault("storage-method", "sqlite");
    writer.addComment("mysql-username", "Requires Mysql.");
    config.addDefault("mysql-username", "root");
    config.addDefault("mysql-password", "");
    config.addDefault("mysql-hostname", "localhost:3306");
    config.addDefault("mysql-database", "minecraft");
    config.addDefault("mysql-table-prefix", "jobs_");
    writer.addComment("save-period", "How often in minutes you want it to save.  This must be a non-zero number");
    config.addDefault("save-period", 10);
    writer.addComment("save-on-disconnect", "Should player data be saved on disconnect?", "Player data is always periodically auto-saved and autosaved during a clean shutdown.", "Only enable this if you have a multi-server setup, or have a really good reason for enabling this.", "Turning this on will decrease database performance.");
    config.addDefault("save-on-disconnect", false);
    writer.addComment("broadcast-on-skill-up", "Do all players get a message when somone goes up a skill level?");
    config.addDefault("broadcast-on-skill-up", false);
    writer.addComment("broadcast-on-level-up", "Do all players get a message when somone goes up a level?");
    config.addDefault("broadcast-on-level-up", false);
    writer.addComment("max-jobs", "Maximum number of jobs a player can join.", "Use 0 for no maximum");
    config.addDefault("max-jobs", 3);
    writer.addComment("hide-jobs-without-permission", "Hide jobs from player if they lack the permission to join the job");
    config.addDefault("hide-jobs-without-permission", false);
    writer.addComment("enable-pay-near-spawner", "option to allow payment to be made when killing mobs from a spawner");
    config.addDefault("enable-pay-near-spawner", false);
    writer.addComment("enable-pay-creative", "option to allow payment to be made in creative mode");
    config.addDefault("enable-pay-creative", false);
    writer.addComment("add-xp-player", "Adds the Jobs xp recieved to the player's Minecraft XP bar");
    config.addDefault("add-xp-player", false);
    writer.addComment("modify-chat", "Modifys chat to add chat titles.  If you're using a chat manager, you may add the tag {jobs} to your chat format and disable this.");
    config.addDefault("modify-chat", true);
    writer.addComment("economy-batch-delay", "Changes how often, in seconds, players are paid out.  Default is 5 seconds.", "Setting this too low may cause tick lag.  Increase this to improve economy performance (at the cost of delays in payment)");
    config.addDefault("economy-batch-delay", 5);
    writer.addComment("economy-async", "Enable async economy calls.", "Only enable if your economy plugin is thread safe, use with EXTREME caution.");
    config.addDefault("economy-async", false);
    String storageMethod = config.getString("storage-method");
    if (storageMethod.equalsIgnoreCase("mysql")) {
        String legacyUrl = config.getString("mysql-url");
        if (legacyUrl != null) {
            String jdbcString = "jdbc:mysql://";
            if (legacyUrl.toLowerCase().startsWith(jdbcString)) {
                legacyUrl = legacyUrl.substring(jdbcString.length());
                String[] parts = legacyUrl.split("/");
                if (parts.length >= 2) {
                    config.set("mysql-hostname", parts[0]);
                    config.set("mysql-database", parts[1]);
                }
            }
        }
        String username = config.getString("mysql-username");
        if (username == null) {
            Jobs.getPluginLogger().severe("mysql-username property invalid or missing");
        }
        String password = config.getString("mysql-password");
        String hostname = config.getString("mysql-hostname");
        String database = config.getString("mysql-database");
        String prefix = config.getString("mysql-table-prefix");
        if (plugin.isEnabled())
            Jobs.setDAO(JobsDAOMySQL.initialize(hostname, database, username, password, prefix));
    } else if (storageMethod.equalsIgnoreCase("h2")) {
        File h2jar = new File(plugin.getDataFolder(), "h2.jar");
        Jobs.getPluginLogger().warning("H2 database no longer supported!  Converting to SQLite.");
        if (!h2jar.exists()) {
            Jobs.getPluginLogger().info("H2 library not found, downloading...");
            try {
                FileDownloader.downloadFile(new URL("http://dev.bukkit.org/media/files/692/88/h2-1.3.171.jar"), h2jar);
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                Jobs.getPluginLogger().severe("Could not download database library!");
            }
        }
        if (plugin.isEnabled()) {
            try {
                Jobs.getJobsClassloader().addFile(h2jar);
            } catch (IOException e) {
                Jobs.getPluginLogger().severe("Could not load database library!");
            }
            if (plugin.isEnabled()) {
                try {
                    JobsDAOH2.convertToSQLite();
                    Jobs.setDAO(JobsDAOSQLite.initialize());
                    config.set("storage-method", "sqlite");
                } catch (SQLException e) {
                    Jobs.getPluginLogger().severe("Error when converting from H2 to SQLite!");
                    e.printStackTrace();
                }
            }
        }
    } else if (storageMethod.equalsIgnoreCase("sqlite")) {
        Jobs.setDAO(JobsDAOSQLite.initialize());
    } else {
        Jobs.getPluginLogger().warning("Invalid storage method!  Changing method to sqlite!");
        config.set("storage-method", "sqlite");
        Jobs.setDAO(JobsDAOSQLite.initialize());
    }
    if (config.getInt("save-period") <= 0) {
        Jobs.getPluginLogger().severe("Save period must be greater than 0!  Defaulting to 10 minutes!");
        config.set("save-period", 10);
    }
    String localeString = config.getString("locale-language");
    try {
        int i = localeString.indexOf('_');
        if (i == -1) {
            locale = new Locale(localeString);
        } else {
            locale = new Locale(localeString.substring(0, i), localeString.substring(i + 1));
        }
    } catch (IllegalArgumentException e) {
        locale = Locale.getDefault();
        Jobs.getPluginLogger().warning("Invalid locale \"" + localeString + "\" defaulting to " + locale.getLanguage());
    }
    savePeriod = config.getInt("save-period");
    economyAsync = config.getBoolean("economy-async");
    isBroadcastingSkillups = config.getBoolean("broadcast-on-skill-up");
    isBroadcastingLevelups = config.getBoolean("broadcast-on-level-up");
    payInCreative = config.getBoolean("enable-pay-creative");
    addXpPlayer = config.getBoolean("add-xp-player");
    hideJobsWithoutPermission = config.getBoolean("hide-jobs-without-permission");
    maxJobs = config.getInt("max-jobs");
    payNearSpawner = config.getBoolean("enable-pay-near-spawner");
    modifyChat = config.getBoolean("modify-chat");
    economyBatchDelay = config.getInt("economy-batch-delay");
    saveOnDisconnect = config.getBoolean("save-on-disconnect");
    // Make sure we're only copying settings we care about
    copySetting(config, writer, "locale-language");
    copySetting(config, writer, "storage-method");
    copySetting(config, writer, "mysql-username");
    copySetting(config, writer, "mysql-password");
    copySetting(config, writer, "mysql-hostname");
    copySetting(config, writer, "mysql-database");
    copySetting(config, writer, "mysql-table-prefix");
    copySetting(config, writer, "save-period");
    copySetting(config, writer, "save-on-disconnect");
    copySetting(config, writer, "broadcast-on-skill-up");
    copySetting(config, writer, "broadcast-on-level-up");
    copySetting(config, writer, "max-jobs");
    copySetting(config, writer, "hide-jobs-without-permission");
    copySetting(config, writer, "enable-pay-near-spawner");
    copySetting(config, writer, "enable-pay-creative");
    copySetting(config, writer, "add-xp-player");
    copySetting(config, writer, "modify-chat");
    copySetting(config, writer, "economy-batch-delay");
    copySetting(config, writer, "economy-async");
    // Write back config
    try {
        writer.save(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Locale(java.util.Locale) MalformedURLException(java.net.MalformedURLException) SQLException(java.sql.SQLException) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) URL(java.net.URL) File(java.io.File)

Example 22 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Jobs by GamingMesh.

the class JobsConfiguration method loadTitleSettings.

/**
     * Method to load the title configuration
     * 
     * loads from Jobs/titleConfig.yml
     */
private synchronized void loadTitleSettings() {
    this.titles.clear();
    File f = new File(plugin.getDataFolder(), "titleConfig.yml");
    YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
    StringBuilder header = new StringBuilder().append("Title configuration").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Stores the titles people gain at certain levels.").append(System.getProperty("line.separator")).append("Each title requres to have a name, short name (used when the player has more than").append(System.getProperty("line.separator")).append("1 job) the colour of the title and the level requrirement to attain the title.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("It is recommended but not required to have a title at level 0.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Titles are completely optional.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Titles:").append(System.getProperty("line.separator")).append("  Apprentice:").append(System.getProperty("line.separator")).append("    Name: Apprentice").append(System.getProperty("line.separator")).append("    ShortName: A").append(System.getProperty("line.separator")).append("    ChatColour: WHITE").append(System.getProperty("line.separator")).append("    levelReq: 0").append(System.getProperty("line.separator")).append("  Novice:").append(System.getProperty("line.separator")).append("    Name: Novice").append(System.getProperty("line.separator")).append("    ShortName: N").append(System.getProperty("line.separator")).append("    ChatColour: GRAY").append(System.getProperty("line.separator")).append("    levelReq: 30").append(System.getProperty("line.separator")).append("  Journeyman:").append(System.getProperty("line.separator")).append("    Name: Journeyman").append(System.getProperty("line.separator")).append("    ShortName: J").append(System.getProperty("line.separator")).append("    ChatColour: GOLD").append(System.getProperty("line.separator")).append("    levelReq: 60").append(System.getProperty("line.separator")).append("  Master:").append(System.getProperty("line.separator")).append("    Name: Master").append(System.getProperty("line.separator")).append("    ShortName: M").append(System.getProperty("line.separator")).append("    ChatColour: BLACK").append(System.getProperty("line.separator")).append("    levelReq: 90").append(System.getProperty("line.separator")).append(System.getProperty("line.separator"));
    conf.options().header(header.toString());
    conf.options().copyDefaults(true);
    conf.options().indent(2);
    ConfigurationSection titleSection = conf.getConfigurationSection("Titles");
    if (titleSection == null) {
        titleSection = conf.createSection("Titles");
    }
    for (String titleKey : titleSection.getKeys(false)) {
        String titleName = conf.getString("Titles." + titleKey + ".Name");
        String titleShortName = conf.getString("Titles." + titleKey + ".ShortName");
        ChatColor titleColor = ChatColor.matchColor(conf.getString("Titles." + titleKey + ".ChatColour", ""));
        int levelReq = conf.getInt("Titles." + titleKey + ".levelReq", -1);
        if (titleName == null) {
            Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid Name property. Skipping!");
            continue;
        }
        if (titleShortName == null) {
            Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid ShortName property. Skipping!");
            continue;
        }
        if (titleColor == null) {
            Jobs.getPluginLogger().severe("Title " + titleKey + "has an invalid ChatColour property. Skipping!");
            continue;
        }
        if (levelReq <= -1) {
            Jobs.getPluginLogger().severe("Title " + titleKey + " has an invalid levelReq property. Skipping!");
            continue;
        }
        this.titles.add(new Title(titleName, titleShortName, titleColor, levelReq));
    }
    try {
        conf.save(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : Title(com.gamingmesh.jobs.container.Title) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) ChatColor(com.gamingmesh.jobs.util.ChatColor) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 23 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Jobs by GamingMesh.

the class JobsConfiguration method loadRestrictedAreaSettings.

/**
     * Method to load the restricted areas configuration
     * 
     * loads from Jobs/restrictedAreas.yml
     */
private synchronized void loadRestrictedAreaSettings() {
    this.restrictedAreas.clear();
    File f = new File(plugin.getDataFolder(), "restrictedAreas.yml");
    YamlConfiguration conf = YamlConfiguration.loadConfiguration(f);
    conf.options().indent(2);
    conf.options().copyDefaults(true);
    StringBuilder header = new StringBuilder();
    header.append("Restricted area configuration").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("Configures restricted areas where you cannot get experience or money").append(System.getProperty("line.separator")).append("when performing a job.").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("The multiplier changes the experience/money gains in an area.").append(System.getProperty("line.separator")).append("A multiplier of 0.0 means no money or xp, while 0.5 means you will get half the normal money/exp").append(System.getProperty("line.separator")).append(System.getProperty("line.separator")).append("restrictedareas:").append(System.getProperty("line.separator")).append("  area1:").append(System.getProperty("line.separator")).append("    world: 'world'").append(System.getProperty("line.separator")).append("    multiplier: 0.0").append(System.getProperty("line.separator")).append("    point1:").append(System.getProperty("line.separator")).append("      x: 125").append(System.getProperty("line.separator")).append("      y: 0").append(System.getProperty("line.separator")).append("      z: 125").append(System.getProperty("line.separator")).append("    point2:").append(System.getProperty("line.separator")).append("      x: 150").append(System.getProperty("line.separator")).append("      y: 100").append(System.getProperty("line.separator")).append("      z: 150").append(System.getProperty("line.separator")).append("  area2:").append(System.getProperty("line.separator")).append("    world: 'world_nether'").append(System.getProperty("line.separator")).append("    multiplier: 0.0").append(System.getProperty("line.separator")).append("    point1:").append(System.getProperty("line.separator")).append("      x: -100").append(System.getProperty("line.separator")).append("      y: 0").append(System.getProperty("line.separator")).append("      z: -100").append(System.getProperty("line.separator")).append("    point2:").append(System.getProperty("line.separator")).append("      x: -150").append(System.getProperty("line.separator")).append("      y: 100").append(System.getProperty("line.separator")).append("      z: -150");
    conf.options().header(header.toString());
    ConfigurationSection areaSection = conf.getConfigurationSection("restrictedareas");
    if (areaSection != null) {
        for (String areaKey : areaSection.getKeys(false)) {
            String worldName = conf.getString("restrictedareas." + areaKey + ".world");
            double multiplier = conf.getDouble("restrictedareas." + areaKey + ".multiplier", 0.0);
            World world = Bukkit.getServer().getWorld(worldName);
            if (world == null)
                continue;
            Location point1 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point1.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point1.z", 0.0));
            Location point2 = new Location(world, conf.getDouble("restrictedareas." + areaKey + ".point2.x", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.y", 0.0), conf.getDouble("restrictedareas." + areaKey + ".point2.z", 0.0));
            this.restrictedAreas.add(new RestrictedArea(point1, point2, multiplier));
        }
    }
    try {
        conf.save(f);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : RestrictedArea(com.gamingmesh.jobs.container.RestrictedArea) IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) World(org.bukkit.World) File(java.io.File) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Location(org.bukkit.Location)

Example 24 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project Dragonet-Legacy by DragonetMC.

the class PluginAdapter method initialize.

public void initialize(String name) {
    if (initialized)
        return;
    this.name = name;
    dataFolder = new File(server.getDragonetServer().getPluginFolder(), this.getName().replace(".", "_").concat("-data"));
    if (dataFolder.isFile()) {
        server.getLogger().warning("Faild to load plugin [" + getName() + "] due to plugin folder is occupied by a regular file. ");
        throw new IllegalStateException("Plugin folder for [" + getName() + "] is occupied by a regular file. ");
    }
    config = new YamlConfiguration();
    try {
        config.load(new File(dataFolder, "config.yml"));
    } catch (IOException | InvalidConfigurationException ex) {
    }
    logger = new PluginLogger(this);
    initialized = true;
}
Also used : IOException(java.io.IOException) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration) File(java.io.File) PluginDescriptionFile(org.bukkit.plugin.PluginDescriptionFile) PluginLogger(org.bukkit.plugin.PluginLogger) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException)

Example 25 with YamlConfiguration

use of org.bukkit.configuration.file.YamlConfiguration in project xAuth by CypherX.

the class MessageHandler method reloadConfig.

public void reloadConfig() {
    config = YamlConfiguration.loadConfiguration(configFile);
    InputStream defConfigStream = plugin.getResource(fileName);
    if (defConfigStream != null) {
        YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
        config.setDefaults(defConfig);
    }
}
Also used : InputStream(java.io.InputStream) YamlConfiguration(org.bukkit.configuration.file.YamlConfiguration)

Aggregations

YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)36 File (java.io.File)24 IOException (java.io.IOException)21 InvalidConfigurationException (org.bukkit.configuration.InvalidConfigurationException)13 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)6 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 Location (org.bukkit.Location)4 FileConfiguration (org.bukkit.configuration.file.FileConfiguration)4 EntityType (org.bukkit.entity.EntityType)4 SettingsFlag (com.wasteofplastic.acidisland.Island.SettingsFlag)3 InputStream (java.io.InputStream)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ChatColor (com.gamingmesh.jobs.util.ChatColor)2 DefaultInfo (de.Keyle.MyPet.api.entity.DefaultInfo)2 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)2 InputStreamReader (java.io.InputStreamReader)2 TreeMap (java.util.TreeMap)2 Material (org.bukkit.Material)2