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

other server online players

Discussion in 'Development' started by amirTBM, Jan 30, 2020.

  1. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    hi i have a multi server server and i need a plugin that show the online players on the slappers and in the scorehud how can i make it?
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:
    const LINK_ONLINE 'https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]';

    /*
    *@Param Server IP $ip
    *@Param Server Port $port
    */
    public function getOnlineServerPlayers(string $ipint $port) : int{
        
    $result str_replace(["[IP]""[PORT]"], [$ip$port], self::LINK_ONLINE);
        
    $online = \pocketmine\utils\Internet::getURL($result);
        return 
    is_int($online) ? $online 0;
    }
     
    ethaniccc likes this.
  3. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Note that this will hang your server while doing the HTTP request, if you don't want that you can either manually put that into an AsyncTask or use PM's BulkCurlTask (see https://github.com/HimbeersaftLP/Li.../src/Himbeer/LibSkin/SkinGatherer.php#L32-L53 for an example)
     
    ethaniccc and GamakCZ like this.
  4. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    tnx very much
     
  5. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    sorry but how can i use it in scorehud? =D
     
  6. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP:
    $online = (int)file_get_contents("https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]");
     
  7. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    where i have to type it?
     
  8. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    Where you want. However you wanted to use it for scoreboard and slappers....
     
    HimbeersaftLP likes this.
  9. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    but its not working in the scorehud =(
     
  10. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    my eror is this
     
  11. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    Screenshot (31).png
     

    Attached Files:

  12. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    You have to use it outside of " "
     
  13. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
    he is using Scorehud, you must edit/make an addon for that.
     
  14. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    its not working now too
     
  15. Fadhel

    Fadhel Witch

    Messages:
    68
    GitHub:
    dimbis
     
  16. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
  17. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    Could you send us the whole code function
     
  18. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    To do this, you need to make a new addon, which should be located in the plugin_data folder. You have to make a new add-on, and you will also need some logic to do this (not trying to offend anyone here!)

    This is what I have made for my server:

    PHP:
    <?php

    declare(strict_types 1);

    /**
     * @name KitPvP
     * @version 1.0.0
     * @main    JackMD\ScoreHud\Addons\KitPvP
     */

    namespace JackMD\ScoreHud\Addons{
        
        use 
    JackMD\ScoreHud\addon\AddonBase;
        use 
    pocketmine\Player;
        use 
    pocketmine\utils\Internet;
        use 
    pocketmine\Server;
        
        class 
    KitPvP extends AddonBase{
            
            const 
    LINK_ONLINE 'https://minecraft-api.com/api/query/playeronline.php?ip=[IP]&port=[PORT]';

            
    /**
             * @param Player $player
             * @return array
             */
            
            
    public function getProcessedTags(Player $player): array{
            
            
    $online = (int)file_get_contents("https://minecraft-api.com/api/query/playeronline.php?ip=51.79.76.77&port=41021");
                
                return [
                    
    "{kitpvp}" => $online
                
    ];
                
            }
            
            
    /*
            *@Param Server IP $ip
            *@Param Server Port $port
            */
            /*
            public function getOnlineServerPlayers(string $ip, int $port) : int{
                $result = str_replace(["51.79.76.77", "41021"], [$ip, $port], self::LINK_ONLINE);
                $online = \pocketmine\utils\Internet::getURL($result);
                return is_int($online) ? $online : 0;
            }
            */
            
            
        
    }
        
    }
    The file name is KitPvP.php, which is why the class is also called KitPvP, and why the name in the note (necessary for some reason) is KitPvP.

    Please keep in note: This will stop your server occasionally (unnoticeable) becuase it will attempt to retrieve the files from Minecraft's API.

    P.S: Check out my kitpvp server if you don't mind (SORRY LMAOOO) :D

    ~ Ethaniccc </3
     
  19. ethaniccc

    ethaniccc Baby Zombie

    Messages:
    189
    GitHub:
    ethaniccc
    Haven't figured out how to do that with the Scoreboard Addons yet, if you could help me with that? When I made the Scoreboard plugin above (check my other comment for reference), I noticed it would like do a mini-stop on my server while doing the HTTP request. By any chance could you help me?
     
  20. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Feel free to copy the function from my virion above and then use it like this:
    PHP:
    asyncHttpGetRequest("https://minecraft-api.com/api/query/playeronline.php?ip=51.79.76.77&port=41021", function ($response) {
      
    $body $response[0];
    });
     
    ethaniccc 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.