Java Code Examples for org.bukkit.Bukkit#unloadWorld()

The following examples show how to use org.bukkit.Bukkit#unloadWorld() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GameMap.java    From AnnihilationPro with MIT License 5 votes vote down vote up
public void unLoadMap()
	{
		//World tpworld = Bukkit.getWorlds().size() > 0 ? Bukkit.getWorlds().get(0) : null;
		World tpworld = Game.LobbyMap != null ? Game.LobbyMap.getWorld() : null;
		if(tpworld == null)
			tpworld = Bukkit.getWorlds().size() > 0 ? Bukkit.getWorlds().get(0) : null;
		for(Player p : Bukkit.getOnlinePlayers())
		{
			if(p.getWorld().getName().equals(this.getWorldName()))
			{
				if(tpworld != null)
					p.teleport(tpworld.getSpawnLocation());
				else
					p.kickPlayer("Unloading the world and we dont want you to get trapped or glitched!");
			}
		}
		this.unregisterListeners();

		boolean b = Bukkit.unloadWorld(super.getWorldName(), false);
        Bukkit.getLogger().info("[Annihilation] "+super.getNiceWorldName()+" was unloaded successfully: "+b);
//		try
//		{
//			FileUtils.deleteDirectory(this.mapDirec);
//			FileUtils.copyDirectory(this.tempDirec, this.mapDirec);
//			FileUtils.deleteDirectory(this.tempDirec);
//		}
//		catch (IOException e)
//		{
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	}
 
Example 2
Source File: DGameWorld.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Delete this instance.
 */
@Override
public void delete() {
    InstanceWorldUnloadEvent event = new InstanceWorldUnloadEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    kickAllPlayers();

    Bukkit.unloadWorld(getWorld(), /* SPIGOT-5225 */ !Version.isAtLeast(Version.MC1_14_4));
    FileUtil.removeDir(getFolder());
    plugin.getInstanceCache().remove(this);
}
 
Example 3
Source File: DResourceWorld.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates the "raw" world that is copied for new instances.
 */
public static void createRaw() {
    WorldCreator rawCreator = WorldCreator.name(".raw");
    rawCreator.type(WorldType.FLAT);
    rawCreator.generateStructures(false);
    World world = rawCreator.createWorld();
    File worldFolder = new File(Bukkit.getWorldContainer(), ".raw");
    FileUtil.copyDir(worldFolder, RAW, DungeonsXL.EXCLUDED_FILES);
    Bukkit.unloadWorld(world, /* SPIGOT-5225 */ !Version.isAtLeast(Version.MC1_14_4));
    FileUtil.removeDir(worldFolder);
}
 
Example 4
Source File: DEditWorld.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void delete(boolean save) {
    EditWorldUnloadEvent event = new EditWorldUnloadEvent(this, true);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    kickAllPlayers();

    if (save) {
        getResource().getSignData().serializeSigns(signs.values());
        Bukkit.unloadWorld(getWorld(), true);
        new BukkitRunnable() {
            @Override
            public void run() {
                getResource().clearFolder();
                FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES);
                DResourceWorld.deleteUnusedFiles(getResource().getFolder());
                FileUtil.removeDir(getFolder());
            }
        }.runTaskLaterAsynchronously(plugin, plugin.getMainConfig().getEditInstanceRemovalDelay() * 20L);
    }
    if (!save) {
        Bukkit.unloadWorld(getWorld(), /* SPIGOT-5225 */ !Version.isAtLeast(Version.MC1_14_4));
        new BukkitRunnable() {
            @Override
            public void run() {
                FileUtil.removeDir(getFolder());
            }
        }.runTaskLaterAsynchronously(plugin, plugin.getMainConfig().getEditInstanceRemovalDelay() * 20L);
    }

    getResource().editWorld = null;
    plugin.getInstanceCache().remove(this);
}
 
Example 5
Source File: GameHandler.java    From CardinalPGM with MIT License 5 votes vote down vote up
public void cycleAndMakeMatch() {
    if (repositoryManager.getRotation().getNext().equals(cycle.getMap())) {
        repositoryManager.getRotation().move();
    }
    World oldMatchWorld = matchWorld == null ? null : matchWorld.get();
    cycle.run();
    if (match != null) match.unregisterModules();
    this.match = new Match(cycle.getUuid(), cycle.getMap(), repositoryManager.getRepo(cycle.getMap()));
    this.match.registerModules();
    Cardinal.getInstance().getLogger().info(this.match.getModules().size() + " modules loaded.");
    Bukkit.getServer().getPluginManager().callEvent(new CycleCompleteEvent(match));
    cycle = new Cycle(repositoryManager.getRotation().getNext(), UUID.randomUUID(), this);
    Bukkit.unloadWorld(oldMatchWorld, true);
}
 
Example 6
Source File: DEditWorld.java    From DungeonsXL with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void save() {
    EditWorldSaveEvent event = new EditWorldSaveEvent(this);
    Bukkit.getPluginManager().callEvent(event);
    if (event.isCancelled()) {
        return;
    }

    plugin.setLoadingWorld(true);
    Map<Player, Double[]> players = new HashMap<>();
    getWorld().getPlayers().forEach(p -> players.put(p,
            new Double[]{
                p.getLocation().getX(),
                p.getLocation().getY(),
                p.getLocation().getZ(),
                new Double(p.getLocation().getYaw()),
                new Double(p.getLocation().getPitch())
            }
    ));
    kickAllPlayers();

    getResource().editWorld = null;
    plugin.getInstanceCache().remove(this);
    getResource().getSignData().serializeSigns(signs.values());
    Bukkit.unloadWorld(getWorld(), true);
    new ProgressBar(players.keySet(), plugin.getMainConfig().getEditInstanceRemovalDelay()) {
        @Override
        public void onFinish() {
            getResource().clearFolder();
            FileUtil.copyDir(getFolder(), getResource().getFolder(), DungeonsXL.EXCLUDED_FILES);
            DResourceWorld.deleteUnusedFiles(getResource().getFolder());
            FileUtil.removeDir(getFolder());

            plugin.setLoadingWorld(false);
            EditWorld newEditWorld = getResource().getOrInstantiateEditWorld(true);
            players.keySet().forEach(p -> {
                if (p.isOnline()) {
                    new DEditPlayer(plugin, p, newEditWorld);
                    Double[] coords = players.get(p);
                    p.teleport(new Location(newEditWorld.getWorld(), coords[0], coords[1], coords[2], coords[3].floatValue(), coords[4].floatValue()));
                }
            });
        }
    }.send(plugin);
}
 
Example 7
Source File: WorldHandler.java    From VoxelGamesLibv2 with MIT License 2 votes vote down vote up
/**
 * Unloads a local world
 *
 * @param name the world to load
 * @throws WorldException if the world is not found or something else goes wrong
 */
public void unloadLocalWorld(@Nonnull String name) {
    log.finer("Unloading world " + name);
    Bukkit.unloadWorld(name, false);
}