本文整理汇总了PHP中pocketmine\event\player\PlayerAnimationEvent类的典型用法代码示例。如果您正苦于以下问题:PHP PlayerAnimationEvent类的具体用法?PHP PlayerAnimationEvent怎么用?PHP PlayerAnimationEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PlayerAnimationEvent类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleDataPacket
//.........这里部分代码省略.........
$armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
$points = 0;
foreach ($target->getInventory()->getArmorContents() as $index => $i) {
if (isset($armorValues[$i->getId()])) {
$points += $armorValues[$i->getId()];
}
}
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if ($cancelled) {
$ev->setCancelled();
}
$target->attack($ev->getFinalDamage(), $ev);
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($item->isTool() and $this->isSurvival()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
} else {
$this->inventory->setItemInHand($item, $this);
}
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or $this->dead === true) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
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;
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
//TODO: check if this should be true
switch ($packet->event) {
case 9:
//Eating
$this->eatFoodInHand();
break;
}
break;
case ProtocolInfo::DROP_ITEM_PACKET:
if ($this->spawned === false or $this->blocked === true or $this->dead === true) {
break;
}
if (!$this->inventory->contains($packet->item)) {
$this->inventory->sendContents($this);
break;
示例2: handleDataPacket
//.........这里部分代码省略.........
$armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
$points = 0;
foreach ($target->getInventory()->getArmorContents() as $index => $i) {
if (isset($armorValues[$i->getId()])) {
$points += $armorValues[$i->getId()];
}
}
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if ($cancelled) {
$ev->setCancelled();
}
$target->attack($ev->getFinalDamage(), $ev);
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($item->isTool() and $this->isSurvival()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
} else {
$this->inventory->setItemInHand($item, $this);
}
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or $this->dead === true) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
break;
case ProtocolInfo::RESPAWN_PACKET:
if ($this->spawned === false or $this->dead === false) {
break;
}
$this->craftingType = 0;
$this->server->getPluginManager()->callEvent($ev = new PlayerRespawnEvent($this, $this->getSpawn()));
$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;
示例3: handleDataPacket
//.........这里部分代码省略.........
$thornsEvent = new EntityDamageByEntityEvent($target, $this, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $ev->getThornsDamage(), 0);
if (!$thornsEvent->isCancelled()) {
if ($this->attack($thornsEvent->getFinalDamage(), $thornsEvent) === true) {
$thornsEvent->useArmors();
$ev->setThornsArmorUse();
}
}
}
}
$ev->useArmors();
}
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($this->isSurvival()) {
if ($item->isTool()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
} else {
$this->inventory->setItemInHand($item);
}
}
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
break;
case ProtocolInfo::SET_HEALTH_PACKET:
//Not used
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
$this->craftingType = self::CRAFTING_SMALL;
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
//TODO: check if this should be true
switch ($packet->event) {
case EntityEventPacket::USE_ITEM:
//Eating
$slot = $this->inventory->getItemInHand();
if ($slot->canBeConsumed()) {
$ev = new PlayerItemConsumeEvent($this, $slot);
if (!$slot->canBeConsumedBy($this)) {
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
if (!$ev->isCancelled()) {
$slot->onConsume($this);
} else {
$this->inventory->sendContents($this);
示例4: handleDataPacket
//.........这里部分代码省略.........
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if ($cancelled) {
$ev->setCancelled();
}
$target->attack($ev->getFinalDamage(), $ev);
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($this->isSurvival()) {
if ($item->isTool()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
} else {
$this->inventory->setItemInHand($item);
}
}
$this->exhaust(0.3, PlayerExhaustEvent::CAUSE_ATTACK);
}
}
break;
default:
break;
//TODO: handle other actions
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
break;
case ProtocolInfo::SET_HEALTH_PACKET:
//Not used
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
$this->craftingType = self::CRAFTING_SMALL;
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
//TODO: check if this should be true
switch ($packet->event) {
case EntityEventPacket::USE_ITEM:
//Eating
$slot = $this->inventory->getItemInHand();
if ($slot->canBeConsumed()) {
$ev = new PlayerItemConsumeEvent($this, $slot);
if (!$slot->canBeConsumedBy($this)) {
$ev->setCancelled();
}
$this->server->getPluginManager()->callEvent($ev);
if (!$ev->isCancelled()) {
$slot->onConsume($this);
} else {
$this->inventory->sendContents($this);
示例5: handleDataPacket
//.........这里部分代码省略.........
$armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
$points = 0;
foreach ($target->getInventory()->getArmorContents() as $index => $i) {
if (isset($armorValues[$i->getId()])) {
$points += $armorValues[$i->getId()];
}
}
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if ($cancelled) {
$ev->setCancelled();
}
$target->attack($ev->getFinalDamage(), $ev);
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($item->isTool() and $this->isSurvival()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1), $this);
} else {
$this->inventory->setItemInHand($item, $this);
}
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or $this->dead === true) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
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;
$this->setDataFlag(self::DATA_FLAGS, self::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 = $this->inventory->getItemInHand();
if ($this->getHealth() < $this->getMaxHealth() 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 = $this->getId();
$pk->event = 9;
示例6: handleDataPacket
//.........这里部分代码省略.........
if ($this->isSurvival()) {
$ev->createThornsDamage();
if ($ev->getThornsDamage() > 0) {
$thornsEvent = new EntityDamageByEntityEvent($target, $this, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $ev->getThornsDamage(), 0);
if (!$thornsEvent->isCancelled()) {
if ($this->attack($thornsEvent->getFinalDamage(), $thornsEvent) === true) {
$thornsEvent->useArmors();
$ev->setThornsArmorUse();
}
}
}
}
$ev->useArmors();
}
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($item->isTool() and $this->isSurvival()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
} else {
$this->inventory->setItemInHand($item);
}
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
break;
case ProtocolInfo::SET_HEALTH_PACKET:
//Not used
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
$this->craftingType = 0;
$this->setDataFlag(self::DATA_FLAGS, self::DATA_FLAG_ACTION, false);
//TODO: check if this should be true
switch ($packet->event) {
case 9:
//Eating
$this->consumeHeldItem();
break;
}
break;
case ProtocolInfo::DROP_ITEM_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
if (!$this->inventory->contains($packet->item) or $this->isCreative() and $this->server->limitedCreative) {
$this->inventory->sendContents($this);
break;
示例7: handleDataPacket
//.........这里部分代码省略.........
$armorValues = [Item::LEATHER_CAP => 1, Item::LEATHER_TUNIC => 3, Item::LEATHER_PANTS => 2, Item::LEATHER_BOOTS => 1, Item::CHAIN_HELMET => 1, Item::CHAIN_CHESTPLATE => 5, Item::CHAIN_LEGGINGS => 4, Item::CHAIN_BOOTS => 1, Item::GOLD_HELMET => 1, Item::GOLD_CHESTPLATE => 5, Item::GOLD_LEGGINGS => 3, Item::GOLD_BOOTS => 1, Item::IRON_HELMET => 2, Item::IRON_CHESTPLATE => 6, Item::IRON_LEGGINGS => 5, Item::IRON_BOOTS => 2, Item::DIAMOND_HELMET => 3, Item::DIAMOND_CHESTPLATE => 8, Item::DIAMOND_LEGGINGS => 6, Item::DIAMOND_BOOTS => 3];
$points = 0;
foreach ($target->getInventory()->getArmorContents() as $index => $i) {
if (isset($armorValues[$i->getId()])) {
$points += $armorValues[$i->getId()];
}
}
$damage[EntityDamageEvent::MODIFIER_ARMOR] = -floor($damage[EntityDamageEvent::MODIFIER_BASE] * $points * 0.04);
}
$ev = new EntityDamageByEntityEvent($this, $target, EntityDamageEvent::CAUSE_ENTITY_ATTACK, $damage);
if ($cancelled) {
$ev->setCancelled();
}
$target->attack($ev->getFinalDamage(), $ev);
if ($ev->isCancelled()) {
if ($item->isTool() and $this->isSurvival()) {
$this->inventory->sendContents($this);
}
break;
}
if ($item->isTool() and $this->isSurvival()) {
if ($item->useOn($target) and $item->getDamage() >= $item->getMaxDurability()) {
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 1));
} else {
$this->inventory->setItemInHand($item);
}
}
}
break;
case ProtocolInfo::ANIMATE_PACKET:
if ($this->spawned === false or !$this->isAlive()) {
break;
}
$this->server->getPluginManager()->callEvent($ev = new PlayerAnimationEvent($this, $packet->action));
if ($ev->isCancelled()) {
break;
}
$pk = new AnimatePacket();
$pk->eid = $this->getId();
$pk->action = $ev->getAnimationType();
Server::broadcastPacket($this->getViewers(), $pk);
break;
case ProtocolInfo::SET_HEALTH_PACKET:
//Not used
break;
case ProtocolInfo::ENTITY_EVENT_PACKET:
if ($this->spawned === false or $this->blocked === true or !$this->isAlive()) {
break;
}
$this->craftingType = 0;
$this->setDataFlag(self::DATA_FLAGS, self::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 => 5, Item::COOKED_SALMON => 6, Item::RAW_FISH => 2, Item::RAW_SALMON => 2, Item::CLOWN_FISH => 1, Item::PUFFER_FISH => 1];
$slot = $this->inventory->getItemInHand();
if ($this->getHealth() < $this->getMaxHealth() 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 = $this->getId();
$pk->event = EntityEventPacket::USE_ITEM;