本文整理汇总了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 . "조합 금지 블록을 사용하였습니다");
}
}
示例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;
}
}
}
示例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();
}
}
示例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();
}
}
示例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;
}
}
}
}
}
}