Examples of MVWorldManager


Examples of com.onarandombox.MultiverseCore.api.MVWorldManager

                ChatColor.GREEN + "Complete!");

        // ////////////////////////////////////////////////
        // let's set some world-properties
        // we can test the API with this, too :D
        MVWorldManager worldManager = core.getMVWorldManager();
        assertNotNull(worldManager);

        MultiverseWorld mvWorld = worldManager.getMVWorld("world");
        MultiverseWorld netherWorld = worldManager.getMVWorld("world_nether");
        assertNotNull(mvWorld);
        assertNotNull(netherWorld);
        assertSame(mvWorld, worldManager.getFirstSpawnWorld());
        assertSame(mvWorld, worldManager.getSpawnWorld());

        /* ***************************** *
         *        Check defaults
         * ***************************** */
        assertFalse(mvWorld.isHidden());
        assertEquals(mvWorld.getName(), mvWorld.getAlias());
        assertEquals(ChatColor.WHITE, mvWorld.getColor());
        assertTrue(mvWorld.isPVPEnabled());
        assertEquals(1D, mvWorld.getScaling(), 0);
        assertNull(mvWorld.getRespawnToWorld());
        assertTrue(mvWorld.isWeatherEnabled());
        assertEquals(Difficulty.NORMAL, mvWorld.getDifficulty());
        assertTrue(mvWorld.canAnimalsSpawn());
        assertTrue(mvWorld.canMonstersSpawn());
        assertEquals(-1, mvWorld.getCurrency());
        assertEquals(0, mvWorld.getPrice(), 0);
        assertTrue(mvWorld.getHunger());
        assertTrue(mvWorld.getAutoHeal());
        assertTrue(mvWorld.getAdjustSpawn());
        assertEquals(GameMode.SURVIVAL, mvWorld.getGameMode());
        assertTrue(mvWorld.isKeepingSpawnInMemory());
        assertTrue(mvWorld.getBedRespawn());
        assertTrue(mvWorld.getAutoLoad());
        assertEquals(new SpawnLocation(0, 64, 0), mvWorld.getSpawnLocation());

        /* ****************************************** *
         *    Call some events and verify behavior
         * ****************************************** */
        createEvents(mvWorld);

        // call both weather change events
        core.getWeatherListener().weatherChange(weatherChangeOffEvent);
        assertFalse(weatherChangeOffEvent.isCancelled());
        core.getWeatherListener().weatherChange(weatherChangeOnEvent);
        assertFalse(weatherChangeOnEvent.isCancelled());

        // call both thunder change events
        core.getWeatherListener().thunderChange(thunderChangeOffEvent);
        assertFalse(thunderChangeOffEvent.isCancelled());
        core.getWeatherListener().thunderChange(thunderChangeOnEvent);
        assertFalse(thunderChangeOnEvent.isCancelled());

        // call player chat event
        core.getMVConfig().setPrefixChat(true);
        ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
        verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
        core.getMVConfig().setPrefixChat(false);
        ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
        verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)

        // call player join events
        core.getPlayerListener().playerJoin(playerJoinEvent);
        verify(mockPlayer, never()).teleport(any(Location.class));
        core.getPlayerListener().playerJoin(playerNewJoinEvent);
        verify(mockNewPlayer).teleport(worldManager.getFirstSpawnWorld().getSpawnLocation());

        // call player respawn events
        core.getPlayerListener().playerRespawn(playerRespawnBed);
        // bedrespawn is on so nothing should happen
        verify(playerRespawnBed, never()).setRespawnLocation(any(Location.class));
        core.getPlayerListener().playerRespawn(playerRespawnNormal);
        verify(playerRespawnNormal).setRespawnLocation(mvWorld.getSpawnLocation());

        // call entity regain health event
        core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
        // autoheal is on so nothing should happen
        verify(entityRegainHealthEvent, never()).setCancelled(true);


        /* ************************ *
         *     Modify & Verify
         * ************************ */
        mvWorld.setHidden(true);
        assertEquals(true, mvWorld.isHidden());
        mvWorld.setAlias("alias");
        assertEquals("alias", mvWorld.getAlias());
        assertTrue(mvWorld.setColor("BLACK"));
        assertFalse(mvWorld.setColor("INVALID COLOR"));
        assertEquals(ChatColor.BLACK, mvWorld.getColor());
        assertEquals(ChatColor.BLACK.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
        mvWorld.setPVPMode(false);
        assertEquals(false, mvWorld.isPVPEnabled());
        assertTrue(mvWorld.setScaling(2D));
        assertEquals(2D, mvWorld.getScaling(), 0);
        assertFalse(mvWorld.setRespawnToWorld("INVALID WORLD"));
        assertTrue(mvWorld.setRespawnToWorld("world_nether"));
        assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
                mvWorld.getRespawnToWorld());
        mvWorld.setEnableWeather(false);
        assertEquals(false, mvWorld.isWeatherEnabled());
        assertTrue(mvWorld.setDifficulty(Difficulty.PEACEFUL));
        assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
        mvWorld.setAllowAnimalSpawn(false);
        assertEquals(false, mvWorld.canAnimalsSpawn());
        mvWorld.setAllowMonsterSpawn(false);
        assertEquals(false, mvWorld.canMonstersSpawn());
        mvWorld.setCurrency(1);
        assertEquals(1, mvWorld.getCurrency());
        mvWorld.setPrice(1D);
        assertEquals(1D, mvWorld.getPrice(), 0);
        mvWorld.setHunger(false);
        assertEquals(false, mvWorld.getHunger());
        mvWorld.setAutoHeal(false);
        assertEquals(false, mvWorld.getAutoHeal());
        mvWorld.setAdjustSpawn(false);
        assertEquals(false, mvWorld.getAdjustSpawn());
        assertTrue(mvWorld.setGameMode(GameMode.CREATIVE));
        assertEquals(GameMode.CREATIVE, mvWorld.getGameMode());
        mvWorld.setKeepSpawnInMemory(false);
        assertEquals(false, mvWorld.isKeepingSpawnInMemory());
        mvWorld.setBedRespawn(false);
        assertEquals(false, mvWorld.getBedRespawn());
        mvWorld.setAutoLoad(false);
        assertEquals(false, mvWorld.getAutoLoad());
        mvWorld.setSpawnLocation(new Location(mvWorld.getCBWorld(), 1, 1, 1));
        assertEquals(new SpawnLocation(1, 1, 1), mvWorld.getSpawnLocation());


        /* ****************************************** *
         *    Call some events and verify behavior
         * ****************************************** */
        // We have to recreate the events and the mock-objects
        createEvents(mvWorld);

        // call both weather change events
        core.getWeatherListener().weatherChange(weatherChangeOffEvent);
        assertFalse(weatherChangeOffEvent.isCancelled());
        core.getWeatherListener().weatherChange(weatherChangeOnEvent);
        assertTrue(weatherChangeOnEvent.isCancelled());

        // call both thunder change events
        core.getWeatherListener().thunderChange(thunderChangeOffEvent);
        assertFalse(thunderChangeOffEvent.isCancelled());
        core.getWeatherListener().thunderChange(thunderChangeOnEvent);
        assertTrue(thunderChangeOnEvent.isCancelled());

        // call player chat event
        core.getMVConfig().setPrefixChat(true);
        ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
        // never because it's hidden!
        verify(playerChatEvent, never()).setFormat(
                "[" + mvWorld.getColoredWorldString() + "]" + "format");
        mvWorld.setHidden(false);
        ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
        verify(playerChatEvent).setFormat("[" + mvWorld.getColoredWorldString() + "]" + "format");
        core.getMVConfig().setPrefixChat(false);
        ((MVAsyncPlayerChatListener) core.getChatListener()).playerChat(playerChatEvent);
        verify(playerChatEvent, times(1)).setFormat(anyString()); // only ONE TIME (not the 2nd time!)
        mvWorld.setHidden(true); // reset hidden-state

        // call player join events
        core.getPlayerListener().playerJoin(playerJoinEvent);
        verify(mockPlayer, never()).teleport(any(Location.class));
        core.getPlayerListener().playerJoin(playerNewJoinEvent);
        verify(mockNewPlayer).teleport(new SpawnLocation(1, 1, 1));

        // call player respawn events
        core.getPlayerListener().playerRespawn(playerRespawnBed);
        // bedrespawn is off so something should happen (and we've set respawn to nether...)
        verify(playerRespawnBed).setRespawnLocation(netherWorld.getSpawnLocation());
        core.getPlayerListener().playerRespawn(playerRespawnNormal);
        verify(playerRespawnNormal).setRespawnLocation(netherWorld.getSpawnLocation());

        // call entity regain health event
        core.getEntityListener().entityRegainHealth(entityRegainHealthEvent);
        // autoheal is off so something should happen
        verify(entityRegainHealthEvent).setCancelled(true);


        /* ****************************************** *
         *           Test saving/loading
         * ****************************************** */
        assertTrue(core.saveMVConfigs());
        // change a value here
        FileConfiguration config = YamlConfiguration.loadConfiguration(new File(core.getDataFolder(), "worlds.yml"));
        WorldProperties worldObj = (WorldProperties) config.get("worlds.world");
        assertTrue(worldObj.setColor("GREEN"));
        config.set("worlds.world", worldObj);
        config.save(new File(core.getDataFolder(), "worlds.yml"));
        // load
        core.loadConfigs();

        mvWorld = worldManager.getMVWorld("world");
        assertEquals(true, mvWorld.isHidden());
        assertEquals("alias", mvWorld.getAlias());
        assertEquals(ChatColor.GREEN, mvWorld.getColor());
        assertEquals(ChatColor.GREEN.toString() + "alias" + ChatColor.WHITE.toString(), mvWorld.getColoredWorldString());
        assertEquals(false, mvWorld.isPVPEnabled());
        assertEquals(2D, mvWorld.getScaling(), 0);
        assertSame(worldManager.getMVWorld("world_nether").getCBWorld(),
                mvWorld.getRespawnToWorld());
        assertEquals(false, mvWorld.isWeatherEnabled());
        assertEquals(Difficulty.PEACEFUL, mvWorld.getDifficulty());
        assertEquals(false, mvWorld.canAnimalsSpawn());
        assertEquals(false, mvWorld.canMonstersSpawn());
View Full Code Here

Examples of com.onarandombox.MultiverseCore.api.MVWorldManager

        mvWorld = mock(MultiverseWorld.class);
        cbworld = mock(World.class);
        when(mvWorld.getCBWorld()).thenReturn(cbworld);

        MVWorldManager worldman = mock(MVWorldManager.class);
        when(worldman.isMVWorld(anyString())).thenReturn(true);
        when(worldman.getMVWorld(anyString())).thenReturn(mvWorld);
        Field worldmanfield = MVEntityListener.class.getDeclaredField("worldManager");
        worldmanfield.setAccessible(true);
        worldmanfield.set(listener, worldman);

        core.getMVConfig().setGlobalDebug(3);
View Full Code Here

Examples of com.onarandombox.MultiverseCore.api.MVWorldManager

          MyWorlds.plugin.log(Level.WARNING, "Could not find Multiverse Core main plugin instance");
          return false;
        }

        // Obtain the world configuration information in MV
        MVWorldManager manager = core.getMVWorldManager();
        Map<String, WorldProperties> propsMap = SafeField.get(manager, "worldsFromTheConfig");
        WorldProperties world = propsMap.get(config.worldname);

        // Newly created world: no configuration in MV is available
        if (world == null) {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.