作者:EpicArtz0899
项目:xAut
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);
}
}
作者:ZenaGamingsk
项目:Steadfast
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:
//.........这里部分代码省略.........
作者:pid01
项目:SimpleLogi
public function onPickupItem(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if (!$this->isLogin($player)) {
$event->setCancelled();
return true;
}
}
作者:EmreTr
项目:MineComba
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();
}
}
}
作者:jigibbs12
项目:pocketmine-plugin
/**
* @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);
}
}
作者:rry
项目:PocketMine-M
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 = [];
//.........这里部分代码省略.........
作者:legoboy021
项目:LegionPE-Theta-Bas
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();
}
}
作者:boyboo
项目:PocketMine-M
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();
}
}
}
}
}
作者:LegionP
项目:LegionPE-Et
public function h_onPickup(InventoryPickupItemEvent $event)
{
if (!$this->isLoggedIn()) {
$event->setCancelled();
}
}
作者:Tee7eve
项目:iZon
/**
* @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;
}
}
}
}
作者:Bluplay
项目:BedwarsP
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!");
}
}
}
}
}
作者:GoneTon
项目:HereAut
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();
}
}
作者:EmeraldGem58
项目:MineComba
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();
}
}
}
作者:Edwardthedog
项目:Steadfast
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) {
//.........这里部分代码省略.........
作者:NewDelio
项目:PocketMine-0.13.
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();
}
}
}
}
}
作者:iTXTec
项目:Genisy
protected function checkNearEntities($tickDiff)
{
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(0.5, 0.5, 0.5), $this) as $entity) {
$entity->scheduleUpdate();
if (!$entity->isAlive()) {
continue;
}
if ($entity instanceof Arrow and $entity->hadCollision) {
$item = Item::get(Item::ARROW, $entity->getPotionId(), 1);
$add = false;
if (!$this->server->allowInventoryCheats and !$this->isCreative()) {
if (!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)) {
//The item is added to the floating inventory to allow client to handle the pickup
//We have to also check if it can be added to the real inventory before sending packets.
continue;
}
$add = true;
}
$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);
if ($add) {
$this->getFloatingInventory()->addItem(clone $item);
}
$entity->kill();
} elseif ($entity instanceof DroppedItem) {
if ($entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
$add = false;
if (!$this->server->allowInventoryCheats and !$this->isCreative()) {
if (!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)) {
continue;
}
$add = true;
}
$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);
if ($add) {
$this->getFloatingInventory()->addItem(clone $item);
}
$entity->kill();
}
}
}
}
}
作者:LegionP
项目:LegionPE-Et
/**
* @param InventoryPickupItemEvent $event
* @priority HIGH
*/
public function h_onPickup(InventoryPickupItemEvent $event)
{
$player = $event->getInventory()->getHolder();
if ($player instanceof Player) {
$this->sessions[Session::offset($player)]->h_onPickup($event);
}
}
作者:LegionP
项目:LegionPE-Et
public function onPickup(InventoryPickupItemEvent $event)
{
$inv = $event->getInventory();
if (!$inv instanceof PlayerInventory) {
return;
}
$player = $inv->getHolder();
if (!$player instanceof Player) {
return;
}
$session = $this->getMain()->getSessions()->getSession($player);
if (!$session->inSession($this)) {
return;
}
$item = $event->getItem();
if ($item instanceof ItemBlock) {
if ($item->getBlock() === Block::SNOW_BLOCK) {
$event->setCancelled();
}
}
}