Helper Functions #3: "setting"

Discussion in 'Resources' started by pzxc, Jul 18, 2012.

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

    pzxc

    This function forms the basis of letting you change your config settings in-game with a command.

    Code:
    private void setting(CommandSender sender, String setting, String value) {
        if (value.equals("true")) getConfig().set(setting, true);
        else if (value.equals("false")) getConfig().set(setting, false);
        else if (value.equals("null")) getConfig().set(setting, null);
        else {
            try { getConfig().set(setting, Double.parseDouble(value)); }
            catch (Exception e) { getConfig().set(setting, value); }
        }
        saveConfig(); sender.sendMessage(this.toString() + " setting has been changed.");
    }
    
    Just put that function anywhere in your plugin, then add this line to your onCommand function:

    Code:
    if (cmd.getName().equalsIgnoreCase("setting") && args.length == 2) { setting(s, args[0], args[1]); return true; }
    Now you will be able to change any of your configuration file settings from in-game with /setting category.subcategory.setting value

    Of course you will want to set up permissions on the "setting" command so that only you/ops can use it!
     
  2. you know that this is the wrong topic, like telled at the other 2 post, this should go into the resources section
     
  3. Offline

    pzxc

    I posted all three of these before anyone had replied and I learned my mistake. For some reason I overlooked the resource forum. I don't have access to move these threads or I would. Sorry for posting them.
     
  4. Offline

    TnT

    Moved to the correct forum.
     
Thread Status:
Not open for further replies.

Share This Page