[TUTORIAL|EASY] Basic config setup

Discussion in 'Resources' started by hawkfalcon, Jul 22, 2012.

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

    hawkfalcon

    I have looked at a lot of config tutorials and have been unhappy with them. So I decided to make my own, simple one!
    Step One:
    Create a file called "config.yml" and place it in the same location as your plugin.yml
    Step Two:
    In your config.yml, add a default config. Must be in valid yaml format, such as name: hi
    Step Three:
    In your onEnable method, under
    Code:java
    1. getServer().getPluginManager().registerEvents(this, this);

    add this code:
    Code:java
    1. if (!new File(getDataFolder(), "config.yml").exists()) {
    2. saveDefaultConfig();
    3. }

    Step Four:
    To set a value, use
    Code:java
    1. this.getConfig().set("name", "hello");
    2. this.saveConfig();

    Step Five:
    To get a value it is good to set it to a variable. For example:
    Code:java
    1. String myName = getConfig().getString("name");

    myName will be set to the current value, in this case "hello"
    More "getters" such as getString(), can be found here.

    This is how to set up a basic configuation and how to set values and get values. For more information, please see this.
    Thank you and have fun making a configuration!
    Note:
    There are many ways of doing this. This is one way, and in my opinion, the easiest.
     
  2. Offline

    Kodfod

    Good Tut =D
     
  3. Offline

    hawkfalcon

    Thanks:)
     
  4. Offline

    furt

    Step Three can be done this way to minimize code aswell.
    Code:
    if (!new File(getDataFolder(), config.yml").exists())
          saveDefaultConfig();
     
    hawkfalcon likes this.
  5. Offline

    hawkfalcon

    Modified to reflect this. You forgot a "
     
  6. Offline

    furt

    yea i did lawl
     
  7. Offline

    hawkfalcon

    If I forgot something let me know.
     
  8. Offline

    isleepzzz

    woe. i dont have
    in my onEnabled..

    i got this:
     
  9. Offline

    hawkfalcon

    That's the old way to do it:3 either update it or don't. But you can put it under it.
     
  10. Offline

    isleepzzz

    Ooo ok cool can u give me a skeleton of the "newer" plugin platform please?:)
     
  11. Offline

    hawkfalcon

    Code:
    getServer().getPluginManager().registerEvents(this, this);
    
     
  12. Offline

    isleepzzz

    hahaha can i have the SKELETON?

    for example:

    this would be a skeelton (a blank format looking thing):

    Code:
    package me.rawr.survivalgames;
     
    import java.util.logging.Logger;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class BryceKits extends JavaPlugin {
    public final Logger logger = Logger.getLogger("Minecraft");
    public static SurvivalGames plugin;
     
    @Override
    public void onDisable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Has Been Disabled!");
    }
     
    @Override
    public void onEnable() {
    PluginDescriptionFile pdfFile = this.getDescription();
    this.logger.info(pdfFile.getName() + " Version " + pdfFile.getVersion() + " Has Been Enabled!");
     
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
     
     
     
    return false;
    }
    }
    
    but can i get the "newer" way of doing it like u said?
     
  13. Offline

    hawkfalcon

    Updated code:
    Code:
    package me.rawr.survivalgames;
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
    import org.bukkit.plugin.PluginDescriptionFile;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class ClassName extends JavaPlugin {
     
    @Override
    public void onEnable() {
    getServer().getPluginManager().registerEvents(this, this);
    }
     
    @Override
    public void onDisable() {
    }
     
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
    Player player = (Player) sender;
     
     
     
    return false;
    }
    }
    
    registerEvents Does all the logger stuff automatically.
     
    TheEpicButterStudios likes this.
  14. Offline

    hawkfalcon

    .
     
    bobacadodl likes this.
  15. Offline

    Icyene

    Deep.
     
    bobacadodl likes this.
  16. Offline

    hawkfalcon

    Ikr, its just so .
     
    bobacadodl likes this.
Thread Status:
Not open for further replies.

Share This Page