作者:somenabzofturtle
项目:Small-PM-Plugin
public function onDamage(EntityDamageEvent $event)
{
$cause = $event->getCause();
if ($cause === EntityDamageEvent::CAUSE_BLOCK_EXPLOSION || $cause === EntityDamageEvent::CAUSE_ENTITY_EXPLOSION) {
$event->setCancelled();
}
}
作者:RedEnde
项目:KillMone
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);
}
}
作者:TBNRFrags246
项目:EssentialsP
/**
* @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;
}
作者:ZencraftYouTub
项目:EssentialsP
/**
* @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;
}
作者:TylerGame
项目:PocketMine-M
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
}
作者:DWW
项目:pocketmine-plugin
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();
}
作者:vellry
项目:ClearSk
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
}
作者:EnderKenj
项目:HealthTa
public function onEntityDamage(EntityDamageEvent $event)
{
$entity = $event->getEntity();
if ($entity instanceof Player) {
$player = $entity->getPlayer();
$this->renderNameTag($player);
}
}
作者:nesgohoo
项目:PMMP-Plugin
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();
}
}
}
作者:xHF
项目:SwordEffect
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));
}
}
}
作者:CaptainKenji1
项目:ArrowHi
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]);
}
}
作者:100henrik10
项目:Minecraft-Pocket-Editio
public function onEntityDamageByEntity(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
$victim = $event->getEntity();
$attacker = $event->getDamager();
$this->debug->onDebug('Damage denied');
$event->setCancelled(true);
}
}
作者:Ad500
项目:SafeFl
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);
}
}
}
作者:kdani
项目:CombatLogge
/**
* @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);
}
}
}
}
作者:HeroGaming
项目:PocketMine-MP-Plugin
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);
}
}
}
作者:xHF
项目:ArrowPlugi
public function onDamage(EntityDamageEvent $ev)
{
/***
* http://docs.pocketmine.net/d6/d5c/_entity_damage_by_entity_event_8php_source.html
* public function getDamager(){
* return $this->damager;
*/
$e = $ev->getEntity();
if ($e instanceof Player && $ev->getFinalDamage() - $e->getHealth() <= 0) {
$e->getPlayer()->getInventory()->addItem(Item::get(262, 0, 1));
}
}
作者:Pocket-GA
项目:PocketMine-MP-Plugin
public function onDamage(EntityDamageEvent $event)
{
$victim = $event->getEntity();
if ($victim instanceof Player) {
if (!$event->isCancelled()) {
if ($this->plugin->getFlyingSession($victim)->getFlying()) {
$this->plugin->getFlyingSession($victim)->setFlying(false);
$victim->sendMessage(TF::GOLD . "You are no longer in fly mode!");
}
}
}
}
作者:EmreTr
项目:rt
public function onDamage(EntityDamageEvent $event)
{
if ($event instanceof EntityDamageByEntityEvent) {
if ($this->purgeStarted) {
return;
}
if ($event->getEntity() instanceof Player and $event->getDamager() instanceof Player) {
// TODO 제한시간 출력
$event->setCancelled();
}
}
}
作者:jjplayin
项目:HotBloc
public function onEntityDamage(EntityDamageEvent $event)
{
$entity = $event->getEntity();
$world = $entity->getLevel();
$block = $world->getBlock($entity->floor()->subtract(0, 1));
if ($world->getName() == $this->getHotBlock()->getConfig()->get("world")) {
switch ($block->getId()) {
case Block::PLANKS:
$event->setCancelled(true);
break;
}
}
}
作者:Skull3
项目:MineBloc
public function onEntityDamage(EntityDamageEvent $event)
{
if ($p = $event->getEntity() instanceof Player && $event instanceof EntityDamageByEntityEvent && ($d = $event->getDamager() instanceof Player)) {
$l = $d->getLocation();
if (!isset($this->move[$n = $d->getName()])) {
$this->move[$n] = $l;
}
$m = $this->move[$n];
if ($p->distance($d) > 5 || $m->x == $l->x && $m->y == $l->y && $m->z == $l->z && $m->getYaw() == $l->getYaw() && $m->getPitch() == $l->getPitch()) {
$event->setCancelled(false);
}
}
}