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

Give kit HG :(

Comments in 'Plugin Development' started by MrReskill, Mar 12, 2016.

  1. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    Hello,
    I tried to give the items the player joined the game, the game is good, but do not give launches kits:
    Thanks.
    CODE:
    foreach (HGGame::getApi()->players[$game] as $p) {
    if ($p instanceof Player) {
    $p->sendMessage(FMT::colorMessage(str_replace(["%player%", "%game%"], [$sender->getName(), $game], $this->main->getMessage("joined_game"))));

    $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
    $p->getInventory()->addItem(Item::get(Item::ARROW, 0, 64));
    $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
    $p->getInventory()->addItem(Item::get(Item::BREAD, 0, 8));
    $p->getInventory()->addItem(Item::get(ITEM::BOW));
    $p->getInventory()->addItem(Item::get(Item::GOLDEN_APPLE, 0, 4));


    // Pur the armor on the player
    $p->getInventory()->setHelmet(Item::get(310, 0, 1));
    $p->getInventory()->setChestplate(Item::get(311, 0, 1));
    $p->getInventory()->setLeggings(Item::get(312, 0, 1));
    $p->getInventory()->setBoots(Item::get(313, 0, 1));
    $p->getInventory()->sendArmorContents($player);



    }
    break;
  2. Lambo
    Offline

    Lambo Notable Member Plugin Developer

    Joined:
    Sep 14, 2013
    Posts:
    431
    Plugins:
    4
    Minecraft User:
    Lambo
    PHP:
    $p->getInventory()->sendContents($p);
    $p->getInventory()->sendArmorContents($p);
    after all of the item adding
    PocketKiller and applqpak like this.
  3. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    Oh I forgot I con
  4. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    Good ?
    THIS:
    Code:
     foreach (HGGame::getApi()->players[$game] as $p) {
                            if ($p instanceof Player) {
                                $p->sendMessage(FMT::colorMessage(str_replace(["%player%", "%game%"], [$sender->getName(), $game], $this->main->getMessage("joined_game"))));
    
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::ARROW, 0, 64));
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::BREAD, 0, 8));
            $p->getInventory()->addItem(Item::get(ITEM::BOW));
            $p->getInventory()->addItem(Item::get(Item::GOLDEN_APPLE, 0, 4));
    
           
            // Pur the armor on the player
            $p->getInventory()->setHelmet(Item::get(310, 0, 1));
            $p->getInventory()->setChestplate(Item::get(311, 0, 1));
            $p->getInventory()->setLeggings(Item::get(312, 0, 1));
            $p->getInventory()->setBoots(Item::get(313, 0, 1));
           
    //Send armor and item
             $p->getInventory()->sendContents($p);
         $p->getInventory()->sendArmorContents($p);
           
                
    
                            }
                            break;
  5. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    @Lambo
    It does not work :(
    Code:
     foreach (HGGame::getApi()->players[$game] as $p) {
                            if ($p instanceof Player) {
                                $p->sendMessage(FMT::colorMessage(str_replace(["%player%", "%game%"], [$sender->getName(), $game], $this->main->getMessage("joined_game"))));
    
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::ARROW, 0, 64));
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::BREAD, 0, 8));
            $p->getInventory()->addItem(Item::get(ITEM::BOW));
            $p->getInventory()->addItem(Item::get(Item::GOLDEN_APPLE, 0, 4));
    
          
            // Pur the armor on the player
            $p->getInventory()->setHelmet(Item::get(310, 0, 1));
            $p->getInventory()->setChestplate(Item::get(311, 0, 1));
            $p->getInventory()->setLeggings(Item::get(312, 0, 1));
            $p->getInventory()->setBoots(Item::get(313, 0, 1));
          
    //Send armor and item
             $p->getInventory()->sendContents($p);
         $p->getInventory()->sendArmorContents($p);
          
               
    
                            }
                            break;
  6. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i think you remove items after that, because this code should work if you are using official pocketmine
  7. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
    No clearAll();
    I have this error:

    [04:10:13] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\player\PlayerQuitEvent' to 'HungerGames vbuild#07': Access to undeclared static property: xbeastmode\hg\HGManagement::$BBlocks on xbeastmode\hg\Events
    [04:10:13] [Server thread/CRITICAL]: Error: "Access to undeclared static property: xbeastmode\hg\HGManagement::$BBlocks" (EXCEPTION) in "/phar_1v1-MR_7vnyEi2YdFRGrII.phar/src/xbeastmode/hg/api/EndGame" at line 76
  8. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT

    The code:
    Code:
    <?php
    namespace xbeastmode\hg\commands;
    use pocketmine\command\Command;
    use pocketmine\command\CommandSender;
    use pocketmine\command\PluginIdentifiableCommand;
    use pocketmine\Player;
    use xbeastmode\hg\event\player\PlayerJoinGameEvent;
    use xbeastmode\hg\event\player\PlayerQuitGameEvent;
    use xbeastmode\hg\HGManagement;
    use xbeastmode\hg\Loader;
    use xbeastmode\hg\api\HGGame;
    use xbeastmode\hg\utils\FMT;
    class hgCmd extends Command implements PluginIdentifiableCommand{
        /** @var Loader */
        private $main;
        /**
         * @param Loader $main
         */
        public function __construct(Loader $main){
            parent::__construct("hg", "Hunger Games command", FMT::colorMessage("&e/hg help"), ["sg", "hgg", "sgg", "sggame", "hggame"]);
            $this->main = $main;
        }
        /**
         * @param CommandSender $sender
         * @param string $commandLabel
         * @param string[] $args
         *
         * @return mixed
         */
        public function execute(CommandSender $sender, $commandLabel, array $args)
        {
            if($sender instanceof Player) {
                if (empty($args[0])) {
                    $sender->sendMessage(FMT::colorMessage($this->getUsage()));
                    return;
                }
                switch (strtolower($args[0])) {
                    case 'help':
                        if ($sender->isOp()) {
                            if(isset($args[1]) == 2){
                                $sender->sendMessage(FMT::colorMessage("&f-=[&eHunger&6Games&f &bHELP (2/2)&f]=-"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg join <game> &fjoin game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg quit &fquit game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg addslot <game> &f add slot to game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg create <name> &fcreate a game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg min <game> <number> &fset minimum players for game"));
                            }elseif(empty($args[1])) {
                                $sender->sendMessage(FMT::colorMessage("&f-=[&eHunger&6Games&f &bHELP (1/2)&f]=-"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg max <game> <number> &fset maximum players for game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg time <game> <game|wait> <number> &fchange game/wait time"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg level <game> [level] &fchange level for a game"));
                                $sender->sendMessage(FMT::colorMessage("&e/hg pos <game> <lobby|death-match> &fadd slot to game"));
                            }else{
                                $sender->sendMessage(FMT::colorMessage("&cError[H-1]: &eno command like that exists. &aTry: /hg help"));
                            }
                        } else {
                            $sender->sendMessage(FMT::colorMessage("&e/hg join <game> &fjoin game"));
                            $sender->sendMessage(FMT::colorMessage("&e/hg quit &fquit game"));
                        }
                        break;
                    case 'j':
                    case 'join':
                        if (empty($args[1])) {
                            $sender->sendMessage(FMT::colorMessage("&e/hg join <game> &fjoin game"));
                            return;
                        }
                        $game = $args[1];
                        foreach(HGGame::getApi()->players as $g){
                            if(isset($g[spl_object_hash($sender)])){
                                $sender->sendMessage(FMT::colorMessage("&cError[J-1]: &ealready joined game."));
                                return;
                            }
                            break;
                        }
                        $pjge = new PlayerJoinGameEvent($this->main, $sender, $game);
                        $this->main->getServer()->getPluginManager()->callEvent($pjge);
                        if($pjge->isCancelled()) return;
                        if(isset(HGGame::getApi()->players[$game][spl_object_hash($sender)])){
                            $sender->sendMessage(FMT::colorMessage("&cError[J-1]: &ealready joined game."));
                            return;
                        }
                        if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                            $sender->sendMessage(FMT::colorMessage("&cError[J-2]: &egame does not exist."));
                            return;
                        }
                        if(HGGame::getApi()->tpToOpenSlot($sender, $game) === false){
                            return;
                        }
                        HGManagement::$data[$sender->getName()] = $game;
                        HGManagement::$players[$game][$sender->getName()] = $sender;
                        foreach (HGGame::getApi()->players[$game] as $p) {
                            if ($p instanceof Player) {
                                $p->sendMessage(FMT::colorMessage(str_replace(["%player%", "%game%"], [$sender->getName(), $game], $this->main->getMessage("joined_game"))));
    
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::ARROW, 0, 64));
            $p->getInventory()->addItem(Item::get(ITEM::DIAMOND_SWORD));
            $p->getInventory()->addItem(Item::get(Item::BREAD, 0, 8));
            $p->getInventory()->addItem(Item::get(ITEM::BOW));
            $p->getInventory()->addItem(Item::get(Item::GOLDEN_APPLE, 0, 4));
    
           
            // Pur the armor on the player
            $p->getInventory()->setHelmet(Item::get(310, 0, 1));
            $p->getInventory()->setChestplate(Item::get(311, 0, 1));
            $p->getInventory()->setLeggings(Item::get(312, 0, 1));
            $p->getInventory()->setBoots(Item::get(313, 0, 1));
           
    //Send armor and item
             $p->getInventory()->sendContents($p);
             $p->getInventory()->sendArmorContents($p);
           
                
    
                            }
                            break;
                        }
                    break;
                    case 'q':
                    case 'quit':
                        if(isset(HGManagement::$data[$sender->getName()])){
                            $game = HGManagement::$data[$sender->getName()];
                            if(isset(HGGame::getApi()->players[$game][spl_object_hash($sender)])){
                                $pqge = new PlayerQuitGameEvent($this->main, $sender, $game);
                                $this->main->getServer()->getPluginManager()->callEvent($pqge);
                                if($pqge->isCancelled()) return;
                                $sender->teleport(HGGame::getApi()->getLobbyPosition($game));
                                HGGame::getApi()->onWait[HGManagement::$data[$sender->getName()]] -= 1;
                                $onWait = HGGame::getApi()->onWait[HGManagement::$data[$sender->getName()]];
                                if($onWait == 0){
                                    $this->main->e->resetMap(HGManagement::$data[$sender->getName()]);
                                    $this->main->e->deleteGameData(HGManagement::$data[$sender->getName()]);
                                    $this->main->e->deletePlayerData($sender);
                                    return;
                                }
                                if($onWait == 1){
                                    $this->main->e->resetMap(HGManagement::$data[$sender->getName()]);
                                    $this->main->e->endGame(HGManagement::$data[$sender->getName()]);
                                    $this->main->e->deleteGameData(HGManagement::$data[$sender->getName()]);
                                    $this->main->e->deletePlayerData($sender);
                                    return;
                                }
                                $sender->sendMessage(FMT::colorMessage("&aQuiting..."));
                            }else{
                                $sender->sendMessage(FMT::colorMessage("&cYou are not in a game."));
                            }
                        }
                        break;
                    case 'as':
                    case 'addslot':
                    if ($sender->isOp()) {
                        if (empty($args[1])) {
                            $sender->sendMessage(FMT::colorMessage("&e/hg addslot <game> &f add slot to game"));
                            return;
                        }
                        $game = $args[1];
                        if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                            $sender->sendMessage(FMT::colorMessage("&cError[S-1]: &egame does not exist."));
                            return;
                        }
                        $slot = count($this->main->getConfig()->getAll()["hg_games"][$game]["slots"]) + 1;
                        $x = $sender->x;
                        $y = $sender->y;
                        $z = $sender->z;
                        $this->main->getConfig()->setNested("hg_games.$game.slots.slot$slot", ["x" => $x, 1 => $y, "z" => $z]);
                        $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                        $this->main->getConfig()->save();
                        $sender->sendMessage(FMT::colorMessage("&aSuccessfully added slot at your current position."));
                    }
                        break;
                    case 'c':
                    case 'create':
                    if ($sender->isOp()) {
                        if (empty($args[1])) {
                            $sender->sendMessage(FMT::colorMessage("&e/hg create <name> &fcreate a game"));
                            return;
                        }
                        $game = $args[1];
                        if (isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                            $sender->sendMessage(FMT::colorMessage("&cError[C-1]: &egame already exists."));
                            return;
                        }
                        $s = $this->main->getServer()->getDefaultLevel()->getSpawnLocation();
                        $contents =
                            ["min_players" => 2,
                                "max_players" => 6,
                                "game_time" => 300,
                                "wait_time" => 60,
                                "level" => $sender->getLevel()->getName(),
                                "lobby_pos" =>
                                    [
                                        "x" => $s->x,
                                        1 => $s->y,
                                        "z" => $s->z,
                                        "level" => $s->level->getName()
                                    ],
                                "death_match_pos" =>
                                    [
                                        "x" => $sender->x,
                                        1 => $sender->y,
                                        "z" => $sender->z,
                                        "level" => $sender->level->getName()
                                    ],
                                "slots" => []
                            ];
                        $this->main->getConfig()->setNested("hg_games.$game", $contents);
                        $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                        $this->main->getConfig()->save();
                        $sender->sendMessage(FMT::colorMessage("&aSuccessfully created game $game."));
                    }
                        break;
                    case 'mn':
                    case 'min':
                        if($sender->isOp()) {
                            if (empty($args[1]) || empty($args[2]) || !is_numeric($args[2])) {
                                $sender->sendMessage(FMT::colorMessage("&e/hg min <game> <number> &fset minimum players for game"));
                                return;
                            }
                            $game = $args[1];
                            if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                                $sender->sendMessage(FMT::colorMessage("&cError[M-1]: &egame does not exist."));
                                return;
                            }
                            $min = intval($args[2]);
                            $this->main->getConfig()->setNested("hg_games.$game.min_players", $min);
                            $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                            $this->main->getConfig()->save();
                            $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed minimum players to $min."));
                        }
                        break;
                    case 'mx':
                    case 'max':
                        if($sender->isOp()) {
                            if (empty($args[1]) || empty($args[2]) || !is_numeric($args[2])) {
                                $sender->sendMessage(FMT::colorMessage("&e/hg max <game> <number> &fset minimum players for game"));
                                return;
                            }
                            $game = $args[1];
                            if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                                $sender->sendMessage(FMT::colorMessage("&cError[M-2]: &egame does not exist."));
                                return;
                            }
                            $max = intval($args[2]);
                            $this->main->getConfig()->setNested("hg_games.$game.max_players", $max);
                            $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                            $this->main->getConfig()->save();
                            $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed maximum players to $max."));
                        }
                        break;
                    case 't':
                    case 'time':
                        if($sender->isOp()) {
                            if (empty($args[1]) || empty($args[2]) || !is_numeric($args[3])) {
                                $sender->sendMessage(FMT::colorMessage("&e/hg time <game> <game|wait> <number> &fchange game/wait time"));
                                return;
                            }
                            $time = intval($args[3]);
                            $game = $args[1];
                            if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                                $sender->sendMessage(FMT::colorMessage("&cError[T-1]: &egame does not exist."));
                                return;
                            }
                            if(strtolower($args[2]) === "game"){
                                $this->main->getConfig()->setNested("hg_games.$game.game_time", $time);
                                $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                                $this->main->getConfig()->save();
                                $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed game time for $game to $time."));
                            }
                            if(strtolower($args[2]) === "wait"){
                                $this->main->getConfig()->setNested("hg_games.$game.wait_time", $time);
                                $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                                $this->main->getConfig()->save();
                                $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed wait time for $game to $time."));
                            }
                        }
                        break;
                    case 'l':
                    case 'lvl':
                    case 'level':
                        if($sender->isOp()) {
                            if (empty($args[1]) || empty($args[2])) {
                                $sender->sendMessage(FMT::colorMessage("&e/hg level <game> <level> &fchange level for a game"));
                                return;
                            }
                            $game = $args[1];
                            if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                                $sender->sendMessage(FMT::colorMessage("&cError[L-1]: &egame does not exist."));
                                return;
                            }
                            $level = $this->main->getServer()->getLevelByName($args[2]);
                            if(!$level){
                                $sender->sendMessage(FMT::colorMessage("&cError[L-2]: &einvalid level"));
                                return;
                            }
                            $this->main->getConfig()->setNested("hg_games.$game.level", $level->getName());
                            $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                            $this->main->getConfig()->save();
                            $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed level for $game to ".$level->getName()."."));
                        }
                        break;
                    case 'p':
                    case 'pos':
                    case 'position':
                    if($sender->isOp()) {
                        if (empty($args[1]) || empty($args[2])) {
                            $sender->sendMessage(FMT::colorMessage("&e/hg pos <game> <lobby|death-match> &fadd slot to game"));
                            return;
                        }
                        $game = $args[1];
                        if (!isset($this->main->getConfig()->getAll()["hg_games"][$game])) {
                            $sender->sendMessage(FMT::colorMessage("&cError[T-1]: &egame does not exist."));
                            return;
                        }
                        if(strtolower($args[2]) === "lobby"){
                            $this->main->getConfig()->setNested("hg_games.$game.lobby_pos", ["x" => $sender->x, 1=> $sender->y, "z" => $sender->z, "level" => $sender->level->getName()]);
                            $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                            $this->main->getConfig()->save();
                            $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed lobby position for $game to current position."));
                        }
                        if(strtolower($args[2]) === "death-match"){
                            $this->main->getConfig()->setNested("hg_games.$game.death_match_pos", ["x" => $sender->x, 1=> $sender->y, "z" => $sender->z, "level" => $sender->level->getName()]);
                            $this->main->getConfig()->setAll($this->main->getConfig()->getAll());
                            $this->main->getConfig()->save();
                            $sender->sendMessage(FMT::colorMessage("&aSuccessfully changed death-match position for $game to current position."));
                        }
                    }
                        break;
                    default:
                        $sender->sendMessage(FMT::colorMessage("&eUnknown command. &6Please use: ".$this->getUsage()));
                        break;
                }
            }else{
                $sender->sendMessage(FMT::colorMessage("&cPlease run command in-game."));
            }
        }
        /**
         * @return \pocketmine\plugin\Plugin
         */
        public function getPlugin()
        {
            return $this->main;
        }
    }
    
  9. MrReskill
    Offline

    MrReskill New Member

    Joined:
    Sep 21, 2015
    Posts:
    29
    Minecraft User:
    MrReskillYT
  10. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    -_-
    Item not ITEM, class names are case-sentensive.
  11. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    not related to this, and you're using @xBeastMode's SG.
  12. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Class names are not case sensitive. Only the class file names are sensitive on some systems ;) but still, the same result.
    Vaivez66 likes this.

Share This Page

Advertisement