当前位置: 首页>>代码示例>>PHP>>正文


PHP PlayerDeathEvent::getDrops方法代码示例

本文整理汇总了PHP中pocketmine\event\player\PlayerDeathEvent::getDrops方法的典型用法代码示例。如果您正苦于以下问题:PHP PlayerDeathEvent::getDrops方法的具体用法?PHP PlayerDeathEvent::getDrops怎么用?PHP PlayerDeathEvent::getDrops使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pocketmine\event\player\PlayerDeathEvent的用法示例。


在下文中一共展示了PlayerDeathEvent::getDrops方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: kill


//.........这里部分代码省略.........
                 } else {
                     $params[] = "Unknown";
                 }
             }
             break;
         case EntityDamageEvent::CAUSE_PROJECTILE:
             if ($cause instanceof EntityDamageByEntityEvent) {
                 $e = $cause->getDamager();
                 if ($e instanceof Player) {
                     $message = "death.attack.arrow";
                     $params[] = $e->getDisplayName();
                 } elseif ($e instanceof Living) {
                     $message = "death.attack.arrow";
                     $params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
                     break;
                 } else {
                     $params[] = "Unknown";
                 }
             }
             break;
         case EntityDamageEvent::CAUSE_SUICIDE:
             $message = "death.attack.generic";
             break;
         case EntityDamageEvent::CAUSE_VOID:
             $message = "death.attack.outOfWorld";
             break;
         case EntityDamageEvent::CAUSE_FALL:
             if ($cause instanceof EntityDamageEvent) {
                 if ($cause->getFinalDamage() > 2) {
                     $message = "death.fell.accident.generic";
                     break;
                 }
             }
             $message = "death.attack.fall";
             break;
         case EntityDamageEvent::CAUSE_SUFFOCATION:
             $message = "death.attack.inWall";
             break;
         case EntityDamageEvent::CAUSE_LAVA:
             $message = "death.attack.lava";
             break;
         case EntityDamageEvent::CAUSE_FIRE:
             $message = "death.attack.onFire";
             break;
         case EntityDamageEvent::CAUSE_FIRE_TICK:
             $message = "death.attack.inFire";
             break;
         case EntityDamageEvent::CAUSE_DROWNING:
             $message = "death.attack.drown";
             break;
         case EntityDamageEvent::CAUSE_CONTACT:
             if ($cause instanceof EntityDamageByBlockEvent) {
                 if ($cause->getDamager()->getId() === Block::CACTUS) {
                     $message = "death.attack.cactus";
                 }
             }
             break;
         case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
         case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
             if ($cause instanceof EntityDamageByEntityEvent) {
                 $e = $cause->getDamager();
                 if ($e instanceof Player) {
                     $message = "death.attack.explosion.player";
                     $params[] = $e->getDisplayName();
                 } elseif ($e instanceof Living) {
                     $message = "death.attack.explosion.player";
                     $params[] = $e->getNameTag() !== "" ? $e->getNameTag() : $e->getName();
                     break;
                 }
             } else {
                 $message = "death.attack.explosion";
             }
             break;
         case EntityDamageEvent::CAUSE_MAGIC:
             $message = "death.attack.magic";
             break;
         case EntityDamageEvent::CAUSE_CUSTOM:
             break;
         default:
     }
     Entity::kill();
     $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), new TranslationContainer($message, $params)));
     if (!$ev->getKeepInventory()) {
         foreach ($ev->getDrops() as $item) {
             $this->level->dropItem($this, $item);
         }
         if ($this->inventory !== null) {
             $this->inventory->clearAll();
         }
     }
     if ($ev->getDeathMessage() != "") {
         $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
     }
     $pk = new RespawnPacket();
     $pos = $this->getSpawn();
     $pk->x = $pos->x;
     $pk->y = $pos->y;
     $pk->z = $pos->z;
     $this->dataPacket($pk);
 }
开发者ID:NewDelion,项目名称:PocketMine-0.13.x,代码行数:101,代码来源:Player.php

