[UNSOLVED] Custom YML get information.

Discussion in 'Plugin Development' started by MordorKing78, Apr 12, 2014.

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

    MordorKing78

    Intro: Heey!
    My Problem: So i created if an player buys the permissions then it will add a line in the permissions.yml like this:
    MordorKing78:
    - Earthquake.Hat.Dirt
    But i want to check if a player haves the permissions and than search for this ^^ permissions! Can anyone help me with it?
    Get Permissions in YML Code:
    Code:java
    1. public static void DirtHatBuy(Player p) {
    2. EconomyResponse r = econ.withdrawPlayer(p.getName(), 180.0);
    3. if (r.transactionSuccess()) {
    4. permissionsfile.createSection(p.getName());
    5. DirtHat.add("Earthquake.Hat.Dirt");
    6. permissionsfile.set(p.getName(), DirtHat);
    7. savePermissionsConfig();
    8. p.sendMessage("§8[§cMatriz§8] §aYou successfully bought the Dirt Hat! Go to the Wardrobe to use ur new Hat!!");
    9. } else {
    10. p.sendMessage("§8[§cMatriz§8] §cYou dont have enough Pearls to buy this hat!");
    11. }
    12. p.closeInventory();
    13. }

    So..: Can anyone help me with getting the permissions in the file? (I dont know if you can use p.hasPermissions(permissionsfile. etc.) Plzz help me! Thanks!

    Reactions please :D

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  2. Offline

    rohan576

    MordorKing78
    Please don't post two times in a row without waiting a period of 24 hours.
    I went over this post, but I decided not to say anything because I couldn't quite understand what you need. Perhaps you could explain it in a bit more detail, or give more context?
     
  3. Offline

    MordorKing78

    rohan576 Euhm im trying to make checking the permissions in the file .yml

    rohan576 Like p.hasPermissions("mypermissions"). but I want that he gets permission from the yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    rohan576

    MordorKing78
    You disregarded the first thing I said in my post. Also, please don't spam my inbox to get help from me. I find that very rude.
     
  5. Offline

    MordorKing78

    rohan576 Lol, I did read the first thing -,- and whats rude about finding help?
     
  6. Offline

    rohan576

    MordorKing78
    The first thing was asking you not to double post, which you did anyway .-.

    And what I meant is that I didn't really appreciate it that you sent me a conversation asking for help. I saw your tahg.

    Anyway, for the YML, I think that you might want to rethink the way in which you're formatting it.
     
  7. Offline

    MordorKing78

    rohan576 So.. I will start again: (Sorry)
    Ey, Could u help me with creating this? Because i created everything! If a player buys a item in the shop, Then will there be a text generated in permissios.yml >>
    MordorKing78:
    - Earthquake.Hat.Dirt
    ________________
    And what i am trying to do is getting this permissions like: if(p.hasPermissions(permissionsfile.equals("OrSomethingIdk")); << I know this woud not work :p
    So check if a player have´s this permission. (In the YML File) Plz could u help me with it? :) <3
     
  8. Offline

    rohan576

    Here, have this. I made this a while ago; perhaps you could format it to your liking.

    Add an item:
    Code:java
    1. public static void addItem(String player, String upgradeSection, String shopItem) {
    2. String p = UUIDUtil.getUUID(player);
    3. if (!yml.contains(p)) {
    4. yml.createSection(p);
    5. }
    6. if (!yml.contains(p + ".purchased")) {
    7. yml.createSection(p + ".purchased");
    8. }
    9. if (!yml.contains(p + ".purchased." + upgradeSection)) {
    10. yml.createSection(p + ".purchased." + upgradeSection);
    11. }
    12. List<String> clone = yml.getStringList(p + ".purchased." + upgradeSection);
    13. clone.add(shopItem);
    14. yml.set(p + ".purchased." + upgradeSection, clone);
    15. }


    Check for an item:
    Code:java
    1. public static Boolean checkForItem(Player player, String upgradeSection, String shopItem) {
    2. String p = UUIDUtil.getUUID(player.getName());
    3. if (!yml.contains(p)) {
    4. yml.createSection(p);
    5. }
    6. if (!yml.contains(p + ".purchased")) {
    7. yml.createSection(p + ".purchased");
    8. }
    9. if (!yml.contains(p + ".purchased." + upgradeSection)) {
    10. yml.createSection(p + ".purchased." + upgradeSection);
    11. }
    12. if (yml.getStringList(p + ".purchased." + upgradeSection).contains(shopItem)) {
    13. return true;
    14. }
    15. else {
    16. return false;
    17. }
    18. }


    Though a lot is already done for you, you'd still need to make many changes to fit it into your environment. I'd suggest just using it as a guide or reference. Also, you may want to swap the UUIDs to player names, I've just updated my plugin to support UUIDs.
     
  9. Offline

    MordorKing78

    rohan576 Il check it out, I have already got over 0.5k lines of code. I had already an item and shop etc. but il check it out ;) Thanks!

    rohan576 Eurhm, I want to work with permissions, Could you help me with that?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  10. Offline

    rohan576

    To see if a player has a permission, just do <Player>.hasPermission("permission.permission");
    As for coding a custom permissions plugin, you can look that up, although I wouldn't see why the methods I gave you wouldn't work for that purpose, with some editing.
     
  11. Offline

    MordorKing78

    Yes, But i want to check if a player haves the permissions in the permissions.yml file
     
  12. Offline

    rohan576

  13. Offline

    MordorKing78

    But i want to check if the permissions is in the yml file.
     
Thread Status:
Not open for further replies.

Share This Page