本文整理汇总了PHP中pocketmine\event\inventory\CraftItemEvent::getPlayer方法的典型用法代码示例。如果您正苦于以下问题:PHP CraftItemEvent::getPlayer方法的具体用法?PHP CraftItemEvent::getPlayer怎么用?PHP CraftItemEvent::getPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pocketmine\event\inventory\CraftItemEvent
的用法示例。
在下文中一共展示了CraftItemEvent::getPlayer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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();
}
}
示例3: 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;
}
}
}
}
}
}