How to format config.yml?

Discussion in 'Plugin Development' started by bitbox, Sep 2, 2014.

Thread Status:
Not open for further replies.
  1. I have created a config.yml file for my plugin, for a number of reasons but mainly so it can be translated, and customized to the servers needs.
    Although it all works, I'm sure there must be a nice way to use config files, instead of a massive block of text.
    Another question is how I would implement something like this to work "&1%TargetName%&ahas been set to &bcreative" with colors and variables. I just can't work out how to do this.
    Code:
    #WARNING: THIS FILE DOES NOT HAVE TO BE CHANGED#
    #Available colors are:#
    #    AQUA            #
    #    BLACK            #
    #    BLUE            #
    #    DARK_AQUA        #
    #    DARK_BLUE        #
    #    DARK_GRAY        #
    #    DARK_GREEN        #
    #    DARK_PURPLE        #
    #    DARK_RED        #
    #    GOLD            #
    #    GRAY            #
    #    GREEN            #
    #    LIGHT_PURPLE    #
    #    RED                #
    #    WHITE            #
    #    YELLOW            #
     
    #Gui Titles#
     
    MainMenuguiTitle: Main Menu
    MainMenuguiTitleColor: DARK_PURPLE
     
    GameModeguiTitle: Gamemode Selector
    GameModeguiTitleColor: DARK_PURPLE
     
    OPguiTitle: OP Menu
    OPguiTitleColor: DARK_PURPLE
     
    #Items in the Main Menu Gui#
     
    GameModeItem: BOOK
    GameModeItemName: Gamemode Selector
    GameModeItemNameColor: RED
    GameModeItemLore: Set the Gamemode of your Target.
    GameModeItemLoreColor: GOLD
     
    BanItemName: Ban
    BanItemNameColor: RED
    BanItemLore: Ban your target.
    BanItemLoreColor: GOLD
     
    KickItemName: Kick
    KickItemNameColor: RED
    KickItemLore: Kick your target.
    KickItemLoreColor: GOLD
     
    PardonItemName: Pardon
    PardonItemNameColor: RED
    PardonItemLore: Pardon your target.
    PardonItemLoreColor: GOLD
     
    OPItem: REDSTONE_TORCH_ON
    OPItemName: OP
    OPItemNameColor: RED
    OPItemLore: OP or DEOP your target.
    OPItemLoreColor: GOLD
     
    FlyItem: FEATHER
    FlyItemName: Fly
    FlyItemNameColor: RED
    FlyItemLore: Allow your target to fly.
    FlyItemLoreColor: GOLD
     
    StopFlyItem: LEATHER_BOOTS
    StopFlyItemName: Stop Fly
    StopFlyItemNameColor: RED
    StopFlyItemLore: Stop your target from flying.
    StopFlyItemLoreColor: GOLD
     
    KillItemName: Kill
    KillItemNameColor: RED
    KillItemLore: Kill your target.
    KillItemLoreColor: GOLD
     
    FeedItem: COOKED_BEEF
    FeedItemName: Feed
    FeedItemNameColor: RED
    FeedItemLore: Feed your Target.
    FeedItemLoreColor: GOLD
     
    HealItem: SPECKLED_MELON
    HealItemName: Heal
    HealItemNameColor: RED
    HealItemLore: Heal your Target.
    HealItemLoreColor: GOLD
     
    #Items in the Gamemode Selector Gui#
     
    CreativeWoolItemName: Creative
    CreativeWoolItemNameColor: RED
    CreativeWoolItemLore: Set your Target into Creative.
    CreativeWoolItemLoreColor: GOLD
     
    SurvivalWoolItemName: Survival
    SurvivalWoolItemNameColor: GREEN
    SurvivalWoolItemLore: Set your Target into Survival.
    SurvivalWoolItemLoreColor: GOLD
     
    AdventureWoolItemName: Adventure
    AdventureWoolItemNameColor: GOLD
    AdventureWoolItemLore: Set your Target into Adventure.
    AdventureWoolItemLoreColor: GOLD
     
    #Items in the OP Gui#
     
    OPOnItem: REDSTONE_TORCH_ON
    OPOnItemName: OP
    OPOnItemNameColor: GREEN
    OPOnItemLore: Set your Target as an OP.
    OPOnItemLoreColor: GOLD
     
    OPOffItem:
    OPOffItemName: DeOp
    OPOffItemNameColor: RED
    OPOffItemLore: DeOp your Target.
    OPOffItemLoreColor: GOLD
    Thanks you very much in advance!
     
  2. Offline

    MasterDoctor

    Why don't you take a look at the Essentials config.
     
  3. Offline

    GrimReaper52498

    bitbox
    Not really sure what youre asking, But, Instead of using 'big block of text' to write your config, make it in your IDE and in your onEnable() use
    Code:java
    1. getConfig().options.copyDefaults(true);
    2. //then save it with
    3. saveDefaultConfig();

    , and as for the variables do
    Code:java
    1. getConfig().getString("SomeString").replace("YourVariable", Replacement);

    and for translating colors with the '&' symbol from the config do
    Code:java
    1. getConfig().getString("SomeString").replaceAll("(&([a-fokl0-9]))", "§$2");


    Hope This Helped.
     
  4. Offline

    es359

    I usually do something like this.
    Code:java
    1.  
    2.  
    3. String someString = getConfig().getString("Your_Configuration_Section");
    4.  
    5. someString = someString.replaceAll("YourFunction", "WhatYouWantToReplaceItWith");
     
  5. Offline

    GrimReaper52498

  6. Offline

    BillyGalbreath

    :O!
    Code:java
    1. ChatColor.translateAlternateColorCodes('&', getConfig().getString("SomeString"));
     
  7. Offline

    GrimReaper52498

    BillyGalbreath
    >.< I've always used the way I said I've never really bothered with
    Code:java
    1. ChatColor.translateAlternateColorCodes('&', getConfig().getString("SomeString"));

    Maybe I'll start using it!
     
  8. Offline

    MasterDoctor

    No problem :)
     
Thread Status:
Not open for further replies.

Share This Page