Config true or false option in listener

Discussion in 'Plugin Development' started by ChickenPillow, Aug 20, 2016.

Thread Status:
Not open for further replies.
  1. Hello,

    Basically I've got a PlayerListener where if a player dies there drops are cleared, but I also want to make that an option in the config (true or false)

    So I try:

    If(plugin.getConfig.getBoolean("options.Drop_Items_On_Death")) {

    All the code including } else { etc.

    But I get errors with like delete this add that... But that would ruin the original code.

    Any ideas why and how to fix it? Is it to do with it being a listener, could I like put the listener in the main or something?

    Thanks
     
  2. Offline

    Tecno_Wizard

    @ChickenPillow, post your code inside code tags here. I have absolutely no idea what you're talking about. lol
     
  3. This is the code for my Player Listener > http://pastebin.com/BMXweZqa

    What it does is make it that if a player dies, it will clear their items, but I want this as an option in the config.yml (true or false) but whenever I use an if statement it gives errors

    such as:
    If(plugin.getConfig.getBoolean("options.Drop_Items_On_Death")) {

    how can I make this work, maybe like only run the whole listener if config is set to true (but doesnt run if set to false, in config.yml)

    Thanks
     
  4. Offline

    HeartandSoul

    Code:
      Main plugin;
      public PlayerListeners(Main instance)
      {
        this.plugin = instance;
      }
    This comes directly from your code. Make Main private and final, then initialize the variable in a method. Also, to make things easier for you, try re-naming your variable instance to plugin.
    Never name your main class "Main!" It's bad practice!!!!

    Code:
      @EventHandler
      public void Death(PlayerDeathEvent e)
      {
        e.getDrops().clear();
      }
    }
    Do onDeath, it's better for methods to use lower-case letters at the beginning.

    Code:
    import me.ChickenPillow.KitPvP.Main;
    Although I don't (and I probably should), try following naming conventions. Make your packages lower-case

    You said your code gives you errors. Post your stack trace?
     
  5. Don't worry about the errors (fixed it)

    Also I don't quite understand the initialising the variable in a method?
     
  6. Offline

    HeartandSoul

    Then it's clear that you need to learn java before continuing Bukkit development.

    Code:
      Main plugin;
      public PlayerListeners(Main instance)
      {
        this.plugin = instance;
      }
    this.plugin = instance; is in initializing a variable
     
  7. Yes ik that, but what about the in a method part, I'm not too familiar with that?

    My code > http://pastebin.com/BWvmshw2

    Why do I get an error on getConfig on line 18?

    It says

    getConfig cannot be resolved or is not a field

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Aug 24, 2016
  8. Online

    timtower Administrator Administrator Moderator

  9. Before the getConfig?
     
  10. Offline

    Zombie_Striker

    @ChickenPillow
    This is a clear sign you really need to learn Java before you continue. No, you need the brackets to come after the "getConfig", but if you understood the difference betwen methods and fields, you should not need to post that. Please, pick a tutorial from the following link, learn Java (which should only take a month) and then come back to bukkit. After that, you should be encountering these problems.
    https://bukkit.org/threads/plugin-dev-sticky-learning-java-where-to-learn.395662/
     
  11. @ChickenPillow To be honest. That's a rather complicated boolean... I'd try something simpler like: Death_Drops:
    Just my opinion. Anyways, On topic now, getConfig() is correct.

    @ChickenPillow Basically, They mean you're missing parentheses after the "getConfig".

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  12. Dont worry guys I managed to get it working! Thanks anyway
     
    Last edited: Aug 25, 2016
Thread Status:
Not open for further replies.

Share This Page