1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

get Top player

Discussion in 'Facepalm' started by Kyd, May 29, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I have skywars plugin where I have created .yml class for every joined player. In config player has score example:
    Code:
    score: 101001
    How I get score in all these files and get best score? I dont have any idea now
     
  2. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Take a look at my factions plugin, specifically these lines of code:

    https://github.com/TheDiamondYT1/Po...etFactions/provider/JSONProvider.php#L60-#L69

    Instead of json_decode, use yaml_parse and change any mentions of json to yml.

    Example
    PHP:
    $scores = [];
    $directory $this->plugin->getDataFolder() . "players/";
    foreach(new \
    RecursiveIteratorIterator(new \RecursiveDirectoryIterator($directory)) as $file => $players)
        if(
    pathinfo($file)["extension"] === "yml") {
            
    $players yaml_parse(file_get_contents($players));
            
    $scores[$players["score"]] = $players["score"];
            echo 
    max($scores);
        }
    }
    This code is not tested.

    Written on a phone
     
    Last edited: May 29, 2017
  3. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.