Question If configuration values == whatever

Discussion in 'Plugin Help/Development/Requests' started by 2008Choco, May 29, 2015.

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

    2008Choco

    My goal is to make an in-game configuration editor for my plugin. It works absolutely perfectly except for one little error I can't seem to figure out. Of course, what I need to do is test what type of value the config option is before its change. Obviously if its intended to be a boolean value, I can't let them set an int value. Lol.

    How would I test the type of value for a config option. I attempted getConfig().getConfigurationSection("blahblah").isInt("blahblah"), but that didn't work. (blahblah not being my config option. Just an example). that was the only "isInt()" method I could find.
     
  2. Offline

    Googlelover1234

    @2008Choco
    You could use the code below as an example:

    Code:
    private boolean isItAnInteger = getConfig().isInt(String path);
    You can use the "isType" methods for other types as well, for example, isBoolean, isString, etc.
     
  3. Offline

    2008Choco

    @Googlelover1234 Perfect, that works fabulous!

    I however have another issue, unfortunately. So the configuration option will change, but it won't take effect. If I run /pcconfig set <option> true, it will say it set it to true, but it's still set to false. Here's the code I have, and I have no idea why it won't work.

    Code:
                                                if (args[2].equalsIgnoreCase("true")){
                                                    config.set(configOption, true);
                                                    PC.reloadConfig();
                                                    player.sendMessage(ChatColor.RED + "Conditions> " + ChatColor.GRAY + "Configuration option " + ChatColor.AQUA + configOption + ChatColor.GRAY + " successfully set to " + ChatColor.GREEN + "true");
                                                    return true;
                                                }//Close if true is specified
                                                if (args[2].equalsIgnoreCase("false")){
                                                    config.set(configOption, false);
                                                    PC.reloadConfig();
                                                    player.sendMessage(ChatColor.RED + "Conditions> " + ChatColor.GRAY + "Configuration option " + ChatColor.AQUA + configOption + ChatColor.GRAY + " successfully set to " + ChatColor.RED + "false");
                                                    return true;
                                                }//Close if false is specified
                                                else{
                                                    player.sendMessage(ChatColor.RED + "Conditions> " + ChatColor.GRAY + "Configuration option " + ChatColor.AQUA + configOption + ChatColor.GRAY + " is a true or false value");
                                                    return true;
                                                }//Close if a boolean is NOT specified
                                            }//Close if the specified config is a boolean
    A few notes about the code. It's PC.reloadConfig() because this is in another class. :p PC.reloadConfig() will work for my reload command in another class, so I know for sure this should. Also, this is just the boolean section. I thought it was a good example for the issue I was having. And lastly, "configOption" is the config option specified by the player. All of that works, but the only thing that doesn't work, is the fact that the change in the config won't take effect
     
  4. Offline

    Googlelover1234

    @2008Choco
    Try using "saveConfig()" instead of "reloadConfig()".
     
  5. Offline

    2008Choco

    @Googlelover1234 When I use saveConfig() instead, it will not change it either. And I attempted to use this before also alongside reloadConfig() which won't work either. With saveConfig(), it won't let me change the config option more than once until I restart the server.
     
Thread Status:
Not open for further replies.

Share This Page