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

RealPing

Discussion in 'Requests' started by Daniel23, Nov 29, 2017.

  1. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    The point is that there is no reason to write so much extra code (like static config getters, an individual PluginCommand class, etc.) when you could have just declared the command in plugin.yml, and then your whole plugin can be simplified to just a few lines of code :D
    Code:
    name: Pinger
    version: 1.0
    author: Fris
    api: [3.0.0-ALPHA10]
    main: friscowz\Pinger
    commands:
      ping:
        aliases: [ms, latency, pinger]
    
    PHP:
    <?php
    namespace friscowz\pinger;

    use 
    pocketmine\command\{CommandCommandSender};
    use 
    pocketmine\Player;
    use 
    pocketmine\plugin\PluginBase;

    class 
    Pinger extends PluginBase{
      private 
    $cfg;

      public function 
    onEnable(){
        
    $this->cfg = new Config($this->getDataFolder() . "config.yml"Config::YAML, ["Message" => "§aYour ping is {ping}ms!"]);
      }

      public function 
    onCommand(CommandSender $senderCommand $cmdstring $label, array $args) : bool{
        if(
    $sender instanceof Player$sender->sendMessage(str_replace("{ping}"$sender->getPing(), $this->cfg->get("Message")));
        return 
    true;
      }
    }
    Just 19 lines of PHP code (+ 3 extra lines in plugin.yml). And you made almost 100 (excluding comments).
     
  2. friscowz

    friscowz Baby Zombie Ban Evader Banned

    Messages:
    128
    GitHub:
    friscowzmcpe
    i guess I'm not that type of person
     
    Levi likes this.
  3. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    In all fairness he could be laying the groundwork for a massive plugin that for now only has a single command... or maybe just experimenting with various coding techniques. People can have their own valid reasons for making things more complicated than strictly necessary, and even reinventing the wheel can have its uses. Not often though.
     
    EdwardHamHam, HittmanA, SOFe and 2 others like 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.