Search in sources :

Example 1 with Title

use of com.gamingmesh.jobs.container.Title 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 2 with Title

use of com.gamingmesh.jobs.container.Title in project Jobs by GamingMesh.

the class PlayerManager method performLevelUp.

/**
 * Broadcasts level up about a player
 * @param jPlayer
 * @param job
 * @param oldLevel
 */
public void performLevelUp(JobsPlayer jPlayer, Job job, int oldLevel) {
    Player player = Bukkit.getServer().getPlayer(jPlayer.getPlayerUUID());
    JobProgression prog = jPlayer.getJobProgression(job);
    if (prog == null)
        return;
    String message;
    if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
        message = Language.getMessage("message.levelup.broadcast");
    } else {
        message = Language.getMessage("message.levelup.nobroadcast");
    }
    message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
    Title oldTitle = ConfigManager.getJobsConfiguration().getTitleForLevel(oldLevel);
    if (oldTitle != null) {
        message = message.replace("%titlename%", oldTitle.getChatColor() + oldTitle.getName() + ChatColor.WHITE);
    }
    if (player != null) {
        message = message.replace("%playername%", player.getDisplayName());
    } else {
        message = message.replace("%playername%", jPlayer.getUserName());
    }
    message = message.replace("%joblevel%", "" + prog.getLevel());
    for (String line : message.split("\n")) {
        if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
            Bukkit.getServer().broadcastMessage(line);
        } else if (player != null) {
            player.sendMessage(line);
        }
    }
    Title newTitle = ConfigManager.getJobsConfiguration().getTitleForLevel(prog.getLevel());
    if (newTitle != null && !newTitle.equals(oldTitle)) {
        // user would skill up
        if (ConfigManager.getJobsConfiguration().isBroadcastingSkillups()) {
            message = Language.getMessage("message.skillup.broadcast");
        } else {
            message = Language.getMessage("message.skillup.nobroadcast");
        }
        if (player != null) {
            message = message.replace("%playername%", player.getDisplayName());
        } else {
            message = message.replace("%playername%", jPlayer.getUserName());
        }
        message = message.replace("%titlename%", newTitle.getChatColor() + newTitle.getName() + ChatColor.WHITE);
        message = message.replace("%jobname%", job.getChatColor() + job.getName() + ChatColor.WHITE);
        for (String line : message.split("\n")) {
            if (ConfigManager.getJobsConfiguration().isBroadcastingLevelups()) {
                Bukkit.getServer().broadcastMessage(line);
            } else if (player != null) {
                player.sendMessage(line);
            }
        }
    }
    jPlayer.reloadHonorific();
    Jobs.getPermissionHandler().recalculatePermissions(jPlayer);
}
Also used : Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) JobsPlayer(com.gamingmesh.jobs.container.JobsPlayer) JobProgression(com.gamingmesh.jobs.container.JobProgression) Title(com.gamingmesh.jobs.container.Title)

Aggregations

Title (com.gamingmesh.jobs.container.Title)2 JobProgression (com.gamingmesh.jobs.container.JobProgression)1 JobsPlayer (com.gamingmesh.jobs.container.JobsPlayer)1 ChatColor (com.gamingmesh.jobs.util.ChatColor)1 File (java.io.File)1 IOException (java.io.IOException)1 OfflinePlayer (org.bukkit.OfflinePlayer)1 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)1 YamlConfiguration (org.bukkit.configuration.file.YamlConfiguration)1 Player (org.bukkit.entity.Player)1