Solved config

Discussion in 'Plugin Development' started by mydeblob, Apr 9, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    mydeblob

    Hi,
    I have generated a config.yml file with the following code
    Code:java
    1. File config = new File(getDataFolder(), "config.yml");
    2. if(!config.exists()){
    3. getLogger().info("[KitPvp] No config.yml found, generating a new one!");
    4. this.saveDefaultConfig();
    5. }

    And it generates the config file fine. Here is my default config
    Code:
    #Title of the scoreboard
    title: TemplarKitPvP
    I'm using this value in a scoreboard, in which I'm setting it on the join event here
    Code:java
    1. @EventHandler
    2. public void login(PlayerJoinEvent event){
    3. Player p = (Player) event.getPlayer();
    4. Scoreboard board = Bukkit.getScoreboardManager().getNewScoreboard();
    5. Objective o = board.registerNewObjective("prison", "dummy");
    6. o.setDisplaySlot(DisplaySlot.SIDEBAR);
    7. o.setDisplayName(plugin.getConfig().getString("title").replaceAll("&", "\u00A7"));
    8. }

    This works fine, however once I edit the config file via the server it doesn't work. This is how the config looks after I edit it
    Code:
    #Title of the scoreboard
    title: &a&lKit&b&lPvP
    After a restart and relog, it is still displating "TemplarKitPvP" as the title. Am I doing something wrong?
    Thanks.
     
  2. Offline

    coasterman10

    I'm not sure what could be going wrong since you haven't provided any code for how you're setting the value in the config.

    On the side, there is a better way to set the objective display name, which is to use ChatColor.translateAlternateColorCodes():
    Code:java
    1. String title = plugin.getConfig().getString("title");
    2. o.setDisplayName(ChatColor.translateAlternateColorCodes('&', title));
     
  3. Offline

    mydeblob

    I'll try that method. And I never programmatically set the config. I set it manually in the default config in the jar.
     
  4. Offline

    coasterman10

    There might be an issue with how the default config is being copied over. This is over my head as I have not used a default config in a long time.
     
  5. Offline

    mydeblob

    Edit: Solved, turned out I needed double quotation marks. Don't know why, since other strings in the config work fine when written like above. But it works
     
Thread Status:
Not open for further replies.

Share This Page