下面列出了org.bukkit.Bukkit#getWorldContainer ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Generate a new DResourceWorld.
*
* @return the automatically created DEditWorld instance
*/
public DEditWorld generate() {
int id = DInstanceWorld.counter;
String name = DInstanceWorld.generateName(false, id);
File folder = new File(Bukkit.getWorldContainer(), name);
WorldCreator creator = new WorldCreator(name);
creator.type(WorldType.FLAT);
creator.generateStructures(false);
DEditWorld editWorld = new DEditWorld(plugin, this, folder);
this.editWorld = editWorld;
EditWorldGenerateEvent event = new EditWorldGenerateEvent(editWorld);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
if (!RAW.exists()) {
createRaw();
}
FileUtil.copyDir(RAW, folder, DungeonsXL.EXCLUDED_FILES);
editWorld.generateIdFile();
editWorld.world = creator.createWorld().getName();
editWorld.generateIdFile();
return editWorld;
}
/**
* 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);
}
@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]));
}
@Override
public File getSaveFolder() {
return new File(Bukkit.getWorldContainer(), getWorldName() + File.separator + "region");
}