Search in sources :

Example 1 with Cow

use of org.bukkit.entity.Cow in project Quests by LMBishop.

the class MilkingTaskType method onMilk.

@SuppressWarnings("deprecation")
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onMilk(PlayerInteractEntityEvent event) {
    if (!(event.getRightClicked() instanceof Cow) || (event.getPlayer().getItemInHand().getType() != Material.BUCKET)) {
        return;
    }
    if (event.getPlayer().hasMetadata("NPC"))
        return;
    Player player = event.getPlayer();
    QPlayer qPlayer = plugin.getPlayerManager().getPlayer(player.getUniqueId());
    if (qPlayer == null) {
        return;
    }
    QuestProgressFile questProgressFile = qPlayer.getQuestProgressFile();
    for (Quest quest : super.getRegisteredQuests()) {
        if (qPlayer.hasStartedQuest(quest)) {
            QuestProgress questProgress = qPlayer.getQuestProgressFile().getQuestProgress(quest);
            for (Task task : quest.getTasksOfType(super.getType())) {
                if (!TaskUtils.validateWorld(player, task))
                    continue;
                TaskProgress taskProgress = questProgress.getTaskProgress(task.getId());
                if (taskProgress.isCompleted()) {
                    continue;
                }
                int cowsNeeded = (int) task.getConfigValue("amount");
                int progressMilked;
                if (taskProgress.getProgress() == null) {
                    progressMilked = 0;
                } else {
                    progressMilked = (int) taskProgress.getProgress();
                }
                taskProgress.setProgress(progressMilked + 1);
                if (((int) taskProgress.getProgress()) >= cowsNeeded) {
                    taskProgress.setCompleted(true);
                }
            }
        }
    }
}
Also used : QuestProgress(com.leonardobishop.quests.common.player.questprogressfile.QuestProgress) QPlayer(com.leonardobishop.quests.common.player.QPlayer) Player(org.bukkit.entity.Player) Task(com.leonardobishop.quests.common.quest.Task) Cow(org.bukkit.entity.Cow) TaskProgress(com.leonardobishop.quests.common.player.questprogressfile.TaskProgress) QPlayer(com.leonardobishop.quests.common.player.QPlayer) QuestProgressFile(com.leonardobishop.quests.common.player.questprogressfile.QuestProgressFile) Quest(com.leonardobishop.quests.common.quest.Quest) EventHandler(org.bukkit.event.EventHandler)

Example 2 with Cow

use of org.bukkit.entity.Cow in project BentoBox by BentoBoxWorld.

the class TNTListenerTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    // Monsters and animals
    Zombie zombie = mock(Zombie.class);
    when(zombie.getLocation()).thenReturn(location);
    Slime slime = mock(Slime.class);
    when(slime.getLocation()).thenReturn(location);
    Cow cow = mock(Cow.class);
    when(cow.getLocation()).thenReturn(location);
    // Block
    when(block.getLocation()).thenReturn(location);
    when(block.getWorld()).thenReturn(world);
    // Entity
    when(entity.getType()).thenReturn(EntityType.PRIMED_TNT);
    when(entity.getWorld()).thenReturn(world);
    when(entity.getLocation()).thenReturn(location);
    listener = new TNTListener();
    listener.setPlugin(plugin);
}
Also used : Zombie(org.bukkit.entity.Zombie) Cow(org.bukkit.entity.Cow) Slime(org.bukkit.entity.Slime) Before(org.junit.Before)

Example 3 with Cow

use of org.bukkit.entity.Cow in project BentoBox by BentoBoxWorld.

the class ChestDamageListenerTest method setUp.

