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

TPA plugin dev

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

  1. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    The Problem is if i issue /tpa ja or /tpa accept it still does not call the "else code" it just goes on like normal (I'm trying to make an subcmd) screenshot.png
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Can you show what is exactly happening? There are a lot of "else code".
  3. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    screenshot.png
    So I'm trying to make an Subcommand /tpa accept or /tpa ja!
    And the code down there never executes!
  4. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Your logic is wrong
    PHP:
     if(strtolower($args[0]) != "accept" || strtolower($args[0]) != "ja"
    This will be always true, as it will always satisfy any one or both of it
    Example:
    if $args[0] is "accept", the second part will be true
    if $args[0] is "ja", the first part will be true
    if $args[0] is something else, both parts will be true
    Correct code would be
    PHP:
     if(strtolower($args[0]) != "accept" && strtolower($args[0]) != "ja"
    PEMapModder likes this.
  5. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Wouldn't that result into ONLY going to that else code block if args[0] is "ja" and "accept", wich will never happen...
    Again: I try to make an subcmd /tpa accept (or /tpa ja)
    (ja is the german word for yes)
  6. wolfdale
    Offline

    wolfdale Active Member Plugin Developer

    Joined:
    Dec 3, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    ace
    Isn't that what you are trying to achieve?
    EDIT: my code if checks if args[0] is NOT "accept" AND args[0] is NOT "ja", so your else code will run when args[0] is "accept" OR args[0] is "ja"
  7. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Ok, fixed now thanks!
    Stupid me...
    Last edited: Jan 12, 2016
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Maybe we should have some redstone fun.
    Screenshot_2016-01-13-00-29-54.png
    They are OR, NOR, AND, NAND gates respectively.
    In your case, you want the inverse of A or B. That means you want the inverse of OR. That means you want NOR, which is !($a or $b). If you want to break down the parentheses, you want to add/remove the redstone torches (NOT) at the obsidian blocks, which is the AND gate. Hence !$a and !$b.
    Vaivez66 likes this.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    What if Server::getPlayer($name) returns null?
  10. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    Yay!
    Ok, let's get back to coding the /tpa <PlayerName> command is finished
    But now I'm stuck at the /tpa accept thingy:
    On tpa accept i iterate through the array REQUEST_AIM[Index] until the sender of /tpa accept is found or the REQUEST_AIM[Index] returns NULL.
    So I have the index now and look in REQUEST_ISSUER[Index] and then find the issuer, wich than gets teleported to the issuer of /tpa accept.
    Theory finished.
    Let's get to programming will post code soon!
  11. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    if($server->getPlayer($args[1]) instanceof Player)
  12. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    PHP:
    class Main extends PluginBase implements Listener{
        public 
    $REQUEST_ISSUER = array();
        public 
    $REQUEST_AIM = array();
        public 
    $REQUEST_ID 1;

        public function 
    onEnable(){
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
        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] Diese Funktion ist noch in der ALPHA!");
                                
    $this->getServer()->getPlayer($args[0])->sendMessage("[rBServer] '".$sender->getName()."' will sich zu dir Teleportieren! Um das zu erlauben gebe /tpa accept (oder /tpa ja) ein!");
                                return 
    true;
                            }
                            else
                            {
                                
    $sender->getPlayer()->sendMessage("[rBServer] Der Spieler '".$args[0]."' ist nicht online!");
                                return 
    true;
                            }
                        }
                        else
                        {
                            
    $sender->getPlayer()->sendMessage("[rBServer] Diese Funktion ist noch in der ALPHA!");
                           
                            
    $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] Es wollte sich niemand zu dir teleportieren.");
                                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);
                                    return 
    true;
                                }
                                else
                                {
                                    
    $sender->getPlayer()->sendMessage("[rBServer] Der Spieler '".$ISSUERINISSUERARRAY."' ist nicht mehr online! (Wenn er online ist hier der ErrorCode: ERR_xxx_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] TPA funktioniert so: /TPA <Spielername>");
                        return 
    false;
                    }  
                }
                else
                {
                    
    $this->getServer()->broadcastMessage("ERR_xxx_CONSOLEissued_TPA"); //Nur für die CONSOLE sichtbar machen...
                    
    return true;
                }
            }  
        }
    }
    YES It's working
    Still need help with this:
    I need to delete an string out of the array how to do that (I think something with unset() )
    Cancel an request after time (Here i will need deleting things out of arrays too) [DelayedTask?!]
    And prevent to create an request to an player twice
  13. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    PHP:
    unset($this->REQUEST_ISSUER[$player->getName()];
    And you could just use time() to expire the tpa.
    PEMapModder likes this.
  14. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    unset($this->REQUEST_ISSUER[$player->getName()]; would break my array "Databases" The loop wouldn't find anything after that :(
    time() good idea, but can i just try to use an delayedTask?
  15. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ikr :D i just wanted to point out that you should edit.
    Hotshot_9930 likes this.
  16. Tim // robske Büba
    Offline

    Tim // robske Büba Notable Member

    Joined:
    Feb 26, 2014
    Posts:
    606
    Minecraft User:
    robske_110
    No one has an response to that?
  17. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    There is no need for a task. Using time() is quicker.

Share This Page

Advertisement