Solved How to make a config to this

Discussion in 'Spigot Plugin Help' started by noobskills, May 20, 2016.

  1. Plugin.yml
    Code (Text):
    name: ElytraCrafting
    version: 1.0
    main: me.noobskills.recipe.Recipe
    description: Craft the elytra
    Code (Text):
    package me.noobskills.recipe;

    import org.bukkit.Material;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.ShapedRecipe;

    public class Recipe extends JavaPlugin {
        public void onEnable() {
            ItemStack elytra = new ItemStack(Material.ELYTRA, 1);
            ShapedRecipe Elytrawings = new ShapedRecipe(elytra);
            Elytrawings.shape("*%*","PLP","F F");
            Elytrawings.setIngredient('*', Material.STRING);
            Elytrawings.setIngredient('%', Material.CHORUS_FRUIT);
            Elytrawings.setIngredient('P', Material.PAPER);
            Elytrawings.setIngredient('L', Material.LEATHER);
            Elytrawings.setIngredient('F', Material.FEATHER);
        public void OnDisable() {
    So I want to know how I can make a config so people can disable the plugin and change the crafting recipe. I'm new to coding so yea.
  2. To allow users to disable your plugin:
    Add an option in the config "enabled: true" then in your onEnable() method you would check if that value is true or false. If false disable the plugin.

    For changing the recipe I would use a string list, 3 strings, 3 characters per string. there is a method available via the file configuration class to get a string list so this is very easy.

    You config would look like something like this:
    Code (Text):

    enabled: true

    - 'ABC'
    - 'DEF'
    - 'GHI'
  3. What about making it to any items/blocks they want?
  4. It get a little more complicated due to a number of factors, but basically there are a few ways.

    Instead of chars to represent the ingredients use material names separated by some delimiter i.e. a comma
    Code (Text):

    Read in the string list and split each string at the comma, then you can use the Material#getMaterial() method(might want to call #toUpperCase() on the string representing the material).

    I guess another way could be to keep the recipe list as it is and add a map of sorts i.e.
    Code (Text):

      A: 'STONE'
      B: 'GRASS'
      C: 'DIRT'
      D: '...'
      E: '...'
      F: '...'
    The second method IMO would make it easier to specify a durability value i.e. A: 'WOOL:5'

    EDIT: You really have a lot of choice on how to implement something like this, the possibilities are limitless. ;)
    • Friendly Friendly x 1
  5. Ah ok thank you so much!
    • Friendly Friendly x 1