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

I need help with my plugin.

Comments in 'Plugin Development' started by iiDeathStrokeii, Aug 31, 2015.

  1. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    Hi guys making a One V One plugin.
    PHP:
    <?php

    namespace OneVsOne;

    use 
    pocketmine\Server;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\command\CommandExecutor;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\command\PluginCommand;
    use 
    pocketmine\Player;
    use 
    pocketmine\item\Item;
    use 
    pocketmine\event\player\PlayerChatEvent;
    use 
    pocketmine\event\player\PlayerInteractEvent;
    use 
    pocketmine\event\player\PlayerDeathEvent;
    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\event\entity\EntityLevelChangeEvent;
    use 
    pocketmine\event\block\BlockPlaceEvent;
    use 
    pocketmine\event\block\BlockBreakEvent;
    use 
    pocketmine\event\EventExecutor;
    use 
    pocketmine\event\EventPriority;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\plugin\Plugin;
    use 
    pocketmine\tile\Sign;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\Player\getName;
    use 
    pocketmine\command\ConsoleCommandSender;
    use 
    pocketmine\event\player\PlayerQuitEvent;
    use 
    pocketmine\event\player\PlayerJoinEvent;
    use 
    pocketmine\block\Block;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\pocketmine\Level;
    use 
    pocketmine\entity\Effect;



    class 
    OneVsOne extends PluginBase implements Listener{
       
       
       
       
                    
      
        public function 
    onLoad(){
            
    $this->getLogger()->info(TextFormat::YELLOW."Loaded.");
        }

        public function 
    onEnable(){
        
    $this->getServer()->getPluginManager()->registerEvents($this$this);
       
       
        
    $this->CreateSign false;
       
       
        @
    mkdir($this->getDataFolder() . "arenas/");
       
       
        
    $this->RootDirectory = ($this->getDataFolder() . "arenas/");
        }
       
       
       
       
       
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args){
                switch(
    $command->getName()){
                    case 
    "1v1":
                                 
    /////////////////////////////// CREATE ARENA ///////////////////////////////
                                
                                 
    if($args[0] === "create"){
                                     if(
    $args[1] === "arena"){
                                        
                                         if(isset(
    $args[2])){
                                            
                                             
    $ArenaName $args[2];
                                            
                                             
    $file = ($this->getDataFolder() . "arenas/"."Arena_".$args[2].".yml");
                                            
                                                 if(!
    file_exists($file)){
                                                     
    $this->ArenaFile = new Config($this->getDataFolder()."arenas/"."Arena_".$args[2].".yml"Config::YAML);
                                                     
    $sender->sendMessage("Arena ".$args[2]." has been created.");
                                                     return 
    true;
                                                     break;
                                                 }
                                                 elseif(
    file_exists($file)){
                                                        
    $sender->sendMessage("Arena ".$args[2]." already exists.");
                                                        return 
    true;
                                                        break;
                                                 }
                                            
                                         }
                                        
                                     }
                                    
                                     
    /////////////////////////////// CREATE SIGN ///////////////////////////////
                                    
                                     
    if($args[1] === "sign"){
                                        
    $file = ($this->getDataFolder() . "arenas/"."Arena_".$args[2].".yml");
                                            if(
    $this->CreateSign === false){
                                                if(
    file_exists($file)){
                                                    
    $this->CreateSign true;
                                                    
    $this->ArenaNameForSign $args[2];
                                                    
    $sender->sendMessage("Arena ".$args[2]." exists.");
                                                    
    $sender->sendMessage("Please tap desired sign.");
                                                    return 
    true;
                                                    break;
                                            }
                                        }
                                    elseif(!
    file_exists($file)){
                                    
    $sender->sendMessage("Error.");
                                    
    $sender->sendMessage("Arena ".$args[2]." does not exist.");
                                    return 
    false;
                                    break;
                                    }
                               
                            }
                                 }
                                
                                 
    /////////////////////////////// DELETE ARENA ///////////////////////////////
                                
                                 
    if($args[0] === "delete"){
                                     if(
    $args[1] === "arena"){
                                         if(isset(
    $args[2])){
                                            
                                             
    $ArenaName $args[2];
                                            
                                             
    $file = ($this->getDataFolder() . "arenas/"."Arena_".$args[2].".yml");
                                            
                                                if(
    file_exists($file)){
                                                     
    unlink($file);
                                                     
    $sender->sendMessage("Arena ".$args[2]." has been deleted.");
                                                     return 
    true;
                                                     break;
                                                 }
                                                
                                                elseif(!
    file_exists($file)){
                                                    
    $sender->sendMessage("Arena ".$args[2]." does not exist.");
                                                     return 
    true;
                                                     break;
                                                }
                                                
                                               
                                         }
                                     }
                                 }
                                
                                 if(
    $args[0] === "help"){
                                    
    $sender->sendMessage("Usage:\n/1v1 help\n/1v1 delete <arena>\n/1v1 create arena <arena>\n/1v1 create sign <arena>\n/1v1 setpos <arena> pos1\n/1v1 setpos <arena> pos2");
                                    return 
    true;
                                    break;
                                }
                               
                                 if(
    $args[0] === "setpos"){
                                    if(isset(
    $args[1])){
                                       
                                        
    $ArenaName $args[1];
                                       
                                        
    $file = ($this->getDataFolder() . "arenas/"."Arena_".$args[1].".yml");
                                       
                                                 if(
    file_exists($file)){
                                                     if(
    $args[2] === "pos1"){
                                                         
    $file->set("pos1"$sender->getPosition());
                                                         
    $file->save();
                                                         
    $sender->sendMessage("Position-1 Has been set.");
                                                         return 
    true;
                                                         break;
                                                     }
                                                     if(
    $args[2] === "pos2"){
                                                         
    $file->set("pos2"$sender->getPosition());
                                                         
    $file->save();
                                                         
    $sender->sendMessage("Position-1 Has been set.");
                                                         return 
    true;
                                                         break;
                                                     }
                                                 }
                                                 elseif(!
    file_exists($file)){
                                                     
    $sender->sendMessage("Arena ".$args[1]." does not exist.");
                                                     return 
    true;
                                                     break;
                                                 }
                                    }
                                }
                               
                               
                                
       
                                
                }
        }
       
       
       
            
    /////////////////////////////// CREATE SIGN **TAP/TOUCH** ///////////////////////////////
       
        
    public function createSign(PlayerInteractEvent $event) {
        
    $sign $event->getPlayer()->getLevel()->getTile($event->getBlock());
        if(
    $this->CreateSign === true){
            if(
    $event->getBlock()->getId() == 323 || $event->getBlock()->getId() == 63 || $event->getBlock()->getId() == 68) {
                 if(
    $sign instanceof Sign) {
                    
    $signtext $sign->getText();
                    
    $sign->setText("[1v1]"$this->ArenaNameForSign$signtext[2], $signtext[3]);
                    
    $this->CreateSign false;
                    
    $event->getPlayer()->sendMessage("Sign for Arena: ".$this->ArenaName." successfuly created.");
                 }
            }
           
        }
    }

    }
    It crashes my server when I do /1v1 setpos <arena> pos1 or pos2.
    The error is on the set() function on line 166 which is:
    PHP:
      $file->set("pos1"$sender->getPosition());
    Help would be much appreciated! :)
  2. iiDeathStrokeii
    Offline

    iiDeathStrokeii Active Member

    Joined:
    Mar 30, 2015
    Posts:
    111
    Minecraft User:
    iiDeathstrokeii
    That would be wrong as it must be $sender->getX(), $sender->getY(),...etc
    not sure if this would be the reason it crashes though.
  3. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    I suggest in the pos1 file you add 3 things. "X", "y" and "z".
    After that you can do this
    PHP:
    $this->file = new Config($this->getDataFolder() . "pos1.yml"Config::YAML, array(
                
    "x" => 0,
                
    "y" => 0,
                
    "z" =>0   
                
    )); // creates the pos1.yml
           
                
    if($args[2] == "pos1") {
                    
    $this->file->set("x"floor($sender->getX()));
                    
    $this->file->set("y"floor($sender->getY()));
                    
    $this->file->set("z"floor($sender->getZ()));
                    
    $this->file->save();
                    
    $sender->sendMessage("Position-1 Has been set.");
                    return 
    true;
                    }
    Last edited: Sep 1, 2015
    CrazedMiner and Taha_The_Hacker like this.
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    $file is a string. You want to use it upon a Config object. Suppose you should use $this->ArenaFile instead?
    BTW, conventions indicate that class properties should start with lowercase.
  5. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Code is wrong. It should/could be:
    PHP:
    $file->set("pos1"$sender
    ->getX()
    ->
    getY()
    ->
    getZ());
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is different? It's still wrong, calling getY() upon non-object int from grtX().
    Taha_The_Hacker likes this.
  7. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Where did you mentioned a reason for the crash?
  8. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    It is obvious. Calling member function set on non-object $file.
  9. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    Ouh you're true, my phone did not show the full code.

Share This Page

Advertisement