Enable and disable a class via config

Discussion in 'Plugin Development' started by BrushPainter, Mar 12, 2014.

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

    BrushPainter

    Hey everyone! I just created a plugin, ClassicLogger. I have certain features I would like the user to be able to enable/disable using the configuration file. I'm just wondering how this can be done. I have each feature saved in it's own class.

    Thanks in advance -BrushPainter :)

    P.S. Here is ClassicLogger incase any of you need it or want to check it out. Currently awaiting approval: http://dev.bukkit.org/bukkit-plugins/classiclogger/
     
  2. Offline

    SuperOmegaCow

    BrushPainter
    Just get a boolean from the config and choose either to enable or disable a feature.
     
  3. Offline

    StealerSlain

    Before the feature starts doing something, check if in config it's enabled. If not, say something like "Function isn't enabled" for debug.
     
  4. Offline

    acecheesecr14

    So if each class does different things... So a.class logs blocks, and b.class logs chat, then you probably loaded the class' by using the registerListener method or something?

    So however you load the class' just check if in the config if they're enabled in the config?
     
  5. Offline

    GameplayJDK

    BrushPainter
    A public boolean in your main class and which is set by the config should do whatnyou want.
    After you've assigned the value from the config check its value before executing the method(s) of the feature(s).
     
  6. Offline

    BrushPainter

    GameplayJDK acecheesecr14 StealerSlain SuperOmegaCow Thank you guys for the quick replies, I've been trying a bunch of these methods and I came up with
    Code:java
    1. if(Main.getConfig().getConfigurationSection("ClassicLogger.BlockPlaces.Enabled").getBoolean(true)) {

    Error on if: Syntax error on token "if", invalid AnnotationName - Not sure what to do here
    Error on {: Syntax error, insert "}" to complete Block - I tried inserting another } at the end of the code, yet after I do, it tells me to delete it. :confused:
    Also will using Main.getconfig() work if my main class is named Main?
     
  7. Offline

    SuperOmegaCow

    BrushPainter
    it should be if(this.getConfig().getBoolean("ClassicLogger.BlockPlaces.Enabled")) {}
     
  8. Offline

    BrushPainter

    SuperOmegaCow Ok thanks but I still get the 2 errors on if and {. One more thing, would it automatically know to default to true?
     
  9. Offline

    GameplayJDK

    BrushPainter
    If you use this in a listener or in a commandexecutor, use
    plugin.getConfig()...
    To help you fixing the } errors wenn need to know, what the complete code looks like?
     
  10. Offline

    SuperOmegaCow

    BrushPainter
    Try to see if you can figure it out yourself before coming here. Your program will not do anything unless you tell it to. Also your issue with the { can't be solved unless you provide us with some code.
     
  11. Offline

    BrushPainter

  12. Offline

    SuperOmegaCow

    BrushPainter
    Maybe java is something you should learn before coming to plugin development. Try buying a book.
     
    badboysteee98 and acecheesecr14 like this.
  13. Offline

    BrushPainter

    SuperOmegaCow I'm trying to learn Java as I learn plugin development, I just want to have fun coding.
     
    acecheesecr14 likes this.
  14. Offline

    GameplayJDK

    BrushPainter
    You can't just place an if statement in the raw class. "If" can only be used in methods.
    And you would do the if statement before you register your listener (in main class).
     
  15. Offline

    SuperOmegaCow

    BrushPainter
    Fun starts when you know what you are doing. Let me make it appeasing. If you know dem javas, you could make a game just like minecraft :D
     
  16. Offline

    BrushPainter

    GameplayJDK Thank you!!! I didn't even notice I was doing that. It's fixed now. :)
    SuperOmegaCow True. But I find it easier to learn in duos.
     
  17. Offline

    AoH_Ruthless

    BrushPainter You have other issues also.

    Your @EventHandler has to be in the raw class (opposite of if statements). So, you should call the event first. Then check if it is enabled in config.

    I'm assuming you are using Eclipse here. If you are, Highlight your code and press CTRL + I - This indents your code properly so you can see where blocks are opened and closed. This tells you where you are doing something wrong with the brackets.

    Honestly, you should learn the basics of Java while you are coding. You can only learn a programming language when you practice with it! The way I see it (and did it), you learn from a book (or online) and when you learn something you practice using it - With Bukkit.

    Ex: Learned Enums? Make a bukkit enum to perform a task (vague, but just use your imagination!)
    Learn how to make ArrayLists? Use Bukkit to work with them!

    It's a very controversial topic on these forums about how you should learn Java. Personally, I used a book (as did most people.). Specifically, Java for Dummies 5th Edition is what I used. Many others will suggest you watch youtube videos or take a look at the Oracle Documentation, but you have to see for yourself what works best for you!

    But my point is, don't blindly code Bukkit. When you learn something in Java, make sure you understand how it works or try to understand how it works then work with it in Bukkit. Don't get too far ahead of yourself, as becoming fluent in a programming language takes time! It's like any foreign language like French or Spanish and practice makes perfect but you need to take your time.
     
  18. Offline

    BrushPainter

    AoH_Ruthless Ok thanks for the suggestion man, I'll look into it, but I really find it easier to actually do something hands on then read for a while and then do it. Just like when I was a kid and I would buy a toy, I would throw away the instructions and get building, haha. But I will look into Java for Dummies.
     
  19. Offline

    badboysteee98

    Java For Dummies is a really good book because you can have a lot of fun coding as of tonight I gave Plugin Development a reset and looked in the book I now have 6 extra Projects because whats in the book I've also tried to make so it's not just sitting reading it and try to get it to sink in because I don't learn that way so the book is good for getting you to have ago at what they do :)
     
Thread Status:
Not open for further replies.

Share This Page