示例2: onDeath

 public function onDeath(PlayerDeathEvent $event)
 {
     $player = $event->getEntity();
     if (isset(FlameThrower::$tasks[$player->getName()])) {
         FlameThrower::$tasks[$player->getName()]->getHandler()->cancel();
     }
     if ($this->status === self::STAT_GAME_IN_PROGRESS) {
         $items = $event->getDrops();
         foreach ($items as $key => $item) {
             if ($item->getId() !== self::GUN_ID) {
                 unset($items[$key]);
             }
         }
         $event->setDrops($items);
         $cause = $player->getLastDamageCause();
         if ($cause !== null && $cause->getCause() == EntityDamageEvent::CAUSE_FALL) {
             if ($this->players[$player->getName()][2] === self::TEAM_BLUE) {
                 $playerColor = TextFormat::BLUE;
                 $damagerColor = TextFormat::RED;
                 $this->score[self::TEAM_RED]++;
             } else {
                 $playerColor = TextFormat::RED;
                 $damagerColor = TextFormat::BLUE;
                 $this->score[self::TEAM_BLUE]++;
             }
             $firstKill = "";
             if ($this->score[self::TEAM_BLUE] + $this->score[self::TEAM_RED] <= 1) {
                 $firstKill = TextFormat::YELLOW . "FIRST BLOOD\n" . TextFormat::WHITE;
             }
             $this->broadcastPopup($firstKill . $playerColor . $player->getName() . $damagerColor . " SUICIDED");
         }
         if (!$cause instanceof EntityDamageByEntityEvent) {
             return;
         }
         if ($cause !== null and $cause->getCause() === 15) {
             $damager = $cause->getDamager();
             if ($damager instanceof Player) {
                 if ($this->players[$damager->getName()][2] === self::TEAM_BLUE) {
                     $damagerColor = TextFormat::BLUE;
                     $playerColor = TextFormat::RED;
                     $this->score[self::TEAM_BLUE]++;
                 } else {
                     $damagerColor = TextFormat::RED;
                     $playerColor = TextFormat::BLUE;
                     $this->score[self::TEAM_RED]++;
                 }
                 $firstKill = "";
                 if ($this->score[self::TEAM_BLUE] + $this->score[self::TEAM_RED] <= 1) {
                     $firstKill = TextFormat::YELLOW . "FIRST BLOOD\n" . TextFormat::WHITE;
                 }
                 $this->broadcastPopup($firstKill . $damagerColor . $damager->getName() . TextFormat::WHITE . " -> " . $playerColor . $player->getName());
                 ++$this->killDeath[0][$damager->getName()];
                 ++$this->killDeath[1][$player->getName()];
                 $this->level[$damager->getName()] += $damager->getHealth() * 5;
                 $level = floor($this->level[$damager->getName()] / 10000);
                 $damager->setNameTag("Lv." . $level . $damagerColor . $damager->getName());
             }
         } elseif ($cause !== null and $cause->getCause() === 16) {
             $damager = $cause->getDamager();
             if ($damager instanceof Player) {
                 if ($this->players[$damager->getName()][2] === self::TEAM_BLUE) {
                     $damagerColor = TextFormat::BLUE;
                     $playerColor = TextFormat::RED;
                     $this->score[self::TEAM_BLUE]++;
                 } else {
                     $damagerColor = TextFormat::RED;
                     $playerColor = TextFormat::BLUE;
                     $this->score[self::TEAM_RED]++;
                 }
                 $firstKill = "";
                 if ($this->score[self::TEAM_BLUE] + $this->score[self::TEAM_RED] <= 1) {
                     $firstKill = TextFormat::YELLOW . "FIRST BLOOD\n" . TextFormat::WHITE;
                 }
                 $this->broadcastPopup($firstKill . $damagerColor . $damager->getName() . TextFormat::WHITE . " -O-> " . $playerColor . $player->getName());
                 ++$this->killDeath[0][$damager->getName()];
                 ++$this->killDeath[1][$player->getName()];
                 $this->level[$damager->getName()] += $damager->getHealth() * 5;
                 $level = floor($this->level[$damager->getName()] / 10000);
                 $damager->setNameTag("Lv." . $level . $damagerColor . $damager->getName());
             }
         }
         $event->setDeathMessage("");
     }
 }
开发者ID:EmreTr1,项目名称:MineCombat,代码行数:84,代码来源:MineCombat.php

