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

Minutes Played

Discussion in 'Development' started by XxCodeRedxX, Dec 7, 2017.

  1. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
    How would could I make it where it pops up a tip on the side of the screen and says "Time: ###Minutes"
     
  2. KittyDev

    KittyDev Slime

    Messages:
    96
    GitHub:
    FreakingDev
    Any attempt?
     
  3. XxCodeRedxX

    XxCodeRedxX Witch

    Messages:
    68
  4. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  5. Ant

    Ant Spider

    Messages:
    9
    GitHub:
    Dead
    PHP:
    public $registry = [];

    onPlayerJoin
    $this
    ->registry[$player->getName()] = time();

    Timer
    $player
    ->sendTip(format(time() - $this->registry[$player->getName()]));

    function 
    format(int $time) : string {
        return 
    floor($time 60).":".($time % / 60);
    }
    You will also need to save the registry somewhere.

    PHP:
    (new Config($plugin->getDataFolder()."registry.yml"Config::YAML$this->registry))->save();
    // And load
    $this->registry = (new Config($plugin->getDataFolder()."registry.yml"Config::YAML$this->registry))->getAll();
     
    Last edited: Dec 7, 2017
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    If you only use it to get all data you might as well use yaml_parse_file instead of using a Config.
     
    Ant likes this.
  7. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    wouldnt that clash with first register/seen by plugin date?
    as i could log on, play 3 min, log off for 1 day and play 1 hour
    my time should be 1 hour 3 min, not 1 hour because you didnt account for someone might already have played
    but ill blame this on OP for not giving details
     
    Ant likes this.
  8. Ant

    Ant Spider

    Messages:
    9
    GitHub:
    Dead
    I'm not coding a plugin for him, just showing how it might be done.
     
  9. QuiverlyRivalry

    QuiverlyRivalry Zombie Pigman

    Messages:
    491
    GitHub:
    quiverlyrivalry
    I made some sort of attempt of the plugin, for my server might make it public.
    We also have to take in that, the players time resets on server restart
     
  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.