How to save information?

Discussion in 'Plugin Development' started by Growl, Mar 8, 2014.

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

    Growl

    Hi, guys. I need your help again.
    What I need:
    There are some Permissions in a Plugin. First Permission can teleport Player to the place "1", second Permission - to the place "2", third Permission - to the place "3"(it might be not a teleportation). Player can Buy some of the Permissions with his own expirience. To save information about Player who owns some of them I want to create 3 files: "First", "Second" and "Third". In every file would be only names of the owners. And it would be cool if you can help me with a command which writes or removes names of the owners in the files.
    Maybe I want so much from you, but if you can - help me please:)
    P.S. I can`t use plugin PermissionEX or something like it.
     
  2. Offline

    LarsNitro

    You'll at least need to have a reader. Take a look at some videos, and store it playername:permission.
    You shouldn't have the command edit the file immedeatly, but rather a HashMap<String (playername, that is.), String (Permission). Make the HashMap read the information in onEnable, and write in onDisable.
    Reccomended search: Java Reading and Writing Files.
    Remember to make the path:

    File folder = new File(getDataFolder().getParent() + \\NameOfPlugin);

    File f = new File(fi + \\First.yml);
    File f2 = new File(fi + \\Second.yml);
    File f3 = new File(fi + \\Third.yml);

    Remember to check if the folder and Files exist before you do createNewFile(); and mkdir();
    If you have a config file, the folder might be created automatically.


    Code:java
    1. if (!folder.exists()) {
    2. log.info("[" + file.getName() + "] INFO: can't find directory file. Attempting to create a new one...");
    3. folder.mkdir();
    4. }
    5.  
    6. if (!f.exists()) {
    7. log.info("[" + file.getName() + "] INFO: can't find players file. Attempting to create a new one...");
    8. try {
    9. f.createNewFile();
    10. } catch (IOException e) {
    11. log.warning("[" + file.getName() + "] ERROR: failed to create file!");
    12. e.printStackTrace();
    13. }
    14.  
    15. }
     
Thread Status:
Not open for further replies.

Share This Page