need some ideas for event handling configuration files

Discussion in 'Plugin Development' started by xize, Sep 1, 2013.

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

    xize

    Hello,

    I'm wondering since some while whats the most efficients way for handling events with configuration files?

    as for now I use some events which open a file and check a boolean, but that could mean it opens like 100 times per invidual player which could be kinda dramatic as I'm planning to make a essentials like plugin.

    my older system whas registering the event only when the configuration boolean whas true and so on I had 100 diffrent class files per configuration option and around 100 diffrent registrations, which kinda doesn't feel right.

    whats the best approach or better way of doing this?

    thanks:D
     
  2. Offline

    metalhedd

    Save the value in memory instead of reading it from the file every time.

    It's right if you have 100 different features that can be individually disabled. There's also no reason you can't put them all in the same listener and just skip the appropriate checks for the features that are disabled, either way is 'fine', but feel free to benchmark and choose the one that's most efficient in your particular case.
     
  3. Offline

    xize

    metalhedd
    thanks for saying this, also I had a new idea but maybe I'm mistaken:p
    what if I store all keys and values into a HashMap maybe with a linkedList when the player joins(not sure if a nested '.' could work like in a config) and use it through that way and remove the player key again when the player leaves could that be better?
     
  4. Offline

    metalhedd

    You could do that, but you can't use the . separators like you can in yaml. what kind of data do you need to store per-player? you should probably create a class to hold it all if its more than a single value, then store instances of that class in the hashmap, keyed on player names.
     
  5. Offline

    xize

    so ive came to a idea to write a small api to load all configuration variables into memory but I'm not sure if this is doing anything good though as I'm litterly storing things into memory, and for player files I'm storing keys and values through a double HashMap, any ways I know I should remove the key when the player leaves or get kicked:p

    my code is: https://github.com/xize/xEssentials/blob/master/src/tv/mineinthebox/xEssentialsMemory.java

    I like to get some feedback if its good or bad to do this.

    thanks:)
     
  6. Offline

    FurmigaHumana


    in my opnion this is the best method you could use.

    But I think your code wont work, static references are the same on every instance, which means that every value will be the same for every player (matching the last player that was loaded), just create a new class like the xEssentialsMemory with all "global" methods and another one without static methods/values with all player values ;3
     
Thread Status:
Not open for further replies.

Share This Page