use of io.papermc.lib.environments.CraftBukkitEnvironment in project BentoBox by BentoBoxWorld.
the class IslandsManagerTest method setUp.
/**
* @throws java.lang.Exception
*/
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
// Clear any lingering database
tearDown();
// Set up plugin
plugin = mock(BentoBox.class);
Whitebox.setInternalState(BentoBox.class, "instance", plugin);
// island world mgr
when(world.getName()).thenReturn("world");
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
when(plugin.getIWM()).thenReturn(iwm);
// Chunk deletion manager
when(plugin.getIslandChunkDeletionManager()).thenReturn(chunkDeletionManager);
// Settings
Settings s = mock(Settings.class);
when(plugin.getSettings()).thenReturn(s);
when(s.getDatabaseType()).thenReturn(DatabaseType.JSON);
// World
when(world.getEnvironment()).thenReturn(World.Environment.NORMAL);
// Command manager
CommandsManager cm = mock(CommandsManager.class);
when(plugin.getCommandsManager()).thenReturn(cm);
// Player
when(user.isOp()).thenReturn(false);
uuid = UUID.randomUUID();
when(user.getUniqueId()).thenReturn(uuid);
when(user.getPlayer()).thenReturn(player);
User.setPlugin(plugin);
// Set up user already
when(player.getUniqueId()).thenReturn(uuid);
User.getInstance(player);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenReturn("mock translation");
// Placeholders
PlaceholdersManager placeholdersManager = mock(PlaceholdersManager.class);
when(plugin.getPlaceholdersManager()).thenReturn(placeholdersManager);
when(placeholdersManager.replacePlaceholders(any(), any())).thenReturn("mock translation");
// Player's manager
when(plugin.getPlayers()).thenReturn(pm);
// Scheduler
BukkitScheduler sch = mock(BukkitScheduler.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getScheduler()).thenReturn(sch);
// version
when(Bukkit.getVersion()).thenReturn("Paper version git-Paper-225 (MC: 1.14.4) (Implementing API version 1.14.4-R0.1-SNAPSHOT)");
// Standard location
when(location.getWorld()).thenReturn(world);
when(location.getBlock()).thenReturn(space1);
when(location.getWorld()).thenReturn(world);
when(location.clone()).thenReturn(location);
Chunk chunk = mock(Chunk.class);
when(location.getChunk()).thenReturn(chunk);
when(space1.getRelative(BlockFace.DOWN)).thenReturn(ground);
when(space1.getRelative(BlockFace.UP)).thenReturn(space2);
// A safe spot
when(ground.getType()).thenReturn(Material.STONE);
when(space1.getType()).thenReturn(Material.AIR);
when(space2.getType()).thenReturn(Material.AIR);
// Neutral BlockState
BlockState blockState = mock(BlockState.class);
when(ground.getState()).thenReturn(blockState);
BlockData bd = mock(BlockData.class);
when(blockState.getBlockData()).thenReturn(bd);
// Online players
// Return a set of online players
when(Bukkit.getOnlinePlayers()).then((Answer<Set<Player>>) invocation -> new HashSet<>());
// Worlds
when(plugin.getIWM()).thenReturn(iwm);
// Default is player is in the world
when(iwm.inWorld(any(World.class))).thenReturn(true);
when(iwm.inWorld(any(Location.class))).thenReturn(true);
// Worlds translate to world
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
// Island
when(island.getOwner()).thenReturn(uuid);
when(island.getWorld()).thenReturn(world);
// default
when(island.getMaxMembers()).thenReturn(null);
// default
when(island.getMaxMembers(Mockito.anyInt())).thenReturn(null);
when(island.getCenter()).thenReturn(location);
when(island.getProtectionCenter()).thenReturn(location);
// Mock island cache
when(islandCache.getIslandAt(any(Location.class))).thenReturn(island);
when(islandCache.get(any(), any())).thenReturn(island);
optionalIsland = Optional.ofNullable(island);
// User location
when(user.getLocation()).thenReturn(location);
// Plugin Manager for events
when(Bukkit.getPluginManager()).thenReturn(pim);
// Addon
when(iwm.getAddon(any())).thenReturn(Optional.empty());
// Cover hostile entities
when(Util.isHostileEntity(any())).thenCallRealMethod();
// Set up island entities
WorldSettings ws = mock(WorldSettings.class);
when(iwm.getWorldSettings(eq(world))).thenReturn(ws);
Map<String, Boolean> worldFlags = new HashMap<>();
when(ws.getWorldFlags()).thenReturn(worldFlags);
Flags.REMOVE_MOBS.setSetting(world, true);
// Default whitelist
Set<EntityType> whitelist = new HashSet<>();
whitelist.add(EntityType.ENDERMAN);
whitelist.add(EntityType.WITHER);
whitelist.add(EntityType.ZOMBIE_VILLAGER);
when(iwm.getRemoveMobsWhitelist(any())).thenReturn(whitelist);
// Monsters and animals
when(zombie.getLocation()).thenReturn(location);
when(zombie.getType()).thenReturn(EntityType.ZOMBIE);
when(zombie.getRemoveWhenFarAway()).thenReturn(true);
when(slime.getLocation()).thenReturn(location);
when(slime.getType()).thenReturn(EntityType.SLIME);
when(slime.getRemoveWhenFarAway()).thenReturn(true);
when(cow.getLocation()).thenReturn(location);
when(cow.getType()).thenReturn(EntityType.COW);
when(wither.getType()).thenReturn(EntityType.WITHER);
when(wither.getRemoveWhenFarAway()).thenReturn(true);
when(creeper.getType()).thenReturn(EntityType.CREEPER);
when(creeper.getRemoveWhenFarAway()).thenReturn(true);
when(pufferfish.getType()).thenReturn(EntityType.PUFFERFISH);
// Named monster
when(skelly.getType()).thenReturn(EntityType.SKELETON);
when(skelly.getCustomName()).thenReturn("Skelly");
when(skelly.getRemoveWhenFarAway()).thenReturn(true);
Collection<Entity> collection = new ArrayList<>();
collection.add(player);
collection.add(zombie);
collection.add(cow);
collection.add(slime);
collection.add(wither);
collection.add(creeper);
collection.add(pufferfish);
collection.add(skelly);
when(world.getNearbyEntities(any(Location.class), Mockito.anyDouble(), Mockito.anyDouble(), Mockito.anyDouble())).thenReturn(collection);
// database must be mocked here
db = mock(Database.class);
// Signs
sign = Material.getMaterial("SIGN");
if (sign == null) {
sign = Material.getMaterial("OAK_SIGN");
}
wallSign = Material.getMaterial("WALL_SIGN");
if (wallSign == null) {
wallSign = Material.getMaterial("OAK_WALL_SIGN");
}
// PaperLib
env = new CraftBukkitEnvironment();
PaperLib.setCustomEnvironment(env);
// Util strip spaces
when(Util.stripSpaceAfterColorCodes(anyString())).thenCallRealMethod();
// Class under test
im = new IslandsManager(plugin);
// Set cache
// im.setIslandCache(islandCache);
}
Aggregations