Adding strings to a stringlist in config.yml via commands

Discussion in 'Plugin Development' started by mgbeenieboy, Sep 9, 2014.

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

    mgbeenieboy

    Code:java
    1. else if (args.length == 3 && args[0].equalsIgnoreCase("whitelist") && args[1].equalsIgnoreCase("add")) {
    2. Main.plugin.getConfig().getStringList("WorldGuard.RegionWhitelist").add(args[2]);
    3. sender.sendMessage("ok");
    4. }
    5.  
    6. else if (args.length == 3 && args[0].equalsIgnoreCase("whitelist") && args[1].equalsIgnoreCase("remove")) {
    7. Main.plugin.getConfig().getStringList("WorldGuard.RegionWhitelist").remove(args[2]);
    8. sender.sendMessage("ok");
    9. }


    I have a config.yml which is embedded in the plugin (maybe this could be the reason). The config has the StringList in path WorldGuard.RegionWhitelist. I want to add and remove strings to this list via commands in game. I get the "ok" message, no errors in the server.log, but it doesn't change anything in the config.yml.
    /rcp whitelist add <region>
     
  2. Offline

    DusRonald

    I believe the code does work, but can you give your config.yml?
     
  3. Offline

    mgbeenieboy

    Code:
    # This is the maximum signal switches Redstone may experience before RSCP reacts
    MaxSignalChanges: 1500
    # Should notify them who have the permission rscp.getnotified about new found and blocked redstone clocks?
    NotifyAdmins: false
    # The clock will be stopped by replacing a redstone with a block which you can decide here
    # It can be a SAPLING, WATER and even AIR, but if you want a written sign remember to write SIGN_POST
    ClockBlocker: SIGN_POST
    # This part is only relevant if ClockBlocker is set to SIGN_POST
    Sign:
    # A sign has four lines. Edit them here.
      Line1: 'Redstone-Clocks'
      Line2: 'are'
      Line3: '&4FORBIDDEN!'
      Line4: ''
    # Here you can add worlds in which the plugin should check on redstone clocks and stop them
    Worlds:
    - world
    - world_nether
    - world_the_end
    # These features only work if you have the plugin WorldGuard on your server!
    WorldGuard:
    # Redstone clocks in these regions will not get blocked by this plugin
      RegionWhitelist:
      - redstone
      - area
    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  4. Offline

    Creeoer

    mgbeenieboy
    Err...argument length ==3? I beleive you should try using args.length == 2, because I beleive argument 0 starts out from 0, argument 1, 1, and argument 2, 2, args.length==2? I cant confirm this but it's worth a shot.

    EDIT: If the above doesn't work, try reverting my suggestion and instead try calling the saveConfig method after you did the change, if that doesn't work either then I guess use my suggestio nand the saveConfigMethod?
     
  5. Offline

    mgbeenieboy


    no... not in this case. if you try calling the arguments, then you start counting up from 0, args[0], args[1], args[2]. But the length is 3 ;)

    I have an embedded config.yml in my plugin.


    So I tried .saveConfig() and .saveDefaultConfig() but they both do not work :(

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  6. Offline

    Creeoer

    mgbeenieboy
    Does the config even generate? Did you generate the config in your onEnable method?
     
  7. Offline

    mgbeenieboy


    onEnable:
    saveDefaultConfig();
    reloadConfig();

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 14, 2016
  8. Offline

    Creeoer

    mgbeenieboy
    You could show me your onEnable method, and your method that generates the config file.
     
  9. Offline

    mgbeenieboy

    I'm currently not on pc, but the method looks like

    public void onEnable() {
    saveDefaultConfig():
    reloadConfig();

    register command
    register event
    }
     
  10. Offline

    Creeoer

    mgbeenieboy
    Try checking if the file even exist first:
    Code:
    if (!new File(getDataFolder(), "config.yml").exists()) {
                  saveDefaultConfig();
     
  11. Offline

    Zarkopafilis

    1) Access Plugin instance properly
    2)Save the config
    3) Main.plugin.getConfig().getStringList("WorldGuard.RegionWhitelist").add(args[2]);
    does nothing. Store the list , add it and then save it
     
  12. Offline

    mgbeenieboy

    If you say storing the list, you mean doing getConfig().set("WorldGuard.RegionWhitelist", stringlist)?
     
  13. Offline

    Zarkopafilis

    Yes
     
Thread Status:
Not open for further replies.

Share This Page