Solved Config doesn't save list, just saves "*id001"

Discussion in 'Plugin Development' started by MrDaniel, Jan 12, 2020.

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

    MrDaniel

    So i have this code
    Code:
    p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #3f7f5f} p.p2 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo} p.p3 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; color: #2a00ff} p.p4 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Menlo; min-height: 14.0px} span.s1 {color: #6a3e3e} span.s2 {color: #7f0055} span.s3 {color: #000000} span.Apple-tab-span {white-space:pre}
    
    // Permissions
    
    List<String> permissions = new ArrayList<String>();
    
    permissions.add("bukkit.command.plugins");
    
    attrConfig.addDefault("permissions.default.id", 0);
    
    attrConfig.addDefault("permissions.default.nameColor", "white");
    
    attrConfig.addDefault("permissions.default.chatColor", "gray");
    
    attrConfig.addDefault("permissions.default.permissions", permissions);
    
    
    permissions.add("minecraft.command.kick");
    
    attrConfig.addDefault("permissions.trusted.id", 1);
    
    attrConfig.addDefault("permissions.trusted.nameColor", "blue");
    
    attrConfig.addDefault("permissions.trusted.chatColor", "white");
    
    attrConfig.addDefault("permissions.trusted.permissions", permissions);
    
    
    permissions.add("minecraft.command.difficulty");
    
    attrConfig.addDefault("permissions.mod.id",2);
    
    attrConfig.addDefault("permissions.mod.nameColor", "green");
    
    attrConfig.addDefault("permissions.mod.chatColor", "white");
    
    attrConfig.addDefault("permissions.mod.permissions", permissions);
    
    
    permissions.add("minecraft.command.ban");
    
    attrConfig.addDefault("permissions.admin.id", 3);
    
    attrConfig.addDefault("permissions.admin.nameColor", "red");
    
    attrConfig.addDefault("permissions.admin.chatColor", "white");
    
    attrConfig.addDefault("permissions.admin.permissions", permissions);
    
    
    permissions.add("minecraft.command.deop");
    
    attrConfig.addDefault("permissions.owner.id", 4);
    
    attrConfig.addDefault("permissions.owner.nameColor", "gold");
    
    attrConfig.addDefault("permissions.owner.chatColor", "white");
    
    attrConfig.addDefault("permissions.owner.permissions", permissions);
    
    attrConfig.options().copyDefaults(true);
    
    
    try {
    
    msgConfig.save(ServerHandler.getMSGFile());
    
    attrConfig.save(ServerHandler.getAttrFile());
    
    } catch (IOException e) {
    
    this.getLogger().severe("Got IOException when saving defaults on the configuration files");
    
    }
    
    
    but config looks like this

    Code:
    permissions:
      default:
        id: 0
        nameColor: white
        chatColor: gray
        permissions: &id001
        - bukkit.command.plugins
        - minecraft.command.kick
        - minecraft.command.difficulty
        - minecraft.command.ban
        - minecraft.command.deop
      trusted:
        id: 1
        nameColor: blue
        chatColor: white
        permissions: *id001
      mod:
        id: 2
        nameColor: green
        chatColor: white
        permissions: *id001
      admin:
        id: 3
        nameColor: red
        chatColor: white
        permissions: *id001
      owner:
        id: 4
        nameColor: gold
        chatColor: white
        permissions: *id001
    
    anybody know why?
    (ignore the admin, id and name color things, that works and is in other pieces of code)
     
  2. Offline

    Symphonic

    The list needs to be a "new List<String>()" not an arraylist
     
  3. Offline

    timtower Moderator Moderator

    You can't call that though as List is an interface and has no constructors.
     
  4. Offline

    KarimAKL

  5. Offline

    MrDaniel

    @KarimAKL, fixed it, thx

    For anybody that also has this issue the thing you need to do is not use the same object for different fields cause YAML will just include a reference to that object.
     
    KarimAKL likes this.
Thread Status:
Not open for further replies.

Share This Page