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

Solved Auto-Filling player object stuff

Comments in 'Plugin Development' started by Tim // robske Büba, Jan 28, 2016.

?

Is this code messed up

  1. YES, WHAT HAVE YOU DONE

    25.0%
  2. Yes, It's messed up

    25.0%
  3. It's OK

    50.0%
  4. No

    0 vote(s)
    0.0%
  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Much Code:
    PHP:
    namespace robske_110\Plugin;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\event\block\SignChangeEvent;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\Player;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\level\Level;

    //TO-DO:
    //

    class Main extends PluginBase implements Listener{
        public 
    $REQUEST_ISSUER = array();
        public 
    $REQUEST_AIM = array();
        public 
    $REQUEST_ID 1;

        public function 
    onEnable(){
            
    $this->getServer()->getLogger()->info(TextFormat::GOLD "[TPA+HOME]" TextFormat::WHITE " I'm loading...");
            @
    mkdir($this->getDataFolder());
            
    $this->config = new Config($this->getDataFolder()."config.yml"Config::YAML, array());
            
    //$this->config->set('plugin-name',"TPA+HOME");
            
    $this->config->save();
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
            
    $this->getServer()->getLogger()->info(TextFormat::GOLD "[TPA+HOME]" TextFormat::WHITE " I'm loaded!");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args)
        {
            switch(
    $command->getName())
            {
                case 
    "tpa":
                if(
    $sender instanceof Player)
                {
                    if(isset(
    $args[0]))
                    {
                        if(
    strtolower($args[0]) != "accept" && strtolower($args[0]) != "ja")
                        {
                            
    $player $this->getServer()->getPlayer($args[0]);
                            if(
    $player instanceof Player && $player->isOnline() == true)
                            {
                                
    var_dump($this->REQUEST_ISSUER); //DEBUG
                                
    var_dump($this->REQUEST_AIM); //DEBUG
                                
    var_dump($this->REQUEST_ID); //DEBUG
                           
                                
    $this->REQUEST_ISSUER[$this->REQUEST_ID] = $sender->getName();
                                
    $this->REQUEST_AIM[$this->REQUEST_ID] = $args[0];
                                
    $this->REQUEST_ID++;
                           
                                
    var_dump($this->REQUEST_ISSUER); //DEBUG
                                
    var_dump($this->REQUEST_AIM); //DEBUG
                                
    var_dump($this->REQUEST_ID); //DEBUG
                                
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::GREEN " Der Spieler '".$player->getName()."' muss jetzt /tpa ja eingeben.");
                                
    $this->getServer()->getPlayer($args[0])->sendMessage("[rBServer]" TextFormat::GREEN " '".$sender->getName()."' will sich zu dir Teleportieren! Um das zu erlauben gebe /tpa ja ein.");
                                return 
    true;
                            }
                            else
                            {
                                
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::DARK_RED " Der Spieler '".TextFormat::WHITE.$args[0].TextFormat::DARK_RED."' ist nicht online!");
                                return 
    true;
                            }
                        }
                        else
                        {
                            
    $AIMINREQUESTARRAY NULL;
                            
    $SEARCH_ID 0;
                            
    $arrayEmpty false;
                            
    $ISSUERINISSUERARRAY NULL;
                            
    $ISSUERINREQUESTARRAYasPlayer NULL;
                            while(
    $AIMINREQUESTARRAY != $sender->getName() && $arrayEmpty != true)
                            {
                                
    $SEARCH_ID++;
                                if(isset(
    $this->REQUEST_AIM[$SEARCH_ID]))
                                {
                                    echo(
    "SearchID:");
                                    
    var_dump($SEARCH_ID);
                                    
    $AIMINREQUESTARRAY $this->REQUEST_AIM[$SEARCH_ID];
                                }  
                                else
                                {
    $arrayEmpty true;}                              
                            }
                            if(
    $arrayEmpty == true//If arrayEmpty is true there was NO request
                            
    {
                                
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::DARK_RED " Es wollte sich niemand zu dir teleportieren! (ErrorCode: ERR_120_arrayEmptyTrue_TPAtriggered)");
                                return 
    true;
                            }
                            if(
    $arrayEmpty == false//If arrayEmpty is false then get REQUEST_ISSUER[$SEARCHID] and get the Player by Name
                            
    {
                                
    $ISSUERINISSUERARRAY $this->REQUEST_ISSUER[$SEARCH_ID];
                                
    $ISSUERINREQUESTARRAYasPlayer $this->getServer()->getPlayer($ISSUERINISSUERARRAY);
                                if (
    $ISSUERINREQUESTARRAYasPlayer != NULL)
                                {
                                    
    $ISSUERINREQUESTARRAYasPlayer->teleport($sender); //WOW This is the teleport part. The rest is just the way of getting these two variables.
                                    
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::GREEN " Der Spieler '".$ISSUERINREQUESTARRAYasPlayer->getName()."' wurde zu dir teleportiert.");
                                    
    $ISSUERINREQUESTARRAYasPlayer->getPlayer()->sendMessage("[rBServer]" TextFormat::GREEN " Du wurdest zu '".$sender->getName()."' teleportiert.");
                                   
                                   
                                    
    $this->REQUEST_ISSUER[$SEARCH_ID] = $this->REQUEST_ISSUER[$SEARCH_ID]."EXPIRED_USED"//"Delete" the request!
                                    
    $this->REQUEST_AIM[$SEARCH_ID] = $this->REQUEST_AIM[$SEARCH_ID]."EXPIRED_USED"//"Delete" the request!
                                   
                                    
    var_dump($this->REQUEST_ISSUER); //DEBUG
                                    
    var_dump($this->REQUEST_AIM); //DEBUG
                                    
    var_dump($this->REQUEST_ID); //DEBUG
                                   
                                    
    return true;
                                }
                                else
                                {
                                    
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::DARK_RED " Der Spieler '".TextFormat::WHITE.$ISSUERINISSUERARRAY.TextFormat::DARK_RED."' ist nicht mehr online! (ErrorCode: ERR_121_PlayerFromIIAaPisNull_TPA)");
                                    return 
    true;
                                }
                            }
                            echo(
    "AIMINREQUESTARRAY: ");
                            
    var_dump($AIMINREQUESTARRAY);
                            echo(
    "ISSUERINREQUESTARRAY: ");
                            
    var_dump($ISSUERINISSUERARRAY);
                            echo(
    "SEARCH_ID: ");
                            
    var_dump($SEARCH_ID);
                            echo(
    "RequestIssuer: ");
                            
    var_dump($this->REQUEST_ISSUER);
                            echo(
    "arrayEmpty: ");
                            
    var_dump($arrayEmpty);
                        }
                    } 
                    else
                    {
                        
    $sender->getPlayer()->sendMessage("[rBServer]" TextFormat::DARK_RED " TPA funktioniert so: /TPA <Spielername>!");
                        return 
    false;
                    }  
                }
                else
                {
                    
    $this->getServer()->getLogger()->info(TextFormat::DARK_RED TextFormat::BOLD "[TPA] ERR_123_ConsoleIssued_TPA");
                    return 
    true;
                }
    There are many problems with this code... But the biggest Problem is:
    Some description of the situation:
    Online Players:
    HeyILikeTPA
    IWantToGetTeleported

    HeyILikeTPA issues /tpa IWantToGetTeleported
    IWantToGetTeleported issues /tpa accept
    WORKS

    HeyILikeTPA issues /tpa dashhsa
    DOES put out error: $sender->getPlayer()->sendMessage("[rBServer]" . TextFormat::DARK_RED . " Der Spieler '".TextFormat::WHITE.$args[0].TextFormat::DARK_RED."' ist nicht online!");
    WORKS, fine

    HeyILikeTPA issues /tpa IWantToGetTele
    THIS DOES PASS THE INSTANCEOF PLAYER AND THE ONLINE CHECK! AND THEN THE VAR "IWantToGetTele" is written in the array but if the player IWantToGetTeleported issues /tpa accept my plugin calls ERR_121 because IWantToGetTele is not online.

    Why does pocketmine auto-fill in the missing characters and at the /tpa accept not?
    How to prevent that auto-filling
  2. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Learn about temporal databases.
    Use objects to save this type of stuff is so... 5 years ago
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    That's not the problem...
  4. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    The Problem is, that pocketmine accepts IWantToGetTele as player... (But there is IWantToGetTeleported online)
  5. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    Try to check if the player is online.
  6. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Tha is already in the code:
    PHP:
    if($player instanceof Player && $player->isOnline() == true)
    And the problem is that this
    PHP:
    $player $this->getServer()->getPlayer($args[0]);
    returns the PlayerObject even if the player name isn't fully written!
    Last edited: Jan 28, 2016
  7. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    // Where $string is the argument
    Server::getPlayerExact($string);
    Or simply use the players name after you confirm they're a player instance.
    PHP:
    // Get a player's name and store it in a variable
    $name Player::getName();
  8. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Thanks!
  9. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    But one question:
    Why is
    PHP:
    $ISSUERINREQUESTARRAYasPlayer $this->getServer()->getPlayer($ISSUERINISSUERARRAY);
    NOT returning the player object then?
  10. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    Also, why not just foreach or for statements for cycling through your arrays?
  11. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    foreach(WHAT?) //I do not exactly know what this helps me?!
    for is almost the same as while and i never liked for
  12. CrazedMiner
    Offline

    CrazedMiner Notable Member Plugin Developer

    Joined:
    Jan 31, 2015
    Posts:
    348
    Plugins:
    2
    Minecraft User:
    CrazedMinerYT
    PHP:
    $array = ["apple""peach" => "seed""banana"]
    foreach(
    $array as as $key => $data) {
        echo 
    $key "=>" $data;
    }
    Would print
    Code:
    "0 => apple"
    "peach => seed"
    "2 => banana"
    
    http://php.net/manual/en/control-structures.foreach.php

Share This Page

Advertisement