Efficient way to save data : Help with classes/test plugin: + 2 More

Discussion in 'Plugin Development' started by CarlosArias604, Jun 22, 2012.

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

    CarlosArias604

    Hello Bukkit Community

    I was wondering what is the most efficient way to save data and how would I go about doing so? As I new to Java and I don't know the best way to save data, The closest thing I know is using the config to save data.
    The reason I would like this is that I am working on a plugin that needs to save data similar to a economy plugin, In which I can save points to a user or vice versa. This would also be great for my knowledge.


    My second thing I need help with is with using multiple classes, This is very essential as I don't want to keep everything in one 2000+ lined class and it would just get out of hand... I also know that some stuff does need to be in another class.
    Basically I want to keep "Chat Helpers" in one big reference class that every class would be connected in, Here is the beginning of my class for the "Chat Helper" which is named "EE_Colours" currently.
    http://pastie.org/4130827 (Chat Class)
    Another problem I have is with my "LoginListener", In which I would to send joining players a message, Similar to Mcmmo's message about the version and that. From what I know I would need to add a timer to delay the message until they are logged in, I have read the wiki but from what I have tried the delayed tick timer doesn't work? I assume I have misused it... Hopefully you can clarify this and here is the class.
    http://pastie.org/4130809 (Login Class)
    My final problem with my test plugin is the main class, As I am not sure if it is implementing the other classes properly and how I should do this? I would also like to know if I import the "EE_Colours" class will it automatically change every string to colour code or do I have to use some line of code to activate it?
    http://pastie.org/4130812 (Main Class)


    My second to last question would be true and false settings in the config, As I would like to make things optional like the welcome message, I have been told this would use a 'Boolean' but I am have no idea where to start with this. I have learned about the basics of a 'Boolean', I plan to learn more when a certain library book gets returned... (Forgot my card when it was in :/)
    Anyway how would I do this?

    The last question (Thank god) is about Hashmaps, This is not directly a proper question about Bukkit but more Java. The question being, Do you know where to learn about 'Hashmaps' and 'HashTables'? I have looked the 'TheNewBoston' but I didn't see anything named "Hash-Anything". It may have been listed under something else but that's not the point.
    I guess to be more on the 'Bukkit' topic I was wondering how could I use Hashmaps and how would they be useful? The only thing I can think of is Hunger Games and those type of plugins, Maybe you could explain this more?


    Thank you for your time and I hope someone can help me with these questions, Thank you! ;)

    Sincerely
    Carlos
     
  2. Offline

    Jeff.Halbert

    the MOST EFFICIENT way to save data would to be in a database, whether relational or flatfile. another easy alternative is of course, custom configs(which is also flatfile).

    here's a like for hashmaps...
    http://www.java-samples.com/showtutorial.php?tutorialid=369

    for your boolean question....
    in your config.yml, make a node then set it to either true or false, like this...
    Code:
    # yml example
    booleanNodeName: true
    then in your program, you can call the value of that boolean, like this....
    Code:
    boolean value = getConfig().getBoolean("booleanNodeName");
    I have some reading to do if i'm gonna answer the rest of your questions....lol

    in your main class, your pdf value is unused.....

    also, you have to register your listener class, like this....
    Code:
    public void onEnable() {
        //your log
        //your config
        //save config
        PluginManager pm = getServer().getPluginManager();
        pm.registerEvents(new listenerClassName, this);
    }
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  3. Offline

    CarlosArias604

    Okay thanks, How would I make a flat file data file?

    [Edit]
    Oh yea I haven't gotten around to using it yet, I plan to use it but just to make it short I decided to ignore it at the moment.

    -C
     
  4. Offline

    Jeff.Halbert

    in your listener class, you make a new instance of your main plugin, not needed, and unused.

    if you want to reference your method in your colors class, then you have to make it static. also, the method is never called anywhere else in your code....

    use the File method....
    here's a link
    http://www.roseindia.net/java/beginners/java-write-to-file.shtml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
Thread Status:
Not open for further replies.

Share This Page