Skip to content

What is the correct usage for this situation? #2

@tienthanh2929

Description

@tienthanh2929

Let's say I want to load a list of the same type of object, but with different data.

For example, I have a Foo object:

class Foo {
  long price;
  String identifier;
  String permission;

  public Foo(int price, String identifier, String permission) {
     // assign to variables
  }
}

In my config file:

foos:
  myFoo: # identifier
    price: 100 #price
    permission: 'perm.myFoo' #permission
  myAnotherFoo:
   price: 200
   permission: 'perm.myAnotherFoo'

If I want to load in a traditional way, I just loop through all foos keys then create each individual Foo objects.

for(String key : config.getConfigurationSection("foos").getKeys(false) {
   String identifier = key;
   String permission = config.getString("foos." + key + ".permission");
   long price = config.getLong("foos." + key + ".price");
 
   Foo foo = new Foo(price, identifier, permission);
   // proceed to store Foo somewhere else
}

So what is the correct usage for this situation with your plugin? Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions