From 75c9f6fb2cf09078b009d84be5dccfeb67d021be Mon Sep 17 00:00:00 2001 From: tastybento Date: Mon, 11 Feb 2019 19:11:48 -0800 Subject: [PATCH] Enables dragon to be summoned using /summon command https://github.com/BentoBoxWorld/BentoBox/issues/522 --- .../bentobox/listeners/BlockEndDragon.java | 20 ---- .../listeners/BlockEndDragonTest.java | 96 ------------------- 2 files changed, 116 deletions(-) delete mode 100644 src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java diff --git a/src/main/java/world/bentobox/bentobox/listeners/BlockEndDragon.java b/src/main/java/world/bentobox/bentobox/listeners/BlockEndDragon.java index ec97c49f0..ef5ceceb7 100644 --- a/src/main/java/world/bentobox/bentobox/listeners/BlockEndDragon.java +++ b/src/main/java/world/bentobox/bentobox/listeners/BlockEndDragon.java @@ -2,13 +2,11 @@ package world.bentobox.bentobox.listeners; import org.bukkit.Material; import org.bukkit.World.Environment; -import org.bukkit.entity.EntityType; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; import org.bukkit.event.block.BlockBreakEvent; import org.bukkit.event.block.BlockPlaceEvent; -import org.bukkit.event.entity.CreatureSpawnEvent; import org.bukkit.event.world.ChunkLoadEvent; import world.bentobox.bentobox.BentoBox; @@ -23,24 +21,6 @@ public class BlockEndDragon implements Listener { this.plugin = plugin; } - /** - * This handles end dragon spawning prevention. Does not kill dragon because that generates random portal placement - * - * @param e - event - * @return true if dragon can spawn, false if not - */ - @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true) - public boolean onDragonSpawn(CreatureSpawnEvent e) { - if (!e.getEntityType().equals(EntityType.ENDER_DRAGON) || plugin.getIWM().isDragonSpawn(e.getEntity().getWorld())) { - return true; - } - e.getEntity().setHealth(0); - e.getEntity().remove(); - e.setCancelled(true); - return false; - } - - /** * This listener moves the end exit island high up in the sky * @param e - event diff --git a/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java b/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java deleted file mode 100644 index 634891d5a..000000000 --- a/src/test/java/world/bentobox/bentobox/listeners/BlockEndDragonTest.java +++ /dev/null @@ -1,96 +0,0 @@ -package world.bentobox.bentobox.listeners; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import org.bukkit.Bukkit; -import org.bukkit.entity.EntityType; -import org.bukkit.entity.LivingEntity; -import org.bukkit.event.entity.CreatureSpawnEvent; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mockito; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.managers.IslandWorldManager; -import world.bentobox.bentobox.util.Util; - -@RunWith(PowerMockRunner.class) -@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Util.class }) -public class BlockEndDragonTest { - - @Test - public void testBlockEndDragon() { - BentoBox plugin = mock(BentoBox.class); - assertNotNull(new BlockEndDragon(plugin)); - } - - @Test - public void testOnDragonSpawnWrongEntityOkayToSpawn() { - LivingEntity le = mock(LivingEntity.class); - when(le.getType()).thenReturn(EntityType.AREA_EFFECT_CLOUD); - CreatureSpawnEvent event = new CreatureSpawnEvent(le, null); - BentoBox plugin = mock(BentoBox.class); - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - // allow dragon spawn - when(iwm.isDragonSpawn(Mockito.any())).thenReturn(true); - BlockEndDragon bed = new BlockEndDragon(plugin); - assertTrue(bed.onDragonSpawn(event)); - assertFalse(event.isCancelled()); - } - - @Test - public void testOnDragonSpawnWrongEntityNoDragonSpawn() { - LivingEntity le = mock(LivingEntity.class); - when(le.getType()).thenReturn(EntityType.AREA_EFFECT_CLOUD); - CreatureSpawnEvent event = new CreatureSpawnEvent(le, null); - BentoBox plugin = mock(BentoBox.class); - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - // allow dragon spawn - when(iwm.isDragonSpawn(Mockito.any())).thenReturn(false); - BlockEndDragon bed = new BlockEndDragon(plugin); - assertTrue(bed.onDragonSpawn(event)); - assertFalse(event.isCancelled()); - } - - @Test - public void testOnDragonSpawnRightEntityOkayToSpawn() { - LivingEntity le = mock(LivingEntity.class); - when(le.getType()).thenReturn(EntityType.ENDER_DRAGON); - CreatureSpawnEvent event = new CreatureSpawnEvent(le, null); - BentoBox plugin = mock(BentoBox.class); - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - // allow dragon spawn - when(iwm.isDragonSpawn(Mockito.any())).thenReturn(true); - BlockEndDragon bed = new BlockEndDragon(plugin); - assertTrue(bed.onDragonSpawn(event)); - assertFalse(event.isCancelled()); - } - - @Test - public void testOnDragonSpawnRightEntityNotOkayToSpawn() { - LivingEntity le = mock(LivingEntity.class); - when(le.getType()).thenReturn(EntityType.ENDER_DRAGON); - CreatureSpawnEvent event = new CreatureSpawnEvent(le, null); - BentoBox plugin = mock(BentoBox.class); - IslandWorldManager iwm = mock(IslandWorldManager.class); - when(plugin.getIWM()).thenReturn(iwm); - // allow dragon spawn - when(iwm.isDragonSpawn(Mockito.any())).thenReturn(false); - BlockEndDragon bed = new BlockEndDragon(plugin); - assertFalse(bed.onDragonSpawn(event)); - Mockito.verify(le).remove(); - Mockito.verify(le).setHealth(0); - assertTrue(event.isCancelled()); - } - -}