作者:TDMGamingM
项目:HungerSimulato
public function playerItemConsume(PlayerItemConsumeEvent $event)
{
$player = $event->getPlayer();
if ($player->getGamemode() == 0) {
$item = $event->getItem();
$item_consumed = $item->getID();
if ($this->isExistsItem($item_consumed)) {
$event->setCancelled();
$count = $item->getCount();
if ($count == 1) {
$item = Item::get(0, 0, 0);
} else {
$item->setCount($count - 1);
}
$player->getInventory()->setItemInHand($item);
if ($item_consumed == 367 || $item_consumed == 365) {
if ($this->setPlayerPoisoned($player->getDisplayName(), $this->poison[$item_consumed]) == true) {
$this->chat($player, "You have been poisoned by food", 4);
}
}
$var = $this->items[$item_consumed];
$this->addFoodLevel($player, $var[0]);
$this->addFoodSaturationLevel($player, $var[1]);
$this->test($player->getDisplayName());
}
}
}
作者:ItzFrozenCreepe
项目:Golden-Appl
public function eat(PlayerItemConsumeEvent $ev)
{
$p = $ev->getPlayer();
if ($ev->getItem()->getId() === 322) {
$p->addEffect(Effect::getEffect(10)->setAmplifier(4)->setDuration(100)->setVisible(true));
$p->addEffect(Effect::getEffect(21)->setAmplifier(2)->setDuration(20 * 120)->setVisible(true));
}
}
作者:EmreTr
项目:rt
public function onDrop(PlayerItemConsumeEvent $event)
{
if ($event->getItem() instanceof Arrow or $event->getItem() instanceof Snowball) {
if ($event->getItem()->shootingEntity == null) {
return;
}
if (isset($this->object_hash[spl_object_hash($event->getEntity())])) {
$event->setCancelled();
}
}
}
作者:HeechFiv
项目:pocketmine-plugin
public function onConsume(PlayerItemConsumeEvent $ev)
{
if ($ev->isCancelled()) {
return;
}
$pl = $ev->getPlayer();
if ($pl->hasPermission("wp.banitem.exempt")) {
return;
}
$world = $pl->getLevel()->getName();
if (!isset($this->wcfg[$world])) {
return;
}
$item = $ev->getItem();
if (!isset($this->wcfg[$world][$item->getId()])) {
return;
}
$pl->sendMessage(mc::_("You can not use that item here!"));
$ev->setCancelled();
}
作者:TDMGamingM
项目:PlayHarde
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof EntityEventPacket) {
if ($player->spawned === \true or $player->blocked === \false or $player->isAlive()) {
$player->craftingType = 0;
$player->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_ACTION, \false);
// TODO: check if this should be true
switch ($packet->event) {
case 9:
// Eating
$items = [Item::APPLE => 4, Item::MUSHROOM_STEW => 10, Item::BEETROOT_SOUP => 10, Item::BREAD => 5, Item::RAW_PORKCHOP => 3, Item::COOKED_PORKCHOP => 8, Item::RAW_BEEF => 3, Item::STEAK => 8, Item::COOKED_CHICKEN => 6, Item::RAW_CHICKEN => 2, Item::MELON_SLICE => 2, Item::GOLDEN_APPLE => 10, Item::PUMPKIN_PIE => 8, Item::CARROT => 4, Item::POTATO => 1, Item::BAKED_POTATO => 6, Item::COOKIE => 2, Item::COOKED_FISH => [0 => 5, 1 => 6], Item::RAW_FISH => [0 => 2, 1 => 2, 2 => 1, 3 => 1]];
$slot = $player->getInventory()->getItemInHand();
if (isset($items[$slot->getId()])) {
$this->getServer()->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($player, $slot));
if ($ev->isCancelled()) {
$player->getInventory()->sendContents($this);
break;
}
$pk = new EntityEventPacket();
$pk->eid = $player->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$player->dataPacket($pk);
Server::broadcastPacket($player->getViewers(), $pk);
$amount = $items[$slot->getId()];
if (\is_array($amount)) {
$amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0;
}
$ev = new EntityRegainHealthEvent($player, $amount, EntityRegainHealthEvent::CAUSE_EATING);
$this->getServer()->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
return;
}
--$slot->count;
$player->getInventory()->setItemInHand($slot, $player);
if ($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP) {
$this->getInventory()->addItem(Item::get(Item::BOWL, 0, 1));
} elseif ($slot->getId() === Item::RAW_FISH and $slot->getDamage() === 3) {
// Pufferfish
$player->addEffect(Effect::getEffect(Effect::HUNGER)->setAmplifier(2)->setDuration(15 * 20));
$player->addEffect(Effect::getEffect(Effect::POISON)->setAmplifier(3)->setDuration(60 * 20));
}
}
$event->setCancelled();
break;
}
}
if ($packet instanceof PlayerActionPacket) {
if ($packet->action == PlayerActionPacket::ACTION_JUMP) {
if ($event->getPlayer()->isSprinting()) {
HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING_WHILE_SPRINTING);
} else {
if ($event->getPlayer()->isSprinting()) {
HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING);
}
}
}
if ($packet->action == PlayerActionPacket::ACTION_START_SPRINT) {
$attribute = AttributeProvider::getInstance()->getAttribute($event->getPlayer());
if ($attribute->getHunger() < 6) {
$event->setCancelled();
}
}
}
}
}
作者:stoastye8
项目:Plugin
public function onPlayerItemConsume(PlayerItemConsumeEvent $event)
{
$event->setCancelled($this->isLogin($event->getPlayer()) ? false : true);
}
作者:pid01
项目:SimpleLogi
public function onPlayerItemConsume(PlayerItemConsumeEvent $event)
{
$player = $event->getPlayer();
if (!$this->isLogin($player)) {
$event->setCancelled();
return true;
}
}
作者:Edwardthedog
项目:BetterLogi
public function onItemConsume(PlayerItemConsumeEvent $event)
{
if (!$this->isLoggedIn($event->getPlayer())) {
$event->setCancelled();
}
return;
}
作者:JungHyun345
项目:PocketMine-Plugin
public function onPlayerItemConsume(\pocketmine\event\player\PlayerItemConsumeEvent $event)
{
if (!$this->isLogin($event->getPlayer())) {
$event->setCancelled();
}
}
作者:WonderlandP
项目:Steadfast
//.........这里部分代码省略.........
if ($f < 0.1 or $diff < 5) {
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
$this->inventory->sendContents($this);
} else {
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if ($this->isSurvival()) {
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1));
$bow->setDamage($bow->getDamage() + 1);
if ($bow->getDamage() >= 385) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0));
} else {
$this->inventory->setItemInHand($bow);
}
}
if ($ev->getProjectile() instanceof Projectile) {
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if ($projectileEv->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$ev->getProjectile()->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
} else {
$ev->getProjectile()->spawnToAll();
}
}
}
} elseif ($this->inventory->getItemInHand()->getId() === Item::BUCKET and $this->inventory->getItemInHand()->getDamage() === 1) {
//Milk!
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $this->inventory->getItemInHand()));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk);
if ($this->isSurvival()) {
$slot = $this->inventory->getItemInHand();
--$slot->count;
$this->inventory->setItemInHand($slot);
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 1));
}
$this->removeAllEffects();
} else {
$this->inventory->sendContents($this);
}
break;
case PlayerActionPacket::ACTION_STOP_SLEEPING:
$this->stopSleep();
break;
case PlayerActionPacket::ACTION_RESPAWN:
if ($this->spawned === false or $this->isAlive() or !$this->isOnline()) {
break;
}
if ($this->server->isHardcore()) {
$this->setBanned(true);
break;
}
$this->craftingType = 0;
作者:DWW
项目:pocketmine-plugin
public function onConsume(PlayerItemConsumeEvent $ev)
{
$this->checkPlenty($ev->getPlayer(), $ev->getItem());
}
作者:XEmAX3
项目:PlayHarde
public function onDataPacketReceiveEvent(DataPacketReceiveEvent $event)
{
$packet = $event->getPacket();
$player = $event->getPlayer();
if ($packet instanceof EntityEventPacket) {
if ($player->spawned === \true or $player->blocked === \false or $player->isAlive()) {
$player->craftingType = 0;
$player->setDataFlag(Player::DATA_FLAGS, Player::DATA_FLAG_ACTION, \false);
// TODO: check if this should be true
switch ($packet->event) {
case 9:
// Eating
$items = [Item::GOLDEN_APPLE => 8];
$slot = $player->getInventory()->getItemInHand();
if (isset($items[$slot->getId()])) {
$this->getServer()->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($player, $slot));
if ($ev->isCancelled()) {
$player->getInventory()->sendContents($player);
break;
}
$pk = new EntityEventPacket();
$pk->eid = $player->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$player->dataPacket($pk);
Server::broadcastPacket($player->getViewers(), $pk);
$amount = $items[$slot->getId()];
if (\is_array($amount)) {
$amount = isset($amount[$slot->getDamage()]) ? $amount[$slot->getDamage()] : 0;
}
$ev = new EntityRegainHealthEvent($player, $amount, EntityRegainHealthEvent::CAUSE_EATING);
$this->getServer()->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
return;
}
--$slot->count;
$player->getInventory()->setItemInHand($slot, $player);
}
$event->setCancelled();
break;
}
}
if ($packet instanceof PlayerActionPacket) {
if ($packet->action == PlayerActionPacket::ACTION_JUMP) {
if ($event->getPlayer()->isSprinting()) {
HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING_WHILE_SPRINTING);
} else {
if ($event->getPlayer()->isSprinting()) {
HungerSystem::exhaustion($event->getPlayer(), HungerSystem::JUMPING);
}
}
}
if ($packet->action == PlayerActionPacket::ACTION_START_SPRINT) {
$attribute = AttributeProvider::getInstance()->getAttribute($event->getPlayer());
if ($attribute->getHunger() < 6) {
$event->setCancelled();
}
}
}
}
}
作者:LegionP
项目:LegionPE-Et
public function h_onItemConsume(PlayerItemConsumeEvent $event)
{
if (!$this->isLoggedIn()) {
$event->setCancelled();
}
}
作者:GoneTon
项目:HereAut
public function onEat(PlayerItemConsumeEvent $event)
{
$user = $this->main->getUserByPlayer($event->getPlayer());
if ($user === null or !$user->isPlaying()) {
$event->setCancelled();
}
}
作者:EmreTr
项目:rt
public function onDrop(PlayerItemConsumeEvent $event)
{
if ($event->getItem() instanceof Arrow) {
if ($event->getItem()->shootingEntity == null) {
return;
}
if ($event->getItem()->shootingEntity instanceof Entities) {
$event->setCancelled();
}
}
}
作者:rry
项目:PocketMine-M
//.........这里部分代码省略.........
$this->teleport($ev->getRespawnPosition());
$this->fireTicks = 0;
$this->airTicks = 300;
$this->deadTicks = 0;
$this->setHealth(20);
$this->dead = false;
$this->sendMetadata($this->getViewers());
$this->sendMetadata($this);
$this->sendSettings();
$this->inventory->sendContents($this);
$this->inventory->sendArmorContents($this);
$this->blocked = false;
$this->spawnToAll();
$this->scheduleUpdate();
break;
case ProtocolInfo::SET_HEALTH_PACKET:
//Not used
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
$this->craftingType = 0;
if ($this->inAction === true) {
$this->inAction = false;
$this->sendMetadata($this->getViewers());
}
switch ($packet->event) {
case 9:
//Eating
$items = [Item::APPLE => 4, Item::MUSHROOM_STEW => 10, Item::BEETROOT_SOUP => 10, Item::BREAD => 5, Item::RAW_PORKCHOP => 3, Item::COOKED_PORKCHOP => 8, Item::RAW_BEEF => 3, Item::STEAK => 8, Item::COOKED_CHICKEN => 6, Item::RAW_CHICKEN => 2, Item::MELON_SLICE => 2, Item::GOLDEN_APPLE => 10, Item::PUMPKIN_PIE => 8, Item::CARROT => 4, Item::POTATO => 1, Item::BAKED_POTATO => 6];
$slot = $this->inventory->getItemInHand();
if ($this->getHealth() < 20 and isset($items[$slot->getId()])) {
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $slot));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
$pk = new EntityEventPacket();
$pk->eid = 0;
$pk->event = 9;
$this->dataPacket($pk);
$pk->eid = $this->getId();
Server::broadcastPacket($this->getViewers(), $pk);
$amount = $items[$slot->getId()];
$this->server->getPluginManager()->callEvent($ev = new EntityRegainHealthEvent($this, $amount, EntityRegainHealthEvent::CAUSE_EATING));
if (!$ev->isCancelled()) {
$this->heal($ev->getAmount(), $ev);
}
--$slot->count;
$this->inventory->setItemInHand($slot, $this);
if ($slot->getId() === Item::MUSHROOM_STEW or $slot->getId() === Item::BEETROOT_SOUP) {
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1), $this);
}
}
break;
}
break;
case ProtocolInfo::DROP_ITEM_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
$packet->eid = $this->id;
$item = $this->inventory->getItemInHand();
$ev = new PlayerDropItemEvent($this, $item);
$this->server->getPluginManager()->callEvent($ev);
作者:jigibbs12
项目:pocketmine-plugin
/**
* @param PlayerItemConsumeEvent $event
*
* @priority LOWEST
*/
public function onPlayerItemConsume(PlayerItemConsumeEvent $event)
{
if (!$this->auth->isPlayerAuthenticated($event->getPlayer())) {
$event->setCancelled(true);
}
}
作者:DesPlaysM
项目:ClearSk
public function eatFoodInHand()
{
if ($this->eatCoolDown + 1800 >= time()) {
return;
}
$eatenItem = $this->inventory->getItemInHand();
if ($eatenItem instanceof Food) {
if ($this->getRealFood() >= 20 && $eatenItem->getId() !== Item::GOLDEN_APPLE && $eatenItem->getId() !== Item::ENCHANTED_GOLDEN_APPLE && $eatenItem->getId() !== Item::POTION && !($eatenItem->getId() === Item::BUCKET && $eatenItem->getDamage() === 1)) {
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $eatenItem));
$ev->setCancelled();
} elseif ($this->getRealFood() < 20 || ($eatenItem->getId() === Item::GOLDEN_APPLE || $eatenItem->getId() === Item::ENCHANTED_GOLDEN_APPLE || $eatenItem->getId() === Item::POTION || $eatenItem->getId() === Item::BUCKET && $eatenItem->getDamage() === 1)) {
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $eatenItem));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
return;
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk);
$this->setFood($this->getFood() + $eatenItem->getSaturation());
--$eatenItem->count;
$this->inventory->setItemInHand($eatenItem);
if ($eatenItem->getId() === Item::MUSHROOM_STEW || $eatenItem->getId() === Item::BEETROOT_SOUP || $eatenItem->getId() === Item::RABBIT_STEW) {
$this->inventory->addItem(Item::get(Item::BOWL, 0, 1));
} elseif ($eatenItem->getId() === Item::POTION) {
$this->inventory->addItem(Item::get(Item::GLASS_BOTTLE, 0, 1));
} elseif ($eatenItem->getId() === Item::BUCKET && $eatenItem->getDamage() === 1) {
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 1));
$this->removeAllEffects();
}
if (!empty($eatenItem->getEffects())) {
foreach ($eatenItem->getEffects() as $effects => $keys) {
if (mt_rand(0, 100) <= $keys[1] * 100) {
$this->addEffect($keys[0]);
}
}
}
}
}
}
作者:robske11
项目:ClearSk
//.........这里部分代码省略.........
if ($f < 0.1 or $diff < 5) {
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
$this->inventory->sendContents($this);
} else {
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if ($this->isSurvival()) {
$this->inventory->removeItem(Item::get(Item::ARROW, $arrow->getDamage(), 1));
$bow->setDamage($bow->getDamage() + 1);
if ($bow->getDamage() >= 385) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0));
} else {
$this->inventory->setItemInHand($bow);
}
}
if ($ev->getProjectile() instanceof Projectile) {
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if ($projectileEv->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$ev->getProjectile()->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
} else {
$ev->getProjectile()->spawnToAll();
}
}
}
} elseif ($this->inventory->getItemInHand()->getId() === Item::BUCKET and $this->inventory->getItemInHand()->getDamage() === 1) {
//Milk!
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $this->inventory->getItemInHand()));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;
$this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk);
if ($this->isSurvival()) {
$slot = $this->inventory->getItemInHand();
--$slot->count;
$this->inventory->setItemInHand($slot);
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 1));
}
$this->removeAllEffects();
} else {
$this->inventory->sendContents($this);
}
break;
case PlayerActionPacket::ACTION_STOP_SLEEPING:
$this->stopSleep();
break;
case PlayerActionPacket::ACTION_RESPAWN:
if ($this->spawned === false or $this->isAlive() or !$this->isOnline()) {
break;
}
if ($this->server->isHardcore()) {
$this->setBanned(true);
break;
}
$this->craftingType = self::CRAFTING_SMALL;
作者:TylerGame
项目:PocketMine-M
//.........这里部分代码省略.........
if ($f < 0.1 or $diff < 5) {
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
if ($ev->isCancelled()) {
$ev->getProjectile()->kill();
$this->inventory->sendContents($this);
} else {
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
if ($this->isSurvival()) {
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1));
$bow->setDamage($bow->getDamage() + 1);
if ($bow->getDamage() >= 385) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0));
} else {
$this->inventory->setItemInHand($bow);
}
}
if ($ev->getProjectile() instanceof Projectile) {
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($ev->getProjectile()));
if ($projectileEv->isCancelled()) {
$ev->getProjectile()->kill();
} else {
$ev->getProjectile()->spawnToAll();
$this->level->addSound(new LaunchSound($this), $this->getViewers());
}
} else {
$ev->getProjectile()->spawnToAll();
}
}
}
} elseif ($this->inventory->getItemInHand()->getId() === Item::BUCKET and $this->inventory->getItemInHand()->getDamage() === 1) {
//Milk!
$this->server->getPluginManager()->callEvent($ev = new PlayerItemConsumeEvent($this, $this->inventory->getItemInHand()));
if ($ev->isCancelled()) {
$this->inventory->sendContents($this);
break;
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = 9;
$pk->setChannel(Network::CHANNEL_WORLD_EVENTS);
$this->dataPacket($pk);
Server::broadcastPacket($this->getViewers(), $pk);
if ($this->isSurvival()) {
$slot = $this->inventory->getItemInHand();
--$slot->count;
$this->inventory->setItemInHand($slot, $this);
$this->inventory->addItem(Item::get(Item::BUCKET, 0, 1));
}
$this->removeAllEffects();
} else {
$this->inventory->sendContents($this);
}
break;
case 6:
//get out of the bed
$this->stopSleep();
break;
case 7:
//Respawn
if ($this->spawned === false or $this->dead === false) {
break;
}
$this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));