Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Solved Which one is better?

Comments in 'Plugin Development' started by Gamecrafter, Nov 21, 2015.

  1. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    I've been working on my QueryFacade a lot recently, with help from @Lambo. I would like to ask you guys which of the following would be better:
    The one I came up with:
    PHP:
    <?php

    namespace queryfacade\network;

    use 
    pocketmine\IPlayer;

    class 
    DummyPlayer implements IPlayer{
        
    /** @var string */
        
    protected $name;
        
    /**
         * @param string name
         */
        
    public function __construct($name){
            
    $this->name = (string) $name;
        }
        
    /**
         * @param bool $value
         */
        
    public function setOp($value){
        }
        
    /**
         * @return bool
         */
        
    public function isBanned(){
            return 
    false;
        }
        
    /**
         * @return bool
         */
        
    public function isWhitelisted(){
            return 
    false;
        }
        public function 
    getLastPlayed(){
        }
        public function 
    getFirstPlayed(){
        }
        
    /**
         * @return string
         */
        
    public function getName(){
            return 
    $this->name;
        }
        public function 
    hasPlayedBefore(){
        }
        
    /**
         * @param bool $banned
         */
        
    public function setBanned($banned){
        }
        
    /**
         * @return bool
         */
        
    public function isOp(){
            return 
    false;
        }
        
    /**
         * @param bool $value
         */
        
    public function setWhitelisted($value){
        }
        
    /**
         * @return bool
         */
        
    public function isOnline(){
            return 
    true;
        }
        public function 
    getPlayer(){
        }
    }
    Or the one @Lambo suggested I use:
    PHP:
    <?php

    namespace queryfacade\network;

    use 
    pocketmine\Player;

    class 
    DummyPlayer extends Player{
        
    /** @var string */
        
    protected $name;
        
    /**
         * @param string name
         */
        
    public function __construct($name){
            
    $this->name = (string) $name;
        }
        
    /**
         * @return string
         */
        
    public function getName(){
            return 
    $this->name;
        }
    }
    I've tested them, and I already know they both work. Any suggestions would be awesome! But please, only post if you know what you're talking about! Thanks for reading. :)
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is QueryFacade for? If it is like Specter, you should extend Player.
  3. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    It is not like Specter. This plugin is for modifying the query server data that is sent.
    HotFireyDeath likes this.
  4. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    Personally, I think yours is bad practice. It says here that $players should be an instanceof Player[], not IPlayer[]. Of course, they both work because it doesn't actually check anywhere if it is an instanceof Player and only calls the getName method but it will confuse your IDE and might create problems in the future.
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Yeah... Thats why I was asking. Would the one I'm using be considered a hack? Is there an upside to using the one I am currently using?
    Last edited: Nov 21, 2015
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It appears that the API design simply wants to have real connected players in the array.
  7. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Nah, we'll modify it... :p And I did some more testing today and I noticed that @Lambo's way actually causes some crashes within one minute of server start. The one I was using didn't crash at all.
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then it is wrong. But not crashing doesn't mean it is right.
    iJoshuaHD and Gamecrafter like this.
  9. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Well, I added the following to the constructor:
    PHP:
    $this->server Server::getInstance();
    That fixed one of the errors I was getting, but now I have to do something about the SourceInterface thing, so I'm assuming I need a DummyInterface now... :( More work. The one I came up with worked perfectly and didn't need that much, but this one will need more. :p
  10. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Or you simply don't have to call parent::__construct(), since you are only hacking the type checks, not trying to use the Player class.

    (And mind you, your question in the main post is like asking whether a refrigerator or an air conditioner would be better without stating what you want to be kept cold)
    Andrey Nazarchuk and Gamecrafter like this.
  11. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Yeah, I think I figured out how to handle this. I'll fix this in the next update, I won't have too much time this month, I want to release it first. :)

Share This Page

Advertisement