@Before
public void setUp() {
    // Set up plugin
    plugin = mock(BentoBox.class);
    Whitebox.setInternalState(BentoBox.class, "instance", plugin);
    Server server = mock(Server.class);
    world = mock(World.class);
    when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
    when(server.getWorld("world")).thenReturn(world);
    when(server.getVersion()).thenReturn("BSB_Mocking");
    PluginManager pim = mock(PluginManager.class);
    ItemFactory itemFactory = mock(ItemFactory.class);
    when(server.getItemFactory()).thenReturn(itemFactory);
    // Bukkit
    PowerMockito.mockStatic(Bukkit.class);
    when(Bukkit.getServer()).thenReturn(server);
    when(Bukkit.getPluginManager()).thenReturn(pim);
    SkullMeta skullMeta = mock(SkullMeta.class);
    when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
    when(Bukkit.getItemFactory()).thenReturn(itemFactory);
    when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
    location = mock(Location.class);
    when(location.getWorld()).thenReturn(world);
    when(location.getBlockX()).thenReturn(0);
    when(location.getBlockY()).thenReturn(0);
    when(location.getBlockZ()).thenReturn(0);
    PowerMockito.mockStatic(Flags.class);
    FlagsManager flagsManager = new FlagsManager(plugin);
    when(plugin.getFlagsManager()).thenReturn(flagsManager);
    // Worlds
    IslandWorldManager iwm = mock(IslandWorldManager.class);
    when(iwm.inWorld(any(World.class))).thenReturn(true);
    when(iwm.inWorld(any(Location.class))).thenReturn(true);
    when(iwm.getAddon(any())).thenReturn(Optional.empty());
    when(plugin.getIWM()).thenReturn(iwm);
    // Monsters and animals
    Zombie zombie = mock(Zombie.class);
    when(zombie.getLocation()).thenReturn(location);
    Slime slime = mock(Slime.class);
    when(slime.getLocation()).thenReturn(location);
    Cow cow = mock(Cow.class);
    when(cow.getLocation()).thenReturn(location);
    // Fake players
    Settings settings = mock(Settings.class);
    Mockito.when(plugin.getSettings()).thenReturn(settings);
    Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>());
    // Users
    // User user = mock(User.class);
    // /user.setPlugin(plugin);
    User.setPlugin(plugin);
    // Locales - final
    LocalesManager lm = mock(LocalesManager.class);
    when(plugin.getLocalesManager()).thenReturn(lm);
    Answer<String> answer = invocation -> (String) Arrays.asList(invocation.getArguments()).get(1);
    when(lm.get(any(), any())).thenAnswer(answer);
    // Player name
    PlayersManager pm = mock(PlayersManager.class);
    when(pm.getName(Mockito.any())).thenReturn("tastybento");
    when(plugin.getPlayers()).thenReturn(pm);
    // World Settings
    WorldSettings ws = mock(WorldSettings.class);
    when(iwm.getWorldSettings(Mockito.any())).thenReturn(ws);
    Map<String, Boolean> worldFlags = new HashMap<>();
    when(ws.getWorldFlags()).thenReturn(worldFlags);
    // Island manager
    IslandsManager im = mock(IslandsManager.class);
    when(plugin.getIslands()).thenReturn(im);
    Island island = mock(Island.class);
    Optional<Island> optional = Optional.of(island);
    when(im.getProtectedIslandAt(Mockito.any())).thenReturn(optional);
    // Util
    PowerMockito.mockStatic(Util.class);
    when(Util.getWorld(Mockito.any())).thenReturn(mock(World.class));
}
Also used : IslandsManager(world.bentobox.bentobox.managers.IslandsManager) Arrays(java.util.Arrays) User(world.bentobox.bentobox.api.user.User) Slime(org.bukkit.entity.Slime) Zombie(org.bukkit.entity.Zombie) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Block(org.bukkit.block.Block) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) After(org.junit.After) Material(org.bukkit.Material) Bukkit(org.bukkit.Bukkit) Entity(org.bukkit.entity.Entity) ItemFactory(org.bukkit.inventory.ItemFactory) PlayersManager(world.bentobox.bentobox.managers.PlayersManager) Logger(java.util.logging.Logger) EntityType(org.bukkit.entity.EntityType) IslandWorldManager(world.bentobox.bentobox.managers.IslandWorldManager) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Util(world.bentobox.bentobox.util.Util) Optional(java.util.Optional) EntityExplodeEvent(org.bukkit.event.entity.EntityExplodeEvent) Flags(world.bentobox.bentobox.lists.Flags) LocalesManager(world.bentobox.bentobox.managers.LocalesManager) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Whitebox(org.powermock.reflect.Whitebox) Island(world.bentobox.bentobox.database.objects.Island) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) FlagsManager(world.bentobox.bentobox.managers.FlagsManager) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) Server(org.bukkit.Server) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BentoBox(world.bentobox.bentobox.BentoBox) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) Settings(world.bentobox.bentobox.Settings) Cow(org.bukkit.entity.Cow) Assert.assertEquals(org.junit.Assert.assertEquals) PluginManager(org.bukkit.plugin.PluginManager) Server(org.bukkit.Server) HashMap(java.util.HashMap) IslandsManager(world.bentobox.bentobox.managers.IslandsManager) SkullMeta(org.bukkit.inventory.meta.SkullMeta) World(org.bukkit.World) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) PluginManager(org.bukkit.plugin.PluginManager) LocalesManager(world.bentobox.bentobox.managers.LocalesManager) FlagsManager(world.bentobox.bentobox.managers.FlagsManager) ItemFactory(org.bukkit.inventory.ItemFactory) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) Settings(world.bentobox.bentobox.Settings) PlayersManager(world.bentobox.bentobox.managers.PlayersManager) Zombie(org.bukkit.entity.Zombie) Cow(org.bukkit.entity.Cow) BentoBox(world.bentobox.bentobox.BentoBox) Slime(org.bukkit.entity.Slime) Island(world.bentobox.bentobox.database.objects.Island) IslandWorldManager(world.bentobox.bentobox.managers.IslandWorldManager) Location(org.bukkit.Location) Before(org.junit.Before)

Example 4 with Cow

use of org.bukkit.entity.Cow 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);
}
Also used : Arrays(java.util.Arrays) User(world.bentobox.bentobox.api.user.User) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Slime(org.bukkit.entity.Slime) Zombie(org.bukkit.entity.Zombie) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) PaperLib(io.papermc.lib.PaperLib) Block(org.bukkit.block.Block) Location(org.bukkit.Location) World(org.bukkit.World) Map(java.util.Map) After(org.junit.After) Chunk(org.bukkit.Chunk) Path(java.nio.file.Path) Database(world.bentobox.bentobox.database.Database) Material(org.bukkit.Material) IslandCache(world.bentobox.bentobox.managers.island.IslandCache) Bukkit(org.bukkit.Bukkit) PufferFish(org.bukkit.entity.PufferFish) ImmutableSet(com.google.common.collect.ImmutableSet) BlockData(org.bukkit.block.data.BlockData) Entity(org.bukkit.entity.Entity) Collection(java.util.Collection) Set(java.util.Set) UUID(java.util.UUID) EntityType(org.bukkit.entity.EntityType) Assert.assertFalse(org.junit.Assert.assertFalse) Util(world.bentobox.bentobox.util.Util) Optional(java.util.Optional) Flags(world.bentobox.bentobox.lists.Flags) Mockito.mock(org.mockito.Mockito.mock) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) IslandDeleteEvent(world.bentobox.bentobox.api.events.island.IslandDeleteEvent) Whitebox(org.powermock.reflect.Whitebox) Island(world.bentobox.bentobox.database.objects.Island) CraftBukkitEnvironment(io.papermc.lib.environments.CraftBukkitEnvironment) Wither(org.bukkit.entity.Wither) Mock(org.mockito.Mock) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) DatabaseType(world.bentobox.bentobox.database.DatabaseSetup.DatabaseType) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) Builder(com.google.common.collect.ImmutableSet.Builder) ArgumentCaptor(org.mockito.ArgumentCaptor) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) BentoBox(world.bentobox.bentobox.BentoBox) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) PowerMockito(org.powermock.api.mockito.PowerMockito) Before(org.junit.Before) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) Files(java.nio.file.Files) Assert.assertNotNull(org.junit.Assert.assertNotNull) Skeleton(org.bukkit.entity.Skeleton) Assert.assertTrue(org.junit.Assert.assertTrue) BlockState(org.bukkit.block.BlockState) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) PermissionAttachmentInfo(org.bukkit.permissions.PermissionAttachmentInfo) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) Creeper(org.bukkit.entity.Creeper) Settings(world.bentobox.bentobox.Settings) Cow(org.bukkit.entity.Cow) Comparator(java.util.Comparator) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) PluginManager(org.bukkit.plugin.PluginManager) Environment(io.papermc.lib.environments.Environment) Entity(org.bukkit.entity.Entity) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) World(org.bukkit.World) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) Database(world.bentobox.bentobox.database.Database) BlockData(org.bukkit.block.data.BlockData) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) Settings(world.bentobox.bentobox.Settings) HashSet(java.util.HashSet) CraftBukkitEnvironment(io.papermc.lib.environments.CraftBukkitEnvironment) BentoBox(world.bentobox.bentobox.BentoBox) Chunk(org.bukkit.Chunk) EntityType(org.bukkit.entity.EntityType) BlockState(org.bukkit.block.BlockState) BukkitScheduler(org.bukkit.scheduler.BukkitScheduler) Location(org.bukkit.Location) Before(org.junit.Before)

Example 5 with Cow

use of org.bukkit.entity.Cow in project BentoBox by BentoBoxWorld.

the class FireListenerTest method setUp.

