当前位置: 首页>>代码示例>>PHP>>正文


PHP CraftItemEvent::setCancelled方法代码示例

本文整理汇总了PHP中pocketmine\event\inventory\CraftItemEvent::setCancelled方法的典型用法代码示例。如果您正苦于以下问题:PHP CraftItemEvent::setCancelled方法的具体用法?PHP CraftItemEvent::setCancelled怎么用?PHP CraftItemEvent::setCancelled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\event\inventory\CraftItemEvent的用法示例。


在下文中一共展示了CraftItemEvent::setCancelled方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: craftEvent

 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 . "조합 금지 블록을 사용하였습니다");
     }
 }
开发者ID:sJimin,项目名称:PHPTEST,代码行数:8,代码来源:BanCraft.php

示例2: onCrafting

 /**
  * @priority LOWEST
  */
 public function onCrafting(CraftItemEvent $event)
 {
     echo __METHOD__ . "," . __LINE__ . "\n";
     //##DEBUG
     foreach ($event->getTransaction()->getInventories() as $inv) {
         echo __METHOD__ . "," . __LINE__ . "\n";
         //##DEBUG
         if ($inv instanceof PlayerInventory) {
             continue;
         }
         echo __METHOD__ . "," . __LINE__ . "\n";
         //##DEBUG
         $player = $inv->getHolder();
         if (!$this->auth->isPlayerAuthenticated($inv->getHolder())) {
             echo __METHOD__ . "," . __LINE__ . "\n";
             //##DEBUG
             $event->setCancelled(true);
             return;
         }
     }
 }
开发者ID:DWWf,项目名称:pocketmine-plugins,代码行数:24,代码来源:EventListener.php

示例3: onCraftItem

 public function onCraftItem(CraftItemEvent $event)
 {
     $t = $event->getTransaction();
     if (!($p = $t->getSource()) instanceof Player) {
         return;
     }
     $r = $t->getResult();
     if (!$p->hasPermission("mineblock.bancraft.craft") && in_array($id = $r->getID() . ":" . $r->getDamage(), $this->bc)) {
         $p->sendMessage("[BanCraft] {$id}" . ($this->isKorean() ? "는 조합금지 아이템입니다. 조합할수없습니다." : " is Ban. You can't craft."));
         $p->getInventory()->sendContents($p);
         $event->setCancelled();
     }
 }
开发者ID:Skull3x,项目名称:MineBlock,代码行数:13,代码来源:BanCraft.php

示例4: onCraftItem

 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();
     }
 }
开发者ID:thebigsmileXD,项目名称:PocketMine-MP-Plugins,代码行数:74,代码来源:MainClass.php

示例5: onCraftItem

 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;
                     }
                 }
             }
         }
     }
 }
开发者ID:HelloWorld017,项目名称:ToAruPG,代码行数:41,代码来源:ToAruPG.php


注:本文中的pocketmine\event\inventory\CraftItemEvent::setCancelled方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。