How do I make the Plugin Read the Configeration File

Discussion in 'Plugin Development' started by jay275475, Aug 21, 2013.

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

    jay275475

    Hello Im making a plugin And Thank you Gaming but i still have one more question. How do I let the plugin read the Config Settings?
     
  2. Offline

    Brendyn Todd

    jay275475 Can I see some code? Its harder for someone to help if they can't see your current situation.
     
  3. Offline

    jay275475

    Well Give me a sec

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                Player player = (Player) sender;
                if (cmd.getName().equalsIgnoreCase("Rules")) {
                    player.sendMessage(ChatColor.DARK_AQUA + "Rules:");
                }
                if (cmd.getName().equalsIgnoreCase("News")) {
                    player.sendMessage(ChatColor.RED + player.getDisplayName() + ChatColor.BLUE + " Latest News:");
            }
            return false;   
        }
            return false;
        }
    }
    I dont know how would I Make it generate File then Read it.

    Well Gunner Sent me the Code but I dont know how to make it create a folder and Config.yml in it

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    Brendyn Todd

    Alrighty, basically to create a config the easiest way is to just create a new file in your project, just right click your project folder and add a new file named "config.yml". Just for this example type on the first line of the config "Name:".

    First of all, you need to set values. So create a new command and do this:
    Code:java
    1. //Sets the command senders username to the "Name" config node.
    2. sender.getConfig().set("Name", sender.getName());


    To read values all you need to do is
    Code:java
    1. //Gets a string value
    2. sender.getConfig().getString("Name");
    3.  


    The above code also works with other variable types other than string. Such as boolean, int, and lists.
     
  5. Offline

    jay275475

    thank you!

    so for News I do News.yml and put
    Code:java
    1. ender.getConfig().set("News", sender.getName());


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  6. Offline

    Brendyn Todd

    No see, you have to create a config named "config.yml" you can create others but I do not know exactly how to manipulate them.

    The code is correct (Other than the missing "s" on sender) The code will put the senders username in the "News" line.
     
  7. jay275475
    Go on YouTube and look for tutorials on this. There are some really good ones out there. It's better to see someone do it and explain it infront of you.
     
  8. Offline

    jay275475

Thread Status:
Not open for further replies.

Share This Page