@Before
public void setUp() {
    worldFlags.clear();
    PowerMockito.mockStatic(Bukkit.class);
    // Set up plugin
    plugin = mock(BentoBox.class);
    Whitebox.setInternalState(BentoBox.class, "instance", plugin);
    Server server = mock(Server.class);
    World world = mock(World.class);
    when(server.getLogger()).thenReturn(Logger.getAnonymousLogger());
    when(server.getWorld("world")).thenReturn(world);
    when(server.getVersion()).thenReturn("BSB_Mocking");
    PluginManager pim = mock(PluginManager.class);
    when(Bukkit.getPluginManager()).thenReturn(pim);
    ItemFactory itemFactory = mock(ItemFactory.class);
    when(server.getItemFactory()).thenReturn(itemFactory);
    SkullMeta skullMeta = mock(SkullMeta.class);
    when(itemFactory.getItemMeta(any())).thenReturn(skullMeta);
    when(Bukkit.getItemFactory()).thenReturn(itemFactory);
    when(Bukkit.getLogger()).thenReturn(Logger.getAnonymousLogger());
    location = mock(Location.class);
    when(location.getWorld()).thenReturn(world);
    when(location.getBlockX()).thenReturn(0);
    when(location.getBlockY()).thenReturn(0);
    when(location.getBlockZ()).thenReturn(0);
    PowerMockito.mockStatic(Flags.class);
    FlagsManager flagsManager = new FlagsManager(plugin);
    when(plugin.getFlagsManager()).thenReturn(flagsManager);
    // Worlds
    IslandWorldManager iwm = mock(IslandWorldManager.class);
    when(iwm.inWorld(any(World.class))).thenReturn(true);
    when(iwm.inWorld(any(Location.class))).thenReturn(true);
    when(plugin.getIWM()).thenReturn(iwm);
    // Monsters and animals
    Zombie zombie = mock(Zombie.class);
    when(zombie.getLocation()).thenReturn(location);
    Slime slime = mock(Slime.class);
    when(slime.getLocation()).thenReturn(location);
    Cow cow = mock(Cow.class);
    when(cow.getLocation()).thenReturn(location);
    // Fake players
    Settings settings = mock(Settings.class);
    Mockito.when(plugin.getSettings()).thenReturn(settings);
    Mockito.when(settings.getFakePlayers()).thenReturn(new HashSet<>());
    // Users
    User.setPlugin(plugin);
    // Locales - final
    LocalesManager lm = mock(LocalesManager.class);
    when(plugin.getLocalesManager()).thenReturn(lm);
    when(lm.get(any(), any())).thenReturn("mock translation");
    // Player name
    PlayersManager pm = mock(PlayersManager.class);
    when(pm.getName(any())).thenReturn("tastybento");
    when(plugin.getPlayers()).thenReturn(pm);
    // World Settings
    WorldSettings ws = mock(WorldSettings.class);
    when(iwm.getWorldSettings(any())).thenReturn(ws);
    when(ws.getWorldFlags()).thenReturn(worldFlags);
    GameModeAddon gma = mock(GameModeAddon.class);
    Optional<GameModeAddon> opGma = Optional.of(gma);
    when(iwm.getAddon(any())).thenReturn(opGma);
    PowerMockito.mockStatic(Util.class);
    when(Util.getWorld(any())).thenReturn(mock(World.class));
}
Also used : PlayersManager(world.bentobox.bentobox.managers.PlayersManager) Server(org.bukkit.Server) Zombie(org.bukkit.entity.Zombie) GameModeAddon(world.bentobox.bentobox.api.addons.GameModeAddon) SkullMeta(org.bukkit.inventory.meta.SkullMeta) Cow(org.bukkit.entity.Cow) BentoBox(world.bentobox.bentobox.BentoBox) World(org.bukkit.World) Slime(org.bukkit.entity.Slime) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) PluginManager(org.bukkit.plugin.PluginManager) LocalesManager(world.bentobox.bentobox.managers.LocalesManager) IslandWorldManager(world.bentobox.bentobox.managers.IslandWorldManager) FlagsManager(world.bentobox.bentobox.managers.FlagsManager) ItemFactory(org.bukkit.inventory.ItemFactory) WorldSettings(world.bentobox.bentobox.api.configuration.WorldSettings) Settings(world.bentobox.bentobox.Settings) Location(org.bukkit.Location) Before(org.junit.Before)

Aggregations

Cow (org.bukkit.entity.Cow)8 Slime (org.bukkit.entity.Slime)6 Zombie (org.bukkit.entity.Zombie)6 Before (org.junit.Before)6 Location (org.bukkit.Location)3 Material (org.bukkit.Material)3 World (org.bukkit.World)3 Block (org.bukkit.block.Block)3 ItemStack (org.bukkit.inventory.ItemStack)3 SkullMeta (org.bukkit.inventory.meta.SkullMeta)3 PluginManager (org.bukkit.plugin.PluginManager)3 BentoBox (world.bentobox.bentobox.BentoBox)3 Settings (world.bentobox.bentobox.Settings)3 WorldSettings (world.bentobox.bentobox.api.configuration.WorldSettings)3 ArrayList (java.util.ArrayList)2 Arrays (java.util.Arrays)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Map (java.util.Map)2 Optional (java.util.Optional)2