Search in sources :

Example 86 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project BentoBox by BentoBoxWorld.

the class InvincibleVisitorsListenerTest method testOnVisitorGetDamageNotVisitor.

@Test
public void testOnVisitorGetDamageNotVisitor() {
    EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
    when(im.userIsOnIsland(any(), any())).thenReturn(true);
    listener.onVisitorGetDamage(e);
    assertFalse(e.isCancelled());
}
Also used : EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 87 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project BentoBox by BentoBoxWorld.

the class InvincibleVisitorsListenerTest method testOnVisitorGetDamageNotInWorld.

@Test
public void testOnVisitorGetDamageNotInWorld() {
    when(iwm.inWorld(any(World.class))).thenReturn(false);
    when(iwm.inWorld(any(Location.class))).thenReturn(false);
    EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
    listener.onVisitorGetDamage(e);
    assertFalse(e.isCancelled());
}
Also used : World(org.bukkit.World) Location(org.bukkit.Location) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 88 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project BentoBox by BentoBoxWorld.

the class InvincibleVisitorsListenerTest method testOnVisitorGetDamageNotVoid.

@Test
public void testOnVisitorGetDamageNotVoid() {
    EntityDamageEvent e = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.CRAMMING, 0D);
    listener.onVisitorGetDamage(e);
    assertTrue(e.isCancelled());
    verify(player, never()).setGameMode(eq(GameMode.SPECTATOR));
}
Also used : EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 89 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project MiniGameWorld by MiniGameWorlds.

the class MiniGame method processEventWhileWaiting.

/**
 * Processes events while players are waiting for start
 *
 * @param event Passed Event
 */
private void processEventWhileWaiting(Event event) {
    if (event instanceof EntityDamageEvent) {
        // prevent player hurts
        EntityDamageEvent e = (EntityDamageEvent) event;
        e.setCancelled(true);
    } else if (event instanceof FoodLevelChangeEvent) {
        // prevent player hunger changes
        FoodLevelChangeEvent e = (FoodLevelChangeEvent) event;
        e.setCancelled(true);
    }
}
Also used : FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Example 90 with EntityDamageEvent

use of org.bukkit.event.entity.EntityDamageEvent in project WindSpigot by Wind-Development.

the class KillCommand method execute.

@Override
public boolean execute(CommandSender sender, String currentAlias, String[] args) {
    if (!testPermission(sender))
        return true;
    if (sender instanceof Player) {
        Player player = (Player) sender;
        EntityDamageEvent ede = new EntityDamageEvent(player, EntityDamageEvent.DamageCause.SUICIDE, 1000);
        Bukkit.getPluginManager().callEvent(ede);
        if (ede.isCancelled())
            return true;
        ede.getEntity().setLastDamageCause(ede);
        player.setHealth(0);
        sender.sendMessage("Ouch. That look like it hurt.");
    } else {
        sender.sendMessage("You can only perform this command as a player");
    }
    return true;
}
Also used : Player(org.bukkit.entity.Player) EntityDamageEvent(org.bukkit.event.entity.EntityDamageEvent)

Aggregations

EntityDamageEvent (org.bukkit.event.entity.EntityDamageEvent)109 Player (org.bukkit.entity.Player)43 EntityDamageByEntityEvent (org.bukkit.event.entity.EntityDamageByEntityEvent)40 Entity (org.bukkit.entity.Entity)30 LivingEntity (org.bukkit.entity.LivingEntity)25 EventHandler (org.bukkit.event.EventHandler)24 Projectile (org.bukkit.entity.Projectile)15 ItemStack (org.bukkit.inventory.ItemStack)13 Test (org.junit.Test)11 Function (com.google.common.base.Function)8 ProjectileSource (org.bukkit.projectiles.ProjectileSource)8 Location (org.bukkit.Location)7 EntityDamageByBlockEvent (org.bukkit.event.entity.EntityDamageByBlockEvent)7 DamageCause (org.bukkit.event.entity.EntityDamageEvent.DamageCause)7 EntityDeathEvent (org.bukkit.event.entity.EntityDeathEvent)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 ArrayList (java.util.ArrayList)6 List (java.util.List)6 World (org.bukkit.World)6 Block (org.bukkit.block.Block)6