How Disable Things On Config?

Discussion in 'Plugin Development' started by MrGriefer_HGTech, Jan 7, 2015.

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

    Skionz

    @MrGriefer_HGTech Use control flow statements and check if that key's value is true, or false before doing anything.
     
  2. @Skionz How? I am new to config things.
     
  3. Offline

    Skionz

  4. if you're using the default config just use :
    Code:
    if(getConfig().getBoolean("path")) // this will check if the value is true
    but if you wanna check if the value is false :
    if(!getConfig().getBoolean("path)) 
    
    //If you're not using default config, just change "getConfig()" for your YamlConfiguration.
     
  5. Can I make it so if the thing was true then it will enable a class?
     
  6. you can use the if statement in the onEnable() to register or not register the class...
    like this
    Code:
    if(getConfig.getBoolean("path"){
       //register class
    }
    
    its like @MaTaMoR_ said above
    but i think its better to use the if statement on every method of the class for it own because than there won't be that much problems/errors


    you can use this statement anywhere you want ;)
    i think that the easiest way
     
  7. @MaTaMoR_ when they put the path:false I just return; correct?
     
  8. Offline

    teej107

    @MrGriefer_HGTech Just make sure the code you don't want being executed to not be ran.
     
  9. A little tuto :
    Code:java
    1.  
    2. Boolean mode = false; //A boolean false
    3. Boolean yourboolean = instance().getConfig().getBoolean("path"); //You can use this to get the boolean from the config
    4. public void lalala() {
    5. if(mode) { //This only will work if the boolean is "true"
    6. //Your stuf will not work because the boolean is "false"
    7. }
    8. //You can also check if the value is false
    9. if(!mode) { //This only will work if the boolean is "false"
    10. //This will work because the boolean is "false"
    11. }
    12. }
    13.  
     
    Last edited: Jan 15, 2015
  10. Here take a look at what i did!
    Code:
    @Override
        public void onEnable() {
            System.out.println(ChatColor.GREEN + "[RealisticBlocks] Enabling...");;
            PluginManager pm = getServer().getPluginManager();
            pm.registerEvents(new EntityExplode(), this);
            pm.registerEvents(new PlayerInteract(), this);
           
            if (getConfig().getBoolean("Falling Blocks")) {
                pm.registerEvents(new BlockPlace(), this);
            }
           
            if (!getConfig().getBoolean("Falling Blocks")) {
                return;
            }
           
            getConfig().options().copyDefaults();
            saveConfig();
        }
    The thing is that everything is working good but when i open the config.yml there is nothing? Why?

    Here is my config.yml:
    Code:
    Falling Blocks: true
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
  11. Offline

    PreFiXAUT

    @MrGriefer_HGTech Please, take a look into the JavaDoc of Bukkit and learn a bit. You NEVER set anything in the Config. You need to create a config.yml File (where your plugin.yml File is) and this is going to be your Template Config.

    In the onEnable() add the Default-Values and Paths (check tutorials for that, there are thousands) and then you can go on.
     
  12. Offline

    teej107

    @MaTaMoR_ @MrGriefer_HGTech
    if else statements!
     
  13. Maybe you just wanna check if the boolean is false .

    You should use default config, create a empty file called "config.yml" in your default package write everything in and on enable use "saveDefaultConfig();"
     
    Last edited by a moderator: Jan 15, 2015
  14. But what should I do when it's "false"? Should I just return?
     
  15. Offline

    Skionz

Thread Status:
Not open for further replies.

Share This Page