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

Help with yml

Comments in 'Plugin Development' started by Rspuds, Aug 18, 2015.

  1. Rspuds
    Offline

    Rspuds New Member

    Joined:
    Aug 4, 2015
    Posts:
    53
    still gives the same error :(

    no $args[0] is the command. I use "/ae create" to prevent plugins having the same command
  2. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I just also got this error.

    Error: Cannot use object of type pocketmine\utils\Config as array
    File: /OITCPE/src/thebigsmileXD/OITCPE/Main
    Line: 206
    Type: E_ERROR

    THIS CRASH WAS CAUSED BY A PLUGIN
    BAD PLUGIN: OITCPE v1.0.0
    Code:
    [197] }
    [198] }
    [199]
    [200] public function joinLobby(Player $player, $lobby=false){
    [201] $this->getPlayerConfig();
    [202] if(!$this->playerExists($player)){
    [203] $this->players["players"][$player->getName()]["playing"]="true";
    [204] $this->setPlayerConfig();
    [205] }
    [206] if($this->players["players"][$name]["playing"]==="true"){
    [207] $player->sendMessage("Du bist bereits in einer Lobby");
    [208] return false;
    [209] }
    [210] else{
    [211] if ($lobby!==false){//prüfen
    [212] $lobby=strtolower($lobby);
    [213] $this->getLevelConfig();
    [214] if(in_array(strtolower($lobby), $this->level)){
    [215] if(isset($this->level[$lobby])){
    [216] return $player->teleport(new Position(
  3. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    :) i am done.. i found the mistake.
    I had the same on my plugin.

    PHP:
    <?php

    namespace thebigsmileXD\AreaEffects;

    use 
    pocketmine\Player;
    use 
    pocketmine\command\Command;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\utils\Config;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\level\Position;
    use 
    pocketmine\event\entity;
    use 
    pocketmine\entity\Effect;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\command\CommandSender;
    use 
    pocketmine\level\Location;
    use 
    pocketmine\level\Level;
    use 
    pocketmine\math\Vector3;

    class 
    Main extends PluginBase implements Listener{

        public 
    $areas;
        private 
    $pos1$pos2;

        public function 
    onLoad() {
            
    $this->getLogger()->info(TextFormat::GREEN."AreaEffects has been loaded!");
        }

        public function 
    onEnable() {
            @
    mkdir($this->getDataFolder () );
            
    $this->getServer ()->getPluginManager ()->registerEvents $this$this );
            
    $this->getLogger ()->info TextFormat::GREEN "AreaEffects has been loaded!" );
            
    $this->saveResource "areas.yml" );
            
    $this->areas = (new Config $this->getDataFolder () . "areas.yml"Config::YAML ))->getAll ();
            
    $this->pos=array();
        }
        public function 
    onDisable() {
            
    $this->areas = new Config $this->getDataFolder () . "areas.yml"$this->areas );
        }
        public function 
    onCommand(CommandSender $senderCommand $command$label, array $args) {
            
    $this->areas = (new Config $this->getDataFolder () . "areas.yml"Config::YAML ))->getAll ();//getAll() was missing
            
    if ($command == "ae") {
                if(
    count($args)===0)//no arguments->help
                    
    return false;
                switch (
    $args [0]) {
                    case 
    "pos1" :{
                        if (
    $sender instanceof Player) {
                            
    $this->pos [$sender->getName ()] ['pos1'] = new Position $sender->getFloorX (), $sender->getFloorY (), $sender->getFloorZ (), $sender->getLevel () );
                            
    $sender->sendMessage 'First position set' );
                            return 
    true;
                            break;
                        }
                    }
                    case 
    "pos2" :{
                        if (
    $sender instanceof Player) {
                            
    $this->pos [$sender->getName ()] ['pos2'] = new Position $sender->getFloorX (), $sender->getFloorY (), $sender->getFloorZ (), $sender->getLevel () );
                            
    $sender->sendMessage 'Second position set' );
                            return 
    true;
                            break;
                        }
                    }
                    case 
    "create" :{
                        if (
    $sender instanceof Player) {
                            if (isset ( 
    $args [1])) {
                                if (isset ( 
    $this->pos [$sender->getName ()] ['pos1'], $this->pos [$sender->getName ()] ['pos2'] )) {
                                    if (
    $this->pos [$sender->getName ()] ['pos1']->getLevel () === $this->pos [$sender->getName ()] ['pos2']->getLevel ()) {
                                        
    $this->areas [$args [1]] = array (
                                                
    'pos1' => array (
                                                        
    'x' => $this->pos [$sender->getName ()] ['pos1']->getX (),
                                                        
    'y' => $this->pos [$sender->getName ()] ['pos1']->getY (),
                                                        
    'z' => $this->pos [$sender->getName ()] ['pos1']->getZ ()
                                                ),
                                                
    'pos2' => array (
                                                        
    'x' => $this->pos [$sender->getName ()] ['pos2']->getX (),
                                                        
    'y' => $this->pos [$sender->getName ()] ['pos2']->getY (),
                                                        
    'z' => $this->pos [$sender->getName ()] ['pos1']->getZ ()
                                                )
                                        );
                                        
    $this->areas = new Config $this->getDataFolder () . "areas.yml"$this->areas );//save areas.yml
                                        
    $sender->sendMessage '[AreasEffect] ' $args [1] . ' created' );
                                        unset ( 
    $this->pos [$sender->getName ()] );
                                        return 
    true;
                                    }
                                }
                            }
                            else {
                                
    $sender instanceof Player?$sender->sendMessage("name missing"):$sender->getServer()->getLogger()->info("name missing");
                                return 
    false;
                            }
                        } else {
                            
    $sender->sendMessage 'Use this command in-game' );
                            return 
    true;
                        }
                    }
                    default:return 
    false;
                }
            }
        }
                                
                                
                                

        public function 
    onMove(PlayerMoveEvent $event){
        if (isset(
    $this->areas)){
            
    $player $event->getPlayer();
            if(empty(
    $this->areas)) {return;}
            foreach(
    $this->areas as $area){
                if(
    $this->isInArea($player$area)){$this->giveEffect($player ,$area);
                    }
                }
            }
        }

        public function 
    isInArea(Player $player$area){
        
            if(
    $player->getFloorX() >= $area['pos1']['x'] && $player->getFloorX() <= $area['pos2']['x'] && $player->getFloorY() >=$area['pos1']['y'] && $player->getFloorY() <= $area['pos2']['y'] && $player->getFloorZ() >= $area['pos1']['z'] && $player->getFloorZ() <= $area['pos2']['y'] && $area['level'] == $player->getLevel()) {return true;}
            else {return 
    false;
            }
        }
        
        public function 
    giveEffect($player$area){
            if(
    $player instanceof Player){
                
    $id $area['effect']['id'];
                
    $effect Effect::getEffect($id);
                
    $effect->setDuration($area['effect']['duration']);
                
    $effect->setAmplifier($area['effect']['amplifier']);
                
    $effect->setVisible($area['effect']['show']);
                
    $player->addEffect($effect);
            }
        }
    }
    the problem was
    PHP:
    $this->areas = (new Config $this->getDataFolder () . "areas.yml"Config::YAML ))->getAll ();//getAll() was missing
    You used the "save yml"-line, not getting the yml.

    At one line you called $this->area instead of $this->areas

    Also i added something to check if there are no arguments given (which previously returned an error)

    But theres still a problem:
    PHP:
    $this->areas = new Config $this->getDataFolder () . "areas.yml"$this->areas );//save areas.yml
    Does NOT save the .yml

    Anyone has an idea?
    Rspuds likes this.
  4. Primus
    Offline

    Primus Notable Member

    Joined:
    Apr 7, 2015
    Posts:
    1,470
    Minecraft User:
    PrimusLV
    /say hello world
    $cmd->getName(); // say
    $args[0] // hello
    $args[1] // world
    $args[2] // Error undefined index '2'
  5. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    I am on my bicycle and had no internet connection until now.
    I wanted to write that i figured out how to save them and access the content about 30 Minutes ago.
    I'll send you the fixed code later :)
    Last edited: Sep 13, 2015
  6. thebigsmileXD
    Offline

    thebigsmileXD Banned

    Joined:
    May 19, 2015
    Posts:
    845
    Plugins:
    1
    Minecraft User:
    XenialDan
    Is this still active?

Share This Page

Advertisement