Yaml access.

Discussion in 'Plugin Development' started by Nic2555, Nov 24, 2014.

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

    Nic2555

    Hey guys,
    I got a big problem. I've been searching on the internet and find nothing about it.
    I need a function that will return me the permission of a plugins. The things is, that I don't wanna use bukkit libs for that, I would like to make it independent. How could I return an ArrayList of all the permission of a certain plugins, located in a directory. For exemple " C:\User\Desktop\Minecraft\Plugins"
    Thanks !

    - Nic,.
     
  2. Offline

    Skionz

    Nic2555 You want to get the file as in the file PermissionsEX as an example stores permissions in? You should probably look into BufferedReaders if you don't know them already.
     
  3. Offline

    Nic2555

    What I want it everythings under Permission: pushed into an arraylist.
    here an exemple :
    Code:
    permissions:
      lottery.*:
          description: Full access to Lottery plugin.
          children:
              lottery.buy: true
              lottery.admin.draw: true
              lottery.admin.addtopot: true
              lottery.admin.editconfig: true
      lottery.buy:
          description: Basic lottery rights. Can buy, check lottery info and claim winnings.
          default: true
      lottery.admin.draw:
          description: Access to /lottery draw command.
          default: op
      lottery.admin.addtopot:
          description: Access to /lottery addtopot command.
          default: op
      lottery.admin.editconfig:
          description: Access to ingame config editing and reloading.
          default: op
    
    I just need the name of the permission and another arrayList for the description,
    that would be awesome :D

    <Edit by mrCookieSlime: Merged posts. Please dont double post. There is an Edit-Button right next to the Date.>
     
  4. Offline

    acer5999

    Bad idea, use HashMaps if your storing 2 values that are closely related such as a permission(Key) and a description (Value)
    Code:java
    1. //Example:
    2. HashMap<Key,Value> example = new HashMap<>();
    3.  
    4. //Application:
    5. HashMap<String,String> perms = new HashMap<>();
    6. perms.put("lotto.create", "creates a lottery");
    7. // Puts Key(lotto.create) and Value (creates a lottery) in to the hashmap, "creates a lottery" is now the value for key "lotto.create"
    8.  
    9. public String getDesc(String perm) {
    10. if(perms.contains(perm)) //Checks if perms contains the key perm{
    11. return perms.get(perm);
    12. //returns the value of perm
    13. }
    14. }

    That could may or may not work, I wrote it in browser
     
  5. Offline

    Nic2555

    Could I sort the HashMap in a two colum list after that ?
    Like :
    [] (checkbox) {Permission} {Description}
     
  6. Offline

    Skionz

    Nic2555 You could iterate through every line using a BufferedReader and then parsing the String.
    EDIT: So you want to be able to get values from your "plugin.yml" file or the "permissions.yml" file in PermissionsEX?
     
  7. Offline

    acer5999

    As far as I know you could but I'm not super experienced with HashMaps, loop through all the entries and print them out into each column maybe?
    Edit: Aw man, Ninja'd
     
  8. Offline

    Nic2555

    Skionz I want to get the Permission in the plugins.yml file in the {plugins}.jar.
     
  9. Offline

    Skionz

    Nic2555 A few quick googles found me this:
    Code:
    File file = new File(this.getClass().getResource("path/to/file.txt").getFile());
    Then you could try something like
    Code:
    FileConfiguration theFile = YamlConfiguration.loadConfiguration(file);
    No idea if this will work but it is worth a shot
     
  10. Offline

    Nic2555

    the Yaml configuration is based on Bukkit, which I don't want.
     
  11. Offline

    mythbusterma

    Nic2555

    Provide a valid reason why you shouldn't use YAML in a plugin. Also, it isn't "based on Bukkit," it's a separate library called "SnakeYAML."

    What's your issue with it? You also haven't even told us what your problem is, as you can't use anything other than YAML to create the plugin file.
     
  12. Offline

    Skionz

    Nic2555 Then your going to have to go pretty deep. Here is how to read a file line by line. You will have to parse each line yourself.
    Code:
    BufferedReader reader = new BufferedReader(new FileReader("stuff.txt");
    for(String line; (line = br.readLine()) != null;) {
        String key = line.substring(0, line.indexOf(":"));
    }
    reader.close();
    if the file has one line and looks like
    Code:
    thisKey: 'value'
    key will equal "thisKey"
     
  13. Offline

    Nic2555

    mythbusterma The yaml are allready created, i just need to use them. they are in the plugin.jar, I need to use them. this is the issue.
    But i'll try the YAMLconfiguration things.
     
Thread Status:
Not open for further replies.

Share This Page