本文整理汇总了PHP中pocketmine\event\inventory\InventoryPickupItemEvent类的典型用法代码示例。如果您正苦于以下问题:PHP InventoryPickupItemEvent类的具体用法?PHP InventoryPickupItemEvent怎么用?PHP InventoryPickupItemEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InventoryPickupItemEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onPickUp
public function onPickUp(InventoryPickupItemEvent $event)
{
if ($event->getPlayer() instanceof Player && $this->plugin->status === "enabled" && $this->plugin->loginmanager[$event->getPlayer()->getId()] !== true && $this->plugin->allowPickup !== true) {
$event->setCancelled(true);
} elseif ($this->plugin->safemode === true and $this->plugin->status !== "enabled") {
$event->setCancelled(true);
$event->getPlayer()->sendMessage($this->disable);
}
}
示例2: onUpdate
public function onUpdate($currentTick)
{
if (!$this->loggedIn) {
return false;
}
$tickDiff = $currentTick - $this->lastUpdate;
if ($tickDiff <= 0) {
return true;
}
$this->messageCounter = 2;
$this->lastUpdate = $currentTick;
if ($this->dead === true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
$this->lastUpdate = $currentTick;
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->speed and $this->isSurvival()) {
$speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2);
if ($speed > 0.45) {
$this->highSpeedTicks += $speed > 3 ? 2 : 1;
if ($this->highSpeedTicks > 40 and !$this->server->getAllowFlight()) {
$this->kick("Flying is not enabled on this server");
return false;
} elseif ($this->highSpeedTicks >= 10 and $this->highSpeedTicks % 4 === 0) {
$this->forceMovement = $this->getPosition();
$this->speed = null;
}
} elseif ($this->highSpeedTicks > 0) {
if ($speed < 22) {
$this->highSpeedTicks = 0;
} else {
$this->highSpeedTicks--;
}
}
}
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 10 and $this->isSurvival() and !$this->isSleeping()) {
$expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * exp(-$this->drag * ($this->inAirTicks - 2));
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
if ($diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()) {
if ($this->inAirTicks < 100) {
$this->setMotion(new Vector3(0, $expectedVelocity, 0));
} else {
$this->kick("Flying is not enabled on this server");
return false;
}
}
}
++$this->inAirTicks;
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->hadCollision) {
if ($entity->dead !== true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
//.........这里部分代码省略.........
示例3: onPickupItem
public function onPickupItem(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if (!$this->isLogin($player)) {
$event->setCancelled();
return true;
}
}
示例4: onPickup
public function onPickup(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player) {
if ($event->getItem()->getItem()->getId() === self::GUN_ID) {
$this->players[$player->getName()][0]->addAmmo(30);
if ($player->getInventory()->contains(Item::get(self::GUN_ID))) {
$event->getItem()->kill();
$event->setCancelled();
}
} else {
$event->getItem()->kill();
}
}
}
示例5: onPickupItem
/**
* @param InventoryPickupItemEvent $event
*
* @priority LOWEST
*/
public function onPickupItem(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player and !$this->auth->isPlayerAuthenticated($player)) {
$event->setCancelled(true);
}
}
示例6: onUpdate
public function onUpdate($currentTick)
{
if ($this->dead === true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
$this->lastUpdate = $currentTick;
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 100 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()) {
$this->kick("Flying is not enabled on this server");
return false;
} else {
++$this->inAirTicks;
}
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->onGround) {
if ($entity->dead !== true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$this->inventory->addItem(clone $item, $this);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$this->inventory->addItem(clone $item, $this);
$entity->kill();
}
}
}
}
}
if ($this->nextChunkOrderRun-- <= 0 or $this->chunk === null) {
$this->orderChunks();
}
if (count($this->loadQueue) > 0 or !$this->spawned) {
$this->sendNextChunk();
}
if (count($this->moveToSend) > 0) {
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->dataPacket($pk);
$this->moveToSend = [];
}
if (count($this->motionToSend) > 0) {
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->dataPacket($pk);
$this->motionToSend = [];
//.........这里部分代码省略.........
示例7: onPickupItem
public function onPickupItem(InventoryPickupItemEvent $event)
{
$holder = $event->getInventory()->getHolder();
if (!$holder instanceof Player) {
return;
}
$session = $this->main->getSession($holder);
if (!$session instanceof Session) {
$event->setCancelled();
return;
}
if ($session->onPickupItem($event) === false) {
$event->setCancelled();
}
}
示例8: onUpdate
public function onUpdate()
{
if ($this->spawned === false) {
return true;
}
$hasUpdate = $this->entityBaseTick();
foreach ($this->getLevel()->getNearbyEntities($this->boundingBox->grow(1, 1, 1), $this) as $entity) {
if ($entity instanceof DroppedItem) {
if ($entity->dead !== true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $item));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getID()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getID();
$this->dataPacket($pk);
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getID();
$pk->target = $entity->getID();
Server::broadcastPacket($entity->getViewers(), $pk);
$this->inventory->addItem(clone $item);
$entity->kill();
}
}
}
}
}
示例9: h_onPickup
public function h_onPickup(InventoryPickupItemEvent $event)
{
if (!$this->isLoggedIn()) {
$event->setCancelled();
}
}
示例10: onPickupItem
/**
* @param InventoryPickupItemEvent $event
*
* @priority HIGH
* @ignoreCancelled true
*/
public function onPickupItem(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player and !$player->isOp()) {
foreach ($this->plugin->getAllZones() as $zone) {
if ($zone->isIn($event->getItem())) {
if ($player->hasPermission($zone->getName() . MEMBER)) {
break;
}
$event->setCancelled(true);
$player->sendMessage("[iZone] This is a private area.");
break;
}
}
}
}
示例11: onPickup
public function onPickup(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player) {
if ($this->inArena($player)) {
if (!in_array($event->getItem()->getId(), $this->pickup)) {
if ($event->getItem()->getItem()->getId() == Item::BRICK) {
$event->setCancelled();
$player->getLevel()->removeEntity($event->getItem());
$this->pickup[] = $event->getItem()->getId();
$player->setExpLevel($player->getExpLevel() + 1);
$player->sendTip(TextFormat::GOLD . "+" . TextFormat::GREEN . "1 Level!");
}
if ($event->getItem()->getItem()->getId() == Item::IRON_INGOT) {
$event->setCancelled();
$player->getLevel()->removeEntity($event->getItem());
$this->pickup[] = $event->getItem()->getId();
$player->setExpLevel($player->getExpLevel() + 10);
$player->sendTip(TextFormat::GOLD . "+" . TextFormat::GREEN . "10 Level!");
}
if ($event->getItem()->getItem()->getId() == Item::GOLD_INGOT) {
$event->setCancelled();
$player->getLevel()->removeEntity($event->getItem());
$this->pickup[] = $event->getItem()->getId();
$player->setExpLevel($player->getExpLevel() + 20);
$player->sendTip(TextFormat::GOLD . "+" . TextFormat::GREEN . "20 Level!");
}
}
}
}
}
示例12: onPick
public function onPick(InventoryPickupItemEvent $event)
{
$inv = $event->getInventory();
if (!$inv instanceof PlayerInventory) {
return;
}
$player = $inv->getHolder();
if (!$player instanceof Player) {
return;
}
$user = $this->main->getUserByPlayer($player);
if ($user === null or !$user->isPlaying()) {
$event->setCancelled();
}
}
示例13: onPickup
public function onPickup(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player) {
$item = $event->getItem()->getItem();
if (isset($this->loadedGuns[$item->getId() . ":" . $item->getDamage()])) {
$gun = $this->players[$player->getName()][0];
if ($gun->getGunItem() === $item->getId() . ":" . $item->getDamage()) {
$gun->addAmmo($gun->getMagazineAmmo());
$event->getItem()->kill();
}
$event->setCancelled();
} else {
$event->getItem()->kill();
}
}
}
示例14: onUpdate
public function onUpdate($currentTick)
{
if (!$this->loggedIn) {
return \false;
}
if ($this->dead === \true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 20 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()) {
$expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * \exp(-$this->drag * ($this->inAirTicks - 2));
$diff = ($this->speed->y - $expectedVelocity) ** 2;
if ($diff > 0.6 and $expectedVelocity < $this->speed->y) {
$this->kick("Disable fly mods.");
}
return \false;
} else {
++$this->inAirTicks;
}
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->hadCollision) {
if ($entity->dead !== \true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
$this->inventory->addItem(clone $item);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== \true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
$this->inventory->addItem(clone $item);
$entity->kill();
}
}
}
}
}
if ($this->nextChunkOrderRun-- <= 0 or $this->chunk === \null) {
$this->orderChunks();
}
if (\count($this->loadQueue) > 0 or !$this->spawned) {
$this->sendNextChunk();
}
if (\count($this->moveToSend) > 0) {
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->moveToSend = [];
}
if (\count($this->motionToSend) > 0) {
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->motionToSend = [];
}
if (\count($this->batchedPackets) > 0) {
//.........这里部分代码省略.........
示例15: checkNearEntities
protected function checkNearEntities($tickDiff)
{
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
$entity->scheduleUpdate();
if (!$entity->isAlive()) {
continue;
}
if ($entity instanceof Arrow and $entity->hadCollision) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
} elseif ($entity instanceof DroppedItem) {
if ($entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
}
}
}
}
}