getPlayer() public method

public getPlayer ( ) : Player
return pocketmine\Player
コード例 #1
0
ファイル: BanCraft.php プロジェクト: sJimin/PHPTEST
 public function craftEvent(CraftItemEvent $event)
 {
     $ItemId = $event->getRecipe()->getResult()->getId() . ":" . $event->getRecipe()->getResult()->getDamage();
     if ($this->isData($ItemId)) {
         $event->setCancelled(true);
         $event->getPlayer()->sendMessage(TextFormat::RED . $ItemId . "조합 금지 블록을 사용하였습니다");
     }
 }
コード例 #2
0
 public function onCraftItem(CraftItemEvent $event)
 {
     //CraftingBug
     $recipe = $event->getRecipe();
     if (!$event->isCancelled() and $recipe instanceof ShapedRecipe and self::ENABLE_CRAFTING_BUG) {
         //todo もっと効率的な処理
         $player = $event->getPlayer();
         $event->setCancelled();
         //イベントをキャンセル
         $mapitems = $recipe->getIngredientMap();
         $items = array();
         foreach ($mapitems as $key => $map) {
             //mapから材料となるアイテムをまとめる
             foreach ($map as $key2 => $item) {
                 $r = true;
                 foreach ($items as $item2) {
                     if ($item->equals($item2)) {
                         $item2->setCount($item2->getCount() + 1);
                         $r = false;
                         break;
                     }
                 }
                 if ($r and $item->getId() !== Item::AIR) {
                     $items[] = $item;
                 }
             }
         }
         foreach ($items as $item) {
             //材料となるアイテムを持っているかを一応確認
             if (!$player->getInventory()->contains($item)) {
                 echo "test";
                 return false;
             }
         }
         $debug = "";
         $contents = $player->getInventory()->getContents();
         foreach ($items as $item) {
             //材料アイテムをプレーヤーからとる
             $count = $item->getCount();
             $checkDamage = $item->getDamage() === null ? false : true;
             $checkTags = $item->getCompoundTag() === null ? false : true;
             foreach ($contents as $slot => $i) {
                 if ($item->equals($i, $checkDamage, $checkTags)) {
                     $nc = min($i->getCount(), $count);
                     $count -= $nc;
                     $newItem = clone $i;
                     $newItem->setCount($i->getCount() - $nc);
                     $player->getInventory()->setItem($slot, $newItem);
                     $debug .= "test:" . $i . "\n";
                     $debug .= $newItem . "\ncount." . $count . "\nnc." . $nc . "\nbc." . $item->getCount() . "\n\n";
                 }
                 if ($count <= 0) {
                     break;
                 }
             }
             if ($count > 0) {
                 continue;
                 //...
             }
         }
         $debug .= "result:" . $recipe->getResult() . "\n\n";
         $extra = $player->getInventory()->addItem($recipe->getResult());
         //完成後のアイテムをインベントリへ
         if (count($extra) > 0) {
             foreach ($extra as $item) {
                 //インベントリが一杯だった場合はその場にドロップさせる
                 $player->getLevel()->dropItem($player, $item);
             }
         }
         $this->getLogger()->debug($debug);
     } else {
         $event->setCancelled();
     }
 }
コード例 #3
0
ファイル: ToAruPG.php プロジェクト: HelloWorld017/ToAruPG
 public function onCraftItem(CraftItemEvent $event)
 {
     /**
      * @var $player Player
      */
     $player = $event->getPlayer();
     $craftingPlayer = $this->getRPGPlayerByName($event->getPlayer());
     if ($craftingPlayer === null) {
         $player->sendMessage(TextFormat::RED . self::getTranslation("INVALID_PLAYER"));
         $event->setCancelled();
         return;
     }
     $recipe = $event->getRecipe();
     if ($recipe instanceof ShapelessRecipe) {
         foreach ($recipe->getIngredientList() as $item) {
             echo $item->getName() . "x" . $item->getCount();
             if ($craftingPlayer->getSkillByItem($item) !== null) {
                 if (!$player->getInventory()->contains(Item::get($item->getId(), $item->getDamage(), $item->getCount() + 1))) {
                     echo "cancelledEvent";
                     $event->setCancelled();
                     return;
                 }
             }
         }
     }
     if ($recipe instanceof ShapedRecipe) {
         foreach ($recipe->getIngredientMap() as $items) {
             /**
              * @var $item Item
              */
             foreach ($items as $item) {
                 if ($craftingPlayer->getSkillByItem($item) !== null) {
                     if (!$player->getInventory()->contains(Item::get($item->getId(), $item->getDamage(), $item->getCount() + 1))) {
                         $event->setCancelled();
                         return;
                     }
                 }
             }
         }
     }
 }