Java Code Examples for org.bukkit.World#save()

The following examples show how to use org.bukkit.World#save() . 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: EliteMobs.java    From EliteMobs with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onDisable() {

    Bukkit.getServer().getScheduler().cancelTasks(MetadataHandler.PLUGIN);

    EntityTracker.shutdownPurger();

    for (World world : validWorldList) {
        world.save();
    }

    /*
    Flush lingering arrows from the arrow tracking power
     */
    for (Arrow arrow : SkeletonTrackingArrow.trackingArrowList)
        arrow.remove();
    SkeletonTrackingArrow.trackingArrowList.clear();

    /*
    todo: Flush lingering blocks
     */


    CustomItemConstructor.customItemList.clear();
    CustomItemConstructor.staticCustomItemHashMap.clear();
    CustomItemConstructor.dynamicRankedItemStacks.clear();
    UniqueItemInitializer.uniqueItemsList.clear();
    validWorldList.clear();

    //save cached data
    Bukkit.getScheduler().cancelTask(PlayerData.databaseSyncTaskID);
    Bukkit.getLogger().info("[EliteMobs] Saving EliteMobs databases...");
    PlayerData.saveDatabases();
    Bukkit.getLogger().info("[EliteMobs] All saved! Good night.");
    PlayerData.clearPlayerData();

}
 
Example 2
Source File: ImportCommand.java    From DungeonsXL with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExecute(String[] args, CommandSender sender) {
    File target = new File(DungeonsXL.MAPS, args[1]);
    File source = new File(Bukkit.getWorldContainer(), args[1]);

    if (!source.exists()) {
        MessageUtil.sendMessage(sender, DMessage.ERROR_NO_SUCH_MAP.getMessage(args[1]));
        return;
    }

    if (target.exists()) {
        MessageUtil.sendMessage(sender, DMessage.ERROR_NAME_IN_USE.getMessage(args[1]));
        return;
    }

    World world = Bukkit.getWorld(args[1]);
    if (world != null) {
        world.save();
    }

    MessageUtil.log(plugin, "&6Creating new map.");
    MessageUtil.log(plugin, "&6Importing world...");

    FileUtil.copyDir(source, target, "playerdata", "stats");

    DResourceWorld resource = new DResourceWorld(plugin, args[1]);
    plugin.getDungeonRegistry().add(args[1], new DDungeon(plugin, resource));
    if (world.getEnvironment() != Environment.NORMAL) {
        WorldConfig config = resource.getConfig(true);
        config.setWorldEnvironment(world.getEnvironment());
        config.save();
    }
    plugin.getMapRegistry().add(resource.getName(), resource);
    MessageUtil.sendMessage(sender, DMessage.CMD_IMPORT_SUCCESS.getMessage(args[1]));
}
 
Example 3
Source File: BukkitPlugin.java    From BlueMap with MIT License 4 votes vote down vote up
@Override
public void onEnable() {
	new MetricsLite(this);
	
	//save world so the level.dat is present on new worlds
	Logger.global.logInfo("Saving all worlds once, to make sure the level.dat is present...");
	for (World world : getServer().getWorlds()) {
		world.save();
	}
	
	//register events
	getServer().getPluginManager().registerEvents(eventForwarder, this);
	
	//register commands
	try {
		final Field bukkitCommandMap = Bukkit.getServer().getClass().getDeclaredField("commandMap");

		bukkitCommandMap.setAccessible(true);
		CommandMap commandMap = (CommandMap) bukkitCommandMap.get(Bukkit.getServer());

		for (BukkitCommand command : commands.getRootCommands()) {
			commandMap.register(command.getLabel(), command);
		}
	} catch(NoSuchFieldException | SecurityException | IllegalAccessException e) {
		Logger.global.logError("Failed to register commands!", e);
	}
	
	//tab completions
	getServer().getPluginManager().registerEvents(commands, this);
	
	//load bluemap
	getServer().getScheduler().runTaskAsynchronously(this, () -> {
		try {
			Logger.global.logInfo("Loading...");
			this.bluemap.load();
			if (bluemap.isLoaded()) Logger.global.logInfo("Loaded!");
		} catch (Throwable t) {
			Logger.global.logError("Failed to load!", t);
		}
	});
}