Want to make a config but don't know how?

Discussion in 'Plugin Development' started by evantheis, Jun 28, 2013.

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

    evantheis

    I am a little knew but i'm to the point where I can kind of know what I am doing. How do I make a config file though?
     
  2. Offline

    Ty Cleere

    @eventheis What you need to do is right click on your project and then create a new file. Call it config.yml. and in your onEnable() put this.

    Code:java
    1. getConfig().options().copyDefaults(true);
    2. saveConfig();
     
  3. Offline

    evantheis

    Now could you help me get something from the plugin.yml? Like I want to get the "version:" and make it so if I would do /jfjdfVersion It'll say "jfjdf is currently running version 1." Or something along those ligns.
     
  4. Offline

    Ty Cleere

    So your wanting a command that gets the server name and then gets the version?
     
  5. Offline

    evantheis

    Is the server name the plugin name?
     
  6. Offline

    Ty Cleere

    I couldn't tell you that for sure. I tried something with the server name a little bit ago and i got craftbukkit. I'm sure there is a way to change it but idk how yet. You could do something where it gets the Plugin name if thats what your doing. like this. I think that will work let me know if it doesnt and ill look at it again.

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd,
    2. String commandLabel, String[] args) {
    3. Player player = (Player) sender;
    4. if (commandLabel.equalsIgnoreCase("v")) {
    5. PluginDescriptionFile pdfFile = this.getDescription();
    6. pdfFile.getName() + "Is Currently Running Version " + pdfFile.getVersion();
    7. }
    8. }
     
  7. Offline

    xxmobkiller

    Code:
        @Override
        public boolean onCommand(CommandSender sender, Command command, String cmd, String[] args) {
              Player player = (Player) sender;
              PluginDescriptionFile pdf = getDescription();
              if (cmd.equalsIgnoreCase("v")) {
              player.sendMessage(pdf.getName() + " Is Currently Running Version " + pdf.getVersion());
              }
              return false;
        }

    There you go, and i don't thank you know how to even make a plugin but here you go, Or you could just be learning it but, Hop that this works becuase it did for me.
     
  8. Offline

    ThunderWaffeMC

    evantheis I think he means that he wants to display something from the config. So if you wanted to set a customizable code you can do something like this:

    In your config.yml add something like "sword: DIAMOND_SWORD"
    To get the data from the config of what the player has added you use

    Code:java
    1.  
    2. public class PluginListener implements Listener {
    3. private PluginMain plugin;
    4. public PluginListener(PluginMain plugin) {
    5. this.plugin = plugin;
    6. }
    7.  
    8. this.plugin.getConfig().getString("sword") //get config and display the text after 'sword:'
    9.  


    You can use this somewhere like setting if the item in hand is a _____ (whatever it is in the config).
     
Thread Status:
Not open for further replies.

Share This Page