Finished ItemFrameListener and test.

This commit is contained in:
tastybento 2018-07-21 21:48:22 -07:00
parent 984de1cd07
commit 944ab36488
3 changed files with 65 additions and 3 deletions

View File

@ -44,6 +44,7 @@ public class ItemFrameListener extends AbstractFlagListener {
} else { } else {
e.setCancelled(true); e.setCancelled(true);
} }
return;
} }
} }

View File

@ -23,6 +23,7 @@ import us.tastybento.bskyblock.listeners.flags.EndermanListener;
import us.tastybento.bskyblock.listeners.flags.EnterExitListener; import us.tastybento.bskyblock.listeners.flags.EnterExitListener;
import us.tastybento.bskyblock.listeners.flags.EntityInteractListener; import us.tastybento.bskyblock.listeners.flags.EntityInteractListener;
import us.tastybento.bskyblock.listeners.flags.FireListener; import us.tastybento.bskyblock.listeners.flags.FireListener;
import us.tastybento.bskyblock.listeners.flags.GeoLimitMobsListener;
import us.tastybento.bskyblock.listeners.flags.HurtingListener; import us.tastybento.bskyblock.listeners.flags.HurtingListener;
import us.tastybento.bskyblock.listeners.flags.InventoryListener; import us.tastybento.bskyblock.listeners.flags.InventoryListener;
import us.tastybento.bskyblock.listeners.flags.InvincibleVisitorsListener; import us.tastybento.bskyblock.listeners.flags.InvincibleVisitorsListener;
@ -190,6 +191,10 @@ public class Flags {
public static final Flag INVINCIBLE_VISITORS = new FlagBuilder().id("INVINCIBLE_VISITORS").icon(Material.DIAMOND_CHESTPLATE).type(Type.WORLD_SETTING) public static final Flag INVINCIBLE_VISITORS = new FlagBuilder().id("INVINCIBLE_VISITORS").icon(Material.DIAMOND_CHESTPLATE).type(Type.WORLD_SETTING)
.listener(ilv).onClick(ilv).subPanel(true).build(); .listener(ilv).onClick(ilv).subPanel(true).build();
private static GeoLimitMobsListener glm = new GeoLimitMobsListener();
static final Flag GEO_LIMIT_MOBS = new FlagBuilder().id("GEO_LIMIT_MOBS").icon(Material.CHAINMAIL_CHESTPLATE).type(Type.WORLD_SETTING)
.listener(glm).onClick(glm).subPanel(true).build();
public static final Flag REMOVE_MOBS = new FlagBuilder().id("REMOVE_MOBS").icon(Material.GLOWSTONE_DUST).type(Type.WORLD_SETTING) public static final Flag REMOVE_MOBS = new FlagBuilder().id("REMOVE_MOBS").icon(Material.GLOWSTONE_DUST).type(Type.WORLD_SETTING)
.listener(new RemoveMobsListener()).allowedByDefault(true).build(); .listener(new RemoveMobsListener()).allowedByDefault(true).build();

View File

@ -3,8 +3,8 @@
*/ */
package us.tastybento.bskyblock.listeners.flags; package us.tastybento.bskyblock.listeners.flags;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any; import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -22,10 +22,15 @@ import org.bukkit.Server;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.entity.Enderman; import org.bukkit.entity.Enderman;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Hanging;
import org.bukkit.entity.ItemFrame; import org.bukkit.entity.ItemFrame;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Projectile;
import org.bukkit.entity.Slime; import org.bukkit.entity.Slime;
import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.entity.EntityDamageEvent.DamageCause; import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
import org.bukkit.event.hanging.HangingBreakByEntityEvent;
import org.bukkit.inventory.ItemFactory; import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.SkullMeta; import org.bukkit.inventory.meta.SkullMeta;
import org.bukkit.material.MaterialData; import org.bukkit.material.MaterialData;
@ -151,17 +156,68 @@ public class ItemFrameListenerTest {
Entity entity = mock(ItemFrame.class); Entity entity = mock(ItemFrame.class);
DamageCause cause = DamageCause.ENTITY_ATTACK; DamageCause cause = DamageCause.ENTITY_ATTACK;
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(entity, enderman, cause , 0); EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, entity, cause , 0);
ifl.onItemFrameDamage(e); ifl.onItemFrameDamage(e);
assertTrue(e.isCancelled()); assertTrue(e.isCancelled());
} }
/**
* Test method for {@link us.tastybento.bskyblock.listeners.flags.ItemFrameListener#onItemFrameDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
*/
@Test
public void testNotItemFrame() {
ItemFrameListener ifl = new ItemFrameListener();
Entity entity = mock(Monster.class);
DamageCause cause = DamageCause.ENTITY_ATTACK;
@SuppressWarnings("deprecation")
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(enderman, entity, cause , 0);
ifl.onItemFrameDamage(e);
assertFalse(e.isCancelled());
}
/**
* Test method for {@link us.tastybento.bskyblock.listeners.flags.ItemFrameListener#onItemFrameDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
*/
@Test
public void testProjectile() {
ItemFrameListener ifl = new ItemFrameListener();
Entity entity = mock(ItemFrame.class);
DamageCause cause = DamageCause.ENTITY_ATTACK;
Projectile p = mock(Projectile.class);
when(p.getShooter()).thenReturn(enderman);
@SuppressWarnings("deprecation")
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause , 0);
ifl.onItemFrameDamage(e);
assertTrue(e.isCancelled());
}
/**
* Test method for {@link us.tastybento.bskyblock.listeners.flags.ItemFrameListener#onItemFrameDamage(org.bukkit.event.entity.EntityDamageByEntityEvent)}.
*/
@Test
public void testPlayerProjectile() {
ItemFrameListener ifl = new ItemFrameListener();
Entity entity = mock(ItemFrame.class);
DamageCause cause = DamageCause.ENTITY_ATTACK;
Projectile p = mock(Projectile.class);
Player player = mock(Player.class);
when(p.getShooter()).thenReturn(player);
@SuppressWarnings("deprecation")
EntityDamageByEntityEvent e = new EntityDamageByEntityEvent(p, entity, cause , 0);
ifl.onItemFrameDamage(e);
assertFalse(e.isCancelled());
}
/** /**
* Test method for {@link us.tastybento.bskyblock.listeners.flags.ItemFrameListener#onItemFrameDamage(org.bukkit.event.hanging.HangingBreakByEntityEvent)}. * Test method for {@link us.tastybento.bskyblock.listeners.flags.ItemFrameListener#onItemFrameDamage(org.bukkit.event.hanging.HangingBreakByEntityEvent)}.
*/ */
@Test @Test
public void testOnItemFrameDamageHangingBreakByEntityEvent() { public void testOnItemFrameDamageHangingBreakByEntityEvent() {
fail("Not yet implemented"); // TODO ItemFrameListener ifl = new ItemFrameListener();
Hanging hanging = mock(ItemFrame.class);
HangingBreakByEntityEvent e = new HangingBreakByEntityEvent(hanging, enderman);
ifl.onItemFrameDamage(e);
assertTrue(e.isCancelled());
} }
} }