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

How get a name of offline players?

Discussion in 'Development' started by DanielYTK, Jan 27, 2017.

  1. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    I'm working in a plugin of votation, and need get name of offline player, how do this?
     
  2. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Sorry, I need of name of all offline players
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    you will need to store a list of players...
    and check if any is online the reset is the ones that are not online,
    ps this will not be the most efficient method
     
  4. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    exists other method?
     
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    By offline you mean those that has .dat file in /players/ that is not online?
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    PHP:
    $files scandir(Server::getInstance()->getDataPath()."players/");
    $players = [];
    foreach(
    $files as $file) {
        
    $players[] = rtrim($file".dat");
    }
    return 
    $players;
     
    Skullex likes this.
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    What do you want to do? You may be loading millions of strings in an array... Terrible performance...
     
    Skullex and Muqsit like this.
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    It's even worse than opening 3 tabs in Google Chrome... :p
     
  9. HBIDamian

    HBIDamian HBIDamian Staff Member

    Messages:
    365
    GitHub:
    HBIDamian
    Or as bad as loading a big program on a loop.
    Code:
    @echo off
    REM notepad.exe causes MASSIVE lag when on loop. ;)
    :startloop
    start notepad.exe
    goto startloop
    
    Basically... the point is: Don't do that method.
     
    Last edited: Jan 27, 2017
    Sandertv and HimbeersaftLP like this.
  10. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    Olhe meu código:

    <? Php

    Namespace DanielYTK;

    Use pocketmine \ Player;
    Use o pocketmine \ Server;
    Use pocketmine \ command \ Command;
    Use o comando pocketmine \ command \ CommandSender;
    Use pocketmine \ utils \ Config;
    Use pocketmine \ event \ Listener;
    Use pocketmine \ event \ player \ PlayerCommandPreprocessEvent;
    Use o pocketmine \ plugin \ PluginBase;


    Classe Main extends PluginBase implementa Listener {

    Public function onEnable () {
    @mkdir ($ this-> getDataFolder ());
    $ This-> config = new Config ($ this-> getDataFolder (). "Votos.json", Config :: JSON, Array ());
    $ This-> config-> set ("votacao", "fechada");
    $ This-> config-> set ("Sim", 0);
    $ This-> config-> set ("Nao", 0);
    $ This-> config-> save ();
    }
    Public function onDisable () {}

    Public function onCommand (CommandSender $ sender, Comando $ command, $ label, array $ args) {
    Switch (strtolower ($ command-> getName ())) {
    Caso "votar":
    $ Sim = 0;
    $ Não = 0;
    $ Player = $ sender-> getPlayer ();
    If (isset ($ args [0])) {
    If ($ args [0] === "sim") {
    If ($ this-> config-> get ("votacao") === "fechada") {
    $ Sender-> sendMessage ("[§5Votação§f] Não existe votação aberta");
    Retorna;
    }
    Foreach (Server :: getInstance () -> getOnlinePlayers () como $ player) {
    $ Nick = $ this-> config-> get ($ player-> getName ());
    If ($ this-> config-> exists ($ player-> getName ())) {
    $ Player-> sendMessage ("[§5Votação§f] Você já não pode votar novamente!");
    Retorna;
    }
    }
    $ This-> config-> set ("Sim", $ this-> config-> get ("Sim") + 1) ;;
    $ This-> config-> set ($ player-> getName (), ["Voto" => "sim"]);
    $ Sender-> sendMessage ("§Voto registrado! Se você sair do servidor o voto será anulado!");
    $ This-> config-> save ();

    }

    If ($ args [0] === "nao") {
    If ($ this-> config-> get ("votacao") === "fechada") {
    $ Sender-> sendMessage ("[§5Votação§f] Não existe votação aberta");
    Retorna;
    }
    Foreach (Server :: getInstance () -> getOnlinePlayers () como $ player) {
    $ Nick = $ this-> config-> get ($ player-> getName ());
    If ($ this-> config-> exists ($ player-> getName ())) {
    $ Player-> sendMessage ("[§5Votação§f] Você já não pode votar novamente!");
    Retorna;
    }
    }
    $ This-> config-> set ("Nao", $ this-> config-> get ("Nao") + 1);
    $ This-> config-> set ($ player-> getName (), ["Voto" => "nao"]);
    $ This-> config-> save ();
    $ Sender-> sendMessage ("§Voto registrado! Se você sair do servidor o voto será anulado!");

    }
    } outro {
    $ Sender-> sendMessage ("[§5Votação§f] Use / votar sim ou / votar não");
    }
    pausa;
    Caso "votacao":
    $ Motivo = implode ("", $ args);
    $ Motivo2 = explode ("", $ motivo);
    Unset ($ motivo2 [0]);
    $ Motivo = implode ("", $ motivo2);
    If (! Isset ($ args [0])) {
    $ Sender-> sendMessage ("[§5Votação§f] Utilização / votacao abrir <motivo> ou / votacao fechar");
    }
    If ($ args [0] === "abrir") {
    $ This-> config-> set ("votacao", "aberta");
    $ This-> config-> save ();
    Server :: getInstance () -> broadcastMessage ("[§5Votação§f] O jogador". $ Sender-> getName (). "Iniciou uma votação ->". §fou §5 / votar não §f] ");
    }
    If ($ args [0] === "fechar") {
    Foreach (Server :: getInstance () -> getOnlinePlayers () como $ player) {
    If ($ this-> config-> exists ($ player-> getName ())) {
    $ This-> config-> remove ($ player-> getName ());
    }
    }
    $ This-> config-> set ("votacao", "fechada");
    $ This-> config-> save ();
    Servidor :: getInstance () -> broadcastMessage ("[§5Votação§f] Resultado: [Sim: §5". $ This-> config-> get ("Sim"). -> config-> get ("Nao"). "§f]");
    $ Este-> config-> set ("Sim", 0);
    $ This-> config-> set ("Nao", 0);
    $ This-> config-> save ();
    }
    }
    }
    }

    - When a player executes yes / no vote, the player's nick will be saved in a ".json" file, but if the player drops the server, after having voted and before the voting ends, even if I finish The vote the nick of the player will be in the file ".json" and when I open another poll, the player with the nick there, will not be able to vote, then ... I thought the best part of doing this was getting the nick of Players off.


    Desculpe, não consigo usar github
     
  11. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    USE CODE TAGS
     
  12. DanielYTK

    DanielYTK Zombie

    Messages:
    227
    whats?
     
  13. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    [PHP]Your php code[/PHP]
    OR FOR NON-PHP CODE:
    [CODE]Put code that's not php (e.g. Yaml files) in code tags[/CODE]
     
  14. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Code:
     [PHP] //your code here\\ [/PHP] 
     
  15. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    we posted at the exact same time -_-
     
    jasonwynn10 likes this.
  16. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    xD
     
    jasonwynn10 likes this.
  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.