示例3: kill

 public function kill()
 {
     if ($this->dead === true or $this->spawned === false) {
         return;
     }
     $message = $this->getName() . " died";
     $cause = $this->getLastDamageCause();
     $ev = null;
     if ($cause instanceof EntityDamageEvent) {
         $ev = $cause;
         $cause = $ev->getCause();
     }
     switch ($cause) {
         case EntityDamageEvent::CAUSE_ENTITY_ATTACK:
             if ($ev instanceof EntityDamageByEntityEvent) {
                 $e = $ev->getDamager();
                 if ($e instanceof Player) {
                     $message = $this->getName() . " was killed by " . $e->getName();
                     break;
                 } elseif ($e instanceof Living) {
                     $message = $this->getName() . " was slain by " . $e->getName();
                     break;
                 }
             }
             $message = $this->getName() . " was killed";
             break;
         case EntityDamageEvent::CAUSE_PROJECTILE:
             if ($ev instanceof EntityDamageByEntityEvent) {
                 $e = $ev->getDamager();
                 if ($e instanceof Living) {
                     $message = $this->getName() . " was shot by " . $e->getName();
                     break;
                 }
             }
             $message = $this->getName() . " was shot by arrow";
             break;
         case EntityDamageEvent::CAUSE_SUICIDE:
             $message = $this->getName() . " died";
             break;
         case EntityDamageEvent::CAUSE_VOID:
             $message = $this->getName() . " fell out of the world";
             break;
         case EntityDamageEvent::CAUSE_FALL:
             $message = $this->getName() . " fell from a high place";
             break;
         case EntityDamageEvent::CAUSE_SUFFOCATION:
             $message = $this->getName() . " suffocated in a wall";
             break;
         case EntityDamageEvent::CAUSE_LAVA:
             $message = $this->getName() . " tried to swim in lava";
             break;
         case EntityDamageEvent::CAUSE_FIRE:
             $message = $this->getName() . " went up in flames";
             break;
         case EntityDamageEvent::CAUSE_FIRE_TICK:
             $message = $this->getName() . " burned to death";
             break;
         case EntityDamageEvent::CAUSE_DROWNING:
             $message = $this->getName() . " drowned";
             break;
         case EntityDamageEvent::CAUSE_CONTACT:
             $message = $this->getName() . " was pricked to death";
             break;
         case EntityDamageEvent::CAUSE_BLOCK_EXPLOSION:
         case EntityDamageEvent::CAUSE_ENTITY_EXPLOSION:
             $message = $this->getName() . " blew up";
             break;
         case EntityDamageEvent::CAUSE_MAGIC:
             $message = $this->getName() . " was slain by magic";
             break;
         case EntityDamageEvent::CAUSE_CUSTOM:
             break;
         default:
     }
     if ($this->dead) {
         return;
     }
     Entity::kill();
     $this->server->getPluginManager()->callEvent($ev = new PlayerDeathEvent($this, $this->getDrops(), $message));
     if (!$ev->getKeepInventory()) {
         foreach ($ev->getDrops() as $item) {
             $this->level->dropItem($this, $item);
         }
         if ($this->inventory !== null) {
             $this->inventory->clearAll();
         }
     }
     if ($ev->getDeathMessage() != "") {
         $this->server->broadcast($ev->getDeathMessage(), Server::BROADCAST_CHANNEL_USERS);
     }
     if ($this->server->isHardcore()) {
         $this->setBanned(true);
     } else {
         $pk = new RespawnPacket();
         $pos = $this->getSpawn();
         $pk->x = $pos->x;
         $pk->y = $pos->y;
         $pk->z = $pos->z;
         $this->dataPacket($pk);
     }
//.........这里部分代码省略.........
开发者ID:ZenaGamingsky,项目名称:Steadfast2,代码行数:101,代码来源:Player.php

示例4: onPlayerDeath

 public function onPlayerDeath(PlayerDeathEvent $event)
 {
     if (!$this->isValidPlayer($event->getEntity())) {
         return;
     }
     $event->getEntity()->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
     $rpgPlayer = $this->players[$event->getEntity()->getName()];
     $rpgPlayer->setHealth(1);
     $rpgPlayer->mana = 0;
     $rpgPlayer->getStatus()->setXp($rpgPlayer->getStatus()->getXp() * (4 / 5));
     $drops = [];
     $this->respawnAdd[$event->getEntity()->getName()] = [];
     foreach ($event->getDrops() as $item) {
         if ($rpgPlayer->getSkillByItem($item) === null) {
             $drops[] = $item;
         } else {
             $this->respawnAdd[$event->getEntity()->getName()][] = $item;
         }
     }
     $event->setDrops($drops);
 }
开发者ID:HelloWorld017,项目名称:ToAruPG,代码行数:21,代码来源:ToAruPG.php


注:本文中的pocketmine\event\player\PlayerDeathEvent::getDrops方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。