Getting from Config

Discussion in 'Plugin Development' started by MrGermanrain, Dec 4, 2013.

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

    MrGermanrain

    Hey Devs!
    I had a question on getting something from the config!

    So lets say that we have a default config:
    Code:
    //If set to "false" you won't be healed by soup.
    soupheals: true
     
    //HPS stats for Hearts Per Soup, this show how many hearts the soup will heal.
    //HINT: Each number stands for half a heart! So "7" will heal 3.5 hearts. (20 is max.)
    HPS: 6
    
    And we have this code in the listener:
    Code:java
    1. package me.mrgermanrain.moresoup;
    2.  
    3. import org.bukkit.Material;
    4. import org.bukkit.entity.Player;
    5. import org.bukkit.event.EventHandler;
    6. import org.bukkit.event.Listener;
    7. import org.bukkit.event.Event.Result;
    8. import org.bukkit.event.block.Action;
    9. import org.bukkit.event.player.PlayerInteractEvent;
    10. import org.bukkit.inventory.ItemStack;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class MoreSoupEvents extends JavaPlugin implements Listener {
    14.  
    15. Boolean sh = getConfig().getBoolean("soupheals");
    16. int hps = getConfig().getInt("hps");
    17.  
    18. @EventHandler
    19. public void onPlayerEat(PlayerInteractEvent e) {
    20. Player p = e.getPlayer();
    21. if (sh != false) {
    22. if (p.getItemInHand().getType() == Material.MUSHROOM_SOUP && p.hasPermission("moresoup.usesoup")) {
    23. if (e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
    24. e.setUseItemInHand(Result.DENY);
    25. p.getInventory().removeItem(new ItemStack(e.getItem().getTypeId(), 1));
    26. if (p.getMaxHealth() > (p.getHealth() + hps)) {
    27. p.setHealth(p.getHealth() + hps);
    28. } else {
    29. p.setHealth(20);
    30. }
    31. }
    32. }
    33. }
    34. }
    35. }



    Would this work?
     
  2. Offline

    Gater12

    MrGermanrain likes this.
  3. Offline

    MrGermanrain

    Thanks! Also when I reload the server would it reset my default config?
     
  4. Offline

    Gater12

    MrGermanrain It shouldn't. It should generate if the config.yml is not already there. (So you're going to have to tell your users should you ever release the plugin to regenerate the config if you changed something in it).
     
  5. Offline

    MrGermanrain

    thanks :)
     
Thread Status:
Not open for further replies.

Share This Page