getConfig() help

Discussion in 'Plugin Development' started by tylerthecreeper1, Mar 2, 2014.

Thread Status:
Not open for further replies.
  1. Hi. I am making a plugin that when you go into water, you take damage. I am having trouble, getting errors, when I getConfig().String("...").

    Here is my code for my event.

    Code:java
    1. @EventHandler
    2. public void onPlayerMove(PlayerMoveEvent event)
    3. {
    4. if (event.getTo().getBlock().getType().equals(Material.STATIONARY_WATER))
    5. {
    6. final int damageAmount = 1; //get from config
    7. if( event.getPlayer().getHealth() <= 20.00){
    8. if( event.getPlayer().getHealth() >= 0.00) {
    9. event.getPlayer().damage(damageAmount);
    10. event.getPlayer().sendMessage(ChatColor.RED + "You can't swim!");//get from config
    11.  
    12. }
    13. }
    14. }
    15. }
    16. }
    17.  


    Thanks in advance.
     
  2. Offline

    Harmings

    tylerthecreeper1
    You cannot call the getConfig() method outside of the main class(class which extends JavaPlugin) you will have to get the instance of you main class which can easily be done with a constructor like this
    private MainClassNameHere plugin;
    public classNameHere(MainClassNameHere instance) {
    this.plugin = instance;
    }
    Now you can get the int in your config like so
    plugin.getConfig().getInt("damageAmount");
     
    Minesuchtiiii likes this.
  3. Offline

    Minesuchtiiii

    Harmings
    allright! I would do same thing in this case!
     
  4. Harmings Thanks! And any idea why I have this issue?
    Code:java
    1. @Override
    2. public void onEnable() {
    3. log.info("[Water] Enabled.");
    4. loadConfiguration();
    5. Listener WaterEvent = new WaterEvent();
    6. PluginManager pm = getServer().getPluginManager();
    7. Bukkit.getPluginManager().registerEvents(WaterEvent, this);
    8. }


    The error is on "new WaterEvent()". I set that instead of registerEvents(new WaterEvent(), this); because I got an error there and it fixed it before. Now I have the error again.
     
  5. Offline

    Harmings

Thread Status:
Not open for further replies.

Share This Page