本文整理汇总了PHP中pocketmine\event\entity\EntityDamageEvent类的典型用法代码示例。如果您正苦于以下问题:PHP EntityDamageEvent类的具体用法?PHP EntityDamageEvent怎么用?PHP EntityDamageEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityDamageEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onDamage
public function onDamage(EntityDamageEvent $event)
{
$cause = $event->getCause();
if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
$event->setCancelled();
}
}
示例2: onDeath
public function onDeath(EntityDamageEvent $event)
{
$damage = $event->getDamage();
$health = $event->getDamager()->getHealth();
if ($health <= $damage) {
$player = $event->getDamager();
$money = $this->getConfig()->get("money");
$player->sendMessage("You've Earned 8 Coins");
$this->addMoney($player->getName(), $money);
}
}
示例3: execute
/**
* @param CommandSender $sender
* @param string $alias
* @param array $args
* @return bool
*/
public function execute(CommandSender $sender, $alias, array $args)
{
if (!$this->testPermission($sender)) {
return false;
}
if (!$sender instanceof Player && count($args) !== 1) {
$this->sendUsage($sender, $alias);
return false;
}
$player = $sender;
if (isset($args[0])) {
if (!$sender->hasPermission("essentials.kill.other")) {
$sender->sendMessage(TextFormat::RED . $this->getPermissionMessage());
return false;
}
if (!($player = $this->getAPI()->getPlayer($args[0])) instanceof Player) {
$sender->sendMessage(TextFormat::RED . "[Error] Player not found");
return false;
}
}
if ($this->getAPI()->isGod($player)) {
$sender->sendMessage(TextFormat::RED . $args[0] . " can't be killed!");
return false;
}
$sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, $player->getHealth()));
if ($ev->isCancelled()) {
return true;
}
$player->setLastDamageCause($ev);
$player->setHealth(0);
$player->sendMessage("Ouch. That look like it hurt.");
return true;
}
示例4: execute
/**
* @param CommandSender $sender
* @param string $alias
* @param array $args
* @return bool
*/
public function execute(CommandSender $sender, $alias, array $args)
{
if (!$this->testPermission($sender)) {
return false;
}
if (count($args) !== 1) {
$sender->sendMessage($sender instanceof Player ? $this->getUsage() : $this->getConsoleUsage());
return false;
}
$player = $this->getPlugin()->getPlayer($args[0]);
if (!$player instanceof Player) {
$sender->sendMessage(TextFormat::RED . "[Error] Player not found");
return false;
}
if ($this->getPlugin()->isGod($player)) {
$sender->sendMessage(TextFormat::RED . "You can't kill " . $args[0]);
return false;
}
$sender->getServer()->getPluginManager()->callEvent($ev = new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, $player->getHealth()));
if ($ev->isCancelled()) {
return true;
}
$player->setLastDamageCause($ev);
$player->setHealth(0);
$player->sendMessage("Ouch. That look like it hurt.");
return true;
}
示例5: attack
public function attack($damage, EntityDamageEvent $source)
{
if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
$lastCause = $this->getLastDamageCause();
if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
$source->setCancelled();
}
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
}
if ($source instanceof EntityDamageByEntityEvent) {
$e = $source->getDamager();
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$yaw = atan2($deltaX, $deltaZ);
$this->knockBack($e, $damage, sin($yaw), cos($yaw), $source->getKnockBack());
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? 3 : 2;
//Ouch!
Server::broadcastPacket($this->hasSpawned, $pk->setChannel(Network::CHANNEL_WORLD_EVENTS));
$this->attackTime = 10;
//0.5 seconds cooldown
}
示例6: onPvP
public function onPvP(EntityDamageEvent $ev)
{
if ($ev->isCancelled()) {
return;
}
if (!$ev instanceof EntityDamageByEntityEvent) {
return;
}
if (!(($pl = $ev->getEntity()) instanceof Player && $ev->getDamager() instanceof Player)) {
return;
}
$world = $pl->getLevel()->getName();
if (!isset($this->wcfg[$world])) {
return;
}
if ($this->wcfg[$world] !== false) {
$sp = $pl->getLevel()->getSpawnLocation();
$dist = $sp->distance($pl);
if ($dist > $this->owner->getServer()->getSpawnRadius()) {
return;
}
}
$this->owner->msg($ev->getDamager(), mc::_("You are not allowed to do that here"));
$ev->setCancelled();
}
示例7: attack
public function attack($damage, EntityDamageEvent $source)
{
if ($this->attackTime > 0 or $this->noDamageTicks > 0) {
$lastCause = $this->getLastDamageCause();
if ($lastCause !== null and $lastCause->getDamage() >= $damage) {
$source->setCancelled();
}
}
parent::attack($damage, $source);
if ($source->isCancelled()) {
return;
}
if ($source instanceof EntityDamageByEntityEvent) {
$e = $source->getDamager();
if ($source instanceof EntityDamageByChildEntityEvent) {
$e = $source->getChild();
}
if ($e->isOnFire() > 0) {
$this->setOnFire(2 * $this->server->getDifficulty());
}
$deltaX = $this->x - $e->x;
$deltaZ = $this->z - $e->z;
$this->knockBack($e, $damage, $deltaX, $deltaZ, $source->getKnockBack());
}
$pk = new EntityEventPacket();
$pk->eid = $this->getId();
$pk->event = $this->getHealth() <= 0 ? EntityEventPacket::DEATH_ANIMATION : EntityEventPacket::HURT_ANIMATION;
// Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
$this->attackTime = 10;
//0.5 seconds cooldown
}
示例8: onEntityDamage
public function onEntityDamage(EntityDamageEvent $event)
{
$entity = $event->getEntity();
if ($entity instanceof Player) {
$player = $entity->getPlayer();
$this->renderNameTag($player);
}
}
示例9: onAttack
public function onAttack(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent or $event instanceof EntityDamageByChildEntityEvent) {
if ($event->getDamager() instanceof Player and $event->getEntity() instanceof Player) {
$this->attackQueue[$event->getEntity()->getName()] = $event->getDamager()->getName();
}
}
}
示例10: onHurt
public function onHurt(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getDamager()->getInventory()->getItemInHand()->getId() === 276) {
$event->getEntity()->addEffect(Effect::getEffect($this->getConfig()->get("DiamondSwordEffect"))->setAmplifier($this->getConfig()->get("DiamondSwordAmp"))->setDuration($this->getConfig()->get("DiamondSwordTime"))->setVisible(false));
}
}
}
示例11: onHit
public function onHit(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByChildEntityEvent) {
$target = $event->getEntity();
$player = $event->getDamager();
$event->getDamager()->sendTip("§aYou hit§c " . $target->getName());
$player->getLevel()->addSound(new AnvilFallSound($player), [$player]);
}
}
示例12: onEntityDamageByEntity
public function onEntityDamageByEntity(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
$victim = $event->getEntity();
$attacker = $event->getDamager();
$this->debug->onDebug('Damage denied');
$event->setCancelled(true);
}
}
示例13: onEntityDamage
public function onEntityDamage(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
$damager = $event->getDamager();
if ($damager instanceof Player && $this->isPlayer($damager)) {
$damager->sendTip(TextFormat::RED . "You cannot damage players while in fly mode!");
$event->setCancelled(true);
}
}
}
示例14: EntityDamageEvent
/**
* @param EnityDamageEvent $event
*
* @priority LOW
* @ignoreCancelled true
*/
public function EntityDamageEvent(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
if ($event->getDamager() instanceof Player) {
foreach (array($event->getDamager(), $event->getEntity()) as $players) {
$this->setTime($players);
}
}
}
}
示例15: onHurt
public function onHurt(EntityDamageEvent $event)
{
$player = $event->getEntity();
if ($player instanceof Player) {
if (!$player->haspermission("worldprotetor.player.hurt")) {
$event->setCancelled(true);
} else {
$event->setCancelled(false);
}
}
}