Enables dragon to be summoned using /summon command

https://github.com/BentoBoxWorld/BentoBox/issues/522
This commit is contained in:
tastybento 2019-02-11 19:11:48 -08:00
parent 179a71b548
commit 75c9f6fb2c
2 changed files with 0 additions and 116 deletions

View File

@ -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

View File

@ -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());
}
}