Help me!!! I'm write plugin PVP Party

Discussion in 'Plugin Help' started by DominixZ, Apr 12, 2017.

  1. DominixZ

    DominixZ Spider

    Messages:
    8
    I'm writing plugin "PVP Party" and i have a error player not teleport to me ;(((

    PHP:
    <?php

    namespace u7Party;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\utils\Config;

    class 
    Main extends PluginBase{
        
        public function 
    onEnable(){
            
    $this->getLogger()->info("vip loaded");
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
       if(
    strtolower($command->getName()) === "7party"){
          
    $sender->sendMessage("§7]-------[§l§57Party§r§7]-------[");
          
    $sender->sendMessage("§7> /7party [gracz] - zaprasza gracza do wspolnej gry");
          
    $sender->sendMessage("§7> /7party spoko - akceptuje party gracza ");
          
    $sender->sendMessage("§7> /7party spadaj - odmawia party ");
          
    $sender->sendMessage("§7> /7party plugin - informacje o pluginie ");
       }
          if(
    $sender instanceof Player) {
            if(isset(
    $args[0])) {
                
    $name $args[0];
                
    $name->sendMessage("§5§l7Party >§r§8 Zostales zaproszony do party wpisz /7party spoko");
                
    $name->sendMessage("§5§l7Party >§r§8 aby akceptowac lub /7party spadaj aby odmowic");
       }
                         if(
    $args[0] == "spoko") {
                            
    $this->getServer()->broadcastMessage("§5§lParty >§r§8 Gracz $sender stworzyl Party z graczem $name ");
                            
    $party "tp $name $sender";
                            
    $this->getServer()->dispatchCommand(new ConsoleCommandSender,$party);
                            
    $name->sendMessage("§5§l7Party >§r§8 Zaakeptowales party gracza");
                            
    $sender->sendMessage("§5§l7Party >§r§8 Twoja prosba zostala zaakceptowana");
                            
    $name->sendMessage("§2+100 monet");
                            
    $sender->sendMessage("§2+100 monet");
       }
                         if(
    $args[0] == "spadaj") {
                            
    $name->sendMessage("§5§l7Party >§r§8 Odmuwiles party");
                            
    $sender->sendMessage("§5§l7Party >§r§8 Twoja prosba zostala odrzucona");
       }
                         if(
    $args[0] == "plugin") {
                             
    $sender->sendMessage("§5§l7Party >§r§8 Plugin na party sluzacy do");
                             
    $sender->sendMessage("§5§l7Party >§r§8 wspolnej gry na minigrach");
                             
    $sender->sendMessage("§5§l7Party >§r§8 plugin jest bardzo prosty ;D");
                             
    $sender->sendMessage("§5§l7Party >§r§8 by DominixZ dla 7Hub");
           return 
    true;
                         }
          }
        }
    }
    I can"t write english very good and I will make a mistakes
     
  2. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    159
    GitHub:
    xdmingxd
    First , import stuff you need
    Second,
    Put you if($sender instanceof Player) at the top like this :
    PHP:
    public function onCommand(CommandSender $senderCommand $command$label, array $args){
    if(
    $sender instanceof Player) {
       if(
    strtolower($command->getName()) === "7party"){
          
    $sender->sendMessage("§7]-------[§l§57Party§r§7]-------[");
          
    $sender->sendMessage("§7> /7party [gracz] - zaprasza gracza do wspolnej gry");
          
    $sender->sendMessage("§7> /7party spoko - akceptuje party gracza ");
          
    $sender->sendMessage("§7> /7party spadaj - odmawia party ");
          
    $sender->sendMessage("§7> /7party plugin - informacje o pluginie ");
          if(isset(
    args[0])) {
              
    //next section
         
    }
    NEXT

    Here, $name returns strings not a player object!
    PHP:
    //if the player is online
    $player $this->getServer()->getPlayer($args[0]);
    :FACEPALM:
     
    Last edited: Apr 12, 2017
    DominixZ likes this.
  3. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    159
    GitHub:
    xdmingxd
    import TextFormat pls
    PHP:
    use pocketmine\utils\TextFormat// you can do : use pocketmine\utils\TextFormat as ANY KEY YOU WANT TO USE;
    So you can just do this :
    PHP:
    TF is the key of TextFormat
    $sender
    ->sendMessage(TF::RED .  "MESSAGE");
     
    DominixZ likes this.
  4. DominixZ

    DominixZ Spider

    Messages:
    8
    Thanks you XdimingXD im stupid XD It's easy
     
  5. Thunder33345

    Thunder33345 Moderator Staff Member Verified

    Messages:
    2,145
    GitHub:
    Thunder33345
    honestly the same in the end of the day, mojang wont be changing the symbol in the foreseeable future either ways
    you should also prevent using AS XYZ unless it's necessary due to name conflict
     
    DominixZ likes this.
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    796
    GitHub:
    Sandertv
    I don't see why you would have to prevent using it. It's often a lot more convenient to shorten the class name in your imports, as long as it doesn't lose too much readability, which I don't think is the case with TextFormat. The GREEN constant should be enough to recognize it in my opinion.
     
    Last edited: Apr 12, 2017
  7. DominixZ

    DominixZ Spider

    Messages:
    8
    I'm have a problem when write in game /7party I see a "Usage: /7party" ;( not ]-------[§l§57Party§r§7]-------[
    > /7party [gracz] - zaprasza gracza do wspolnej gry...
     
  8. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    159
    GitHub:
    xdmingxd
    Sorry , I forgot to return value...
    PHP:
    if(strtolower($command->getName()) === "7party"){
          
    $sender->sendMessage("§7]-------[§l§57Party§r§7]-------[");
          
    $sender->sendMessage("§7> /7party [gracz] - zaprasza gracza do wspolnej gry");
          
    $sender->sendMessage("§7> /7party spoko - akceptuje party gracza ");
          
    $sender->sendMessage("§7> /7party spadaj - odmawia party ");
          
    $sender->sendMessage("§7> /7party plugin - informacje o pluginie ");
    return 
    true;
          if(isset(
    args[0])) {
              
    //next section
         
    }
     
  9. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    796
    GitHub:
    Sandertv
    return; immediately stops the function. This means that the code after it will never be executed. Return true; should be at the end of your command.
     
  10. XdmingXD

    XdmingXD Baby Zombie

    Messages:
    159
    GitHub:
    xdmingxd
    Oops 0.o
    I got confused when I was replying lol
    Thx for your correction :)
     

Share This Page

  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.