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

Problem with arrays

Comments in 'Plugin Development' started by LoveToBeDev, Aug 24, 2015.

  1. LoveToBeDev
    Offline

    LoveToBeDev Active Member

    Joined:
    Aug 19, 2015
    Posts:
    55
    Minecraft User:
    LoveToBeDev
    Hello guys, i have tried to use Vector3 and things like that with arrays, but i don't know whats the problem, thanks for the help.

    Here is the error in the console:



    Here is the full code:

    PHP:
    <?php

    namespace paintball\lovetobedev;

    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\Player;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat as Color;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\item\Item;

    class 
    Main extends PluginBase{
        public function 
    onEnable() {
            
    $this->getLogger()->info(Color::GREEN."Plugin Loaded!");
            
    $this->saveDefaultConfig();
        }
      
        public function 
    onDisable() {
            
    $this->getLogger()->info(Color::RED."Plugin Disabled");
        }
      
        public function 
    onCommand(\pocketmine\command\CommandSender $sender, \pocketmine\command\Command $command$label, array $args) {
            if(
    $sender instanceof Player){
                switch (
    strtolower($command->getName())){
                    case 
    'helppbs':
                        
    $sender->sendMessage(Color::GREEN."[Paintball]");
                        
    $sender->sendMessage(Color::LIGHT_PURPLE."/setpbspawn1");
                        
    $sender->sendMessage(Color::LIGHT_PURPLE."/setpbspawn2");
                        
    $sender->sendMessage(Color::LIGHT_PURPLE."/joinpb");
                        break;
                    case 
    'setpblobby':
                        
    $lobby = [
                            
    $sender->getX(),
                            
    $sender->getY(),
                            
    $sender->getZ()
                        ];
                        
    $this->getConfig()->set("pblobby"$lobby)[0];
                        
    $this->getConfig()->get("pblobby");
                        
    $this->getConfig()->save();
                        
    $sender->sendMessage(Color::GREEN."[Paintball] Lobby Saved Successfully!");
                        
    $sender->sendMessage(Color::RED."[Paintball] Remember that the lobby is only for spectators");
                        break;
                    case 
    'joinpblobby':
                        
    $lobbycor $this->getConfig()->get("pblobby");
                        
    $lobbyj = new Vector3($lobbycor[0], $lobbycor[1], $lobbycor[2]);
                        
    $sender->teleport($lobbyj);
                        break;
                    case 
    'setpbspawn1':
                        
    $sspawn = [
                            
    $sender->getX(),
                            
    $sender->getZ(),
                            
    $sender->getY()
                        ];
                        
    $this->getConfig()->set("pspawn"$sspawn)[0];
                        
    $this->getConfig()->get("pspawn");
                        
    $this->getConfig()->save();
                        
    $sender->sendMessage(Color::GREEN."[Paintball] Team 1 spawn set!");
                        break;
                    case 
    'setpbspawn2':
                        
    $sspawn2 = [
                            
    $sender->getX(),
                            
    $sender->getY(),
                            
    $sender->getZ()
                        ];
                        
    $this->getConfig()->set("pswpawn2"$sspawn2)[0];
                        
    $this->getConfig()->get("pspawn2"$sspawn2);
                        
    $this->getConfig()->save();
                        
    $sender->sendMessage(Color::GREEN."[Paintball] Team 2 spawn set!");
                        break;
                    case 
    'joinpb':
                        
    $random mt_rand(12);
                        
    $name $sender->getPlayer()->getName();
                        
    $coords $this->getConfig()->get("pspawn");
                        
    $coords2 $this->getConfig()->get("pspawn2");
                        
    $pos = new Vector3($coords[0], $coords[1], $coords[2]);
                        
    $pos2 = new Vector3($coords2[0], $coords2[1], $coords2[2]);
                        
    $items = [
                         
    Item::get(332016)
                        ];
                        if(
    $random == 1){
                            
    $sender->teleport($pos);
                            
    Server::getInstance()->broadcastMessage(Color::BLUE."$name Joined to team 1!");
                            
    $sender->getInventory()->addItem($items[0]);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                        } else {
                            
    $sender->teleport($pos2);
                            
    Server::getInstance()->broadcastMessage(Color::RED."$name Joined to team 2!");
                            
    $sender->getInventory()->addItem($items[0]);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                            
    $sender->getInventory()->addItem($items);
                        }
                        break;
                }
            } else {
                
    $sender->sendMessage(Color::RED."please run command in game");
            }
        }
      
            public function 
    saveConfig(){
            if(
    $this->getConfig()->save() === false){
                
    $this->getLogger()->critical("Could not save config to " $this->configFile);
            }
        }
          
            public function 
    onPlayerInteract(PlayerInteractEvent $event){
                
    $player $event->getPlayer(); // Get player who touches the block
                
    $block $event->getItem();
                
    $playername$event->getPlayer()->getName();// Get block that have been touches (including air)
                // $action = $event->getAction();
                
    if($block->getId() === 332){ // If touched block id is equal to stone
                // kill player
                
    $player->kill();
                
    Server::getInstance()->broadcastMessage(Color::RED."$playername Is Out!");// or $player->setHealth(0);
    }
    }
          
      
    }
    Here is the config YAML file:

    PHP:
    ## YAML Template.
    ---
    pblobby0
    pspawn
    0
    pspawn2
    0
    THANKS FOR THE HELP!
  2. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    The most help I can give you is to tell you to learn some more PHP. ;)
    CrazedMiner and HotFireyDeath like this.
  3. LoveToBeDev
    Offline

    LoveToBeDev Active Member

    Joined:
    Aug 19, 2015
    Posts:
    55
    Minecraft User:
    LoveToBeDev
    Las help pls men, i promise ill study php
  4. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Expected Item[]
    That means, you should pass an array of Item objects.
  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    WAT?
  6. LoveToBeDev
    Offline

    LoveToBeDev Active Member

    Joined:
    Aug 19, 2015
    Posts:
    55
    Minecraft User:
    LoveToBeDev
    You sure? Because the teleport sends me to the sky limit haha :p look at the log
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    1. Unnecessary parentheses in line 1
    2. Inventory->addItem() accepts varargs Item objects as the argument. You can pass items like this:
      PHP:
      $inventory->addItem($item0$item1);
      or if you have an array of Item objects $items, pass them like this:
      PHP:
      $inventory->addItem(...$items);
      [/LIST]

      @
      Kvetinac97 please be aware that every post you post here will be viewed by future members on the forum, and posting wrong answers will mislead people and result in more problemsThereforeplease be responsible when you post and please do not post if you don't understand what you are doing.
  8. Kvetinac97
    Offline

    Kvetinac97 Active Member Plugin Developer

    Joined:
    Nov 17, 2014
    Posts:
    276
    Plugins:
    1
    Minecraft User:
    Kvetinac97
    Sorry.

Share This Page

Advertisement