Getting list from a file

Discussion in 'Plugin Development' started by DogeDebugger, Mar 31, 2015.

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

    DogeDebugger

    So i have multiple ymls in my plugin's data folder which each contain a list called "members"

    Code:
    members: [Dogeritos, Dogescoper]
    
    How do i go through all the files in the data folder and find which one's list contains a certain string?

    Btw, I'm using lovely @nverdier 's EnviousAPI for my files :p
     
    Last edited: Mar 31, 2015
  2. config.getStringList("key");
     
  3. Offline

    DogeDebugger

    Okay but...

    I want to loop through all the files in the data folder and find which one contains a certain key .-. Help please :D
    @FisheyLP

    sorry for early bump but i really need help on this :/

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

    Protophite

    Code:
    String path = "YOUR_PATH";
    File folder = new File(path);
    File[] listOfFiles = folder.listFiles();
    
    for(File p : listOfFiles){
        //code
    }

    @DogeDebugger
     
  5. Offline

    DogeDebugger

    @Protophite

    How do i read the files? More specifically, check if it contains a certain string
     
    Last edited: Mar 31, 2015
  6. Offline

    Protophite

    @DogeDebugger

    Code:
    YamlConfiguration a = YamlConfiguration.loadConfiguration(p);
    String test = a.getString("YOUR_PATH");
     
  7. Offline

    DogeDebugger

    @Protophite

    wow thanks :D

    @Protophite

    Hey, can you help me with this code? It's supposed to see if both player's names are in the same file.
    Code:
    @EventHandler
        public void hit(EntityDamageByEntityEvent event) {
            Bukkit.getServer().broadcastMessage("test messsage 1");
            Player e = (Player) event.getEntity();
            Entity e2 = ((EntityDamageByEntityEvent) e).getDamager();
            String path = "plugins/UHCTeams";
            File folder = new File(path);
            File[] listOfFiles = folder.listFiles();
    
            for (File p : listOfFiles) {
                YamlConfiguration a = YamlConfiguration.loadConfiguration(p);
                if (a.getStringList("members").contains(((Player) e2).getName())
                        && a.getStringList("members").contains(e.getName())) {
                    Bukkit.getServer().broadcastMessage("test message 2");
                    event.setCancelled(true);
                }
            }
        }
     
    Last edited by a moderator: Apr 1, 2015
  8. Don't try to do that ... You're looping all files whenever a entity hit another entity, and you didnt even check if the entity and the damager are players.
     
  9. Offline

    CullanP

    If you're doing what I think you're doing. I'd recommend using a hashmap and just storing the player-name/team and then checking if they're inside the map on the same team. If they are, just cancel the event or if you're just keeping player names in a yml and never removing them from the file. You could store the players in the map from the yml and then use it in your event. This would drastically reduce the lag
     
  10. Offline

    DogeDebugger

    The situation won't have any mobs besides players.

    Okay, that makes sense. How can i create a new Hashmap/Team when a player does a command to create a new team?

    @justin_393

    um
    ok

    Do u know how to save a hashmap in a yml?

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

    meguy26

  12. Offline

    DogeDebugger

Thread Status:
Not open for further replies.

Share This Page