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

Need help coding my plugin.

Comments in 'Plugin Development' started by FuryTacticz, Sep 3, 2015.

  1. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    Im making a OneVsOne plugin and I need help.
    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/setpos <arena> pos1\n/setpos <arena> pos2");
                                    return 
    true;
                                    break;
                                }
                              
    //////////////////////////////SET POS/////////////////////////////
                                 
    if($args[0] === "setpos"){
                                    if(isset(
    $args[1])){
                                     
                                        
    $ArenaName $args[1];
                                     
                                        
    $filedir = ($this->getDataFolder() . "arenas/"."Arena_".$args[1].".yml");
                                        
    $file $this->getConfig($this->getDataFolder() . "arenas/"."Arena_".$args[1].".yml");
                                     
                                                 if(
    file_exists($filedir)){
                                                     if(
    $args[2] === "pos1"){
                                                         
    $file->set("pos1""test");
                                                         
    $file->save();
                                                         
    $sender->sendMessage("Position-1 Has been set.");
                                                         return 
    true;
                                                         break;
                                                     }
                                                     if(
    $args[2] === "pos2"){
                                                         
    $file->set("pos2""Test");
                                                         
    $file->save();
                                                         
    $sender->sendMessage("Position-2 Has been set.");
                                                         return 
    true;
                                                         break;
                                                     }
                                                 }
                                                 elseif(!
    file_exists($filedir)){
                                                     
    $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.");
                 }
            }
         
        }
    }

    }
    The issue happens on /1v1 setpos

    This is the error I get: :/
    PHP:
    [17:52:01] [Server thread/CRITICAL]: Unhandled exception executing command '1v1 setpos lol pos1' in 1v1yaml_parse(): end of stream reached without finding document 0
    [17:52:01] [Server thread/WARNING]: RuntimeException"yaml_parse(): end of stream reached without finding document 0" (E_WARNINGin "/src/pocketmine/utils/Config" at line 143
    Help would be great! :)
  2. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
    Okay thanks for the reply but would that not create another config or remake the current one as it says "new" just asking?
  3. FuryTacticz
    Offline

    FuryTacticz New Member

    Joined:
    Aug 31, 2015
    Posts:
    23
    Minecraft User:
    FuryTacticz
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    I got the same confusion too when I saw the Java line `new File()` :p I really miss those old days.
    EvolSoft, FuryTacticz and jojoe77777 like this.

Share This Page

Advertisement