本文整理汇总了Java中org.spongepowered.api.world.WorldArchetypes类的典型用法代码示例。如果您正苦于以下问题:Java WorldArchetypes类的具体用法?Java WorldArchetypes怎么用?Java WorldArchetypes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WorldArchetypes类属于org.spongepowered.api.world包,在下文中一共展示了WorldArchetypes类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import org.spongepowered.api.world.WorldArchetypes; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource commandSource, CommandContext args) throws CommandException {
String worldURI = args.<String>getOne("uri").get();
// TODO (HACK) for now we'll just interpret this as a directory
// the idea is to later handle URIs, like in BundleManager, and be able to import e.g. from GitHub!! ;)
File worldSavesDir = Sponge.getGame().getSavesDirectory().resolve("world").toFile();
// worlds apparently (learnt the hard way..) HAVE to be in the saves directory!
// if later we want arbitrary dirs, or stream from git, we'd have to copy/move them here:
File worldDirectory = new File(worldSavesDir, worldURI);
if (!(worldDirectory.exists() && worldDirectory.isDirectory())) {
throw new CommandException(Text.of("Must be an existing directory, but isn't: " + worldDirectory));
}
// TODO this WorldArchetype metadata should be read from some properties [JSON/YAML] file along the world/ (saves/ ?) dir.
String newWorldName = worldDirectory.getName();
WorldArchetype archetype = WorldArchetypes.OVERWORLD;
WorldProperties loadedWorldProperties = CommandExceptions.getOrThrow("createWorldProperties: " + newWorldName,
() -> Sponge.getServer().createWorldProperties(newWorldName, archetype));
if (loadedWorldProperties != null) {
Sponge.getServer().saveWorldProperties(loadedWorldProperties);
if (!loadedWorldProperties.getWorldName().equals(newWorldName)) {
commandSource.sendMessage(Texts.inRed("Uh oh; imported folder name does not match new world name... this is BAD!"));
}
// TODO .onClick(TextActions.executeCallback(/tpw) ..
commandSource.sendMessage(Text.of("OK, created new world " + loadedWorldProperties.getWorldName()));
} else {
throw CommandExceptions.create("Failed to load: " + newWorldName);
}
return CommandResult.success();
}
示例2: execute
import org.spongepowered.api.world.WorldArchetypes; //导入依赖的package包/类
@Override
public CommandResult execute(CommandSource commandSource, CommandContext args) throws CommandException {
String newWorldName = args.<String>getOne(ARG_NAME).get();
// TODO more configuration options!
WorldProperties loadedWorldProperties = CommandExceptions.getOrThrow("createWorldProperties: " + newWorldName,
() -> Sponge.getServer().createWorldProperties(newWorldName, WorldArchetypes.THE_SKYLANDS));
commandSource.sendMessage(Text.of("Create new world!"));
return CommandResult.success();
}
示例3: WorldArchetypeRegistryModule
import org.spongepowered.api.world.WorldArchetypes; //导入依赖的package包/类
public WorldArchetypeRegistryModule() {
super(WorldArchetypes.class);
}
示例4: create
import org.spongepowered.api.world.WorldArchetypes; //导入依赖的package包/类
@Command(desc = "Creates a new world")
public void create(CommandSource context,
String name,
@Default @Named({"dimension", "dim"}) DimensionType dimension,
@Named("seed") String seed,
@Default @Named({"type"}) GeneratorType type,
@Default @Label("generate") @Named({"structure", "struct"}) boolean generateStructures,
@Default @Named({"gamemode", "mode"}) GameMode gamemode,
@Default @Named({"difficulty", "diff"}) Difficulty difficulty,
@org.cubeengine.butler.parametric.Optional @Label("name") @Named({"generator","gen"}) WorldGeneratorModifier generator,
@Flag boolean recreate,
@Flag boolean noload,
@Flag boolean spawnInMemory)
{
Optional<World> world = Sponge.getServer().getWorld(name);
if (world.isPresent())
{
if (recreate)
{
i18n.send(context, NEGATIVE, "You have to unload a world before recreating it!");
return;
}
i18n.send(context, NEGATIVE, "A world named {world} already exists and is loaded!", world.get());
return;
}
Optional<WorldProperties> worldProperties = Sponge.getServer().getWorldProperties(name);
if (worldProperties.isPresent())
{
if (!recreate)
{
i18n.send(context, NEGATIVE, "A world named {name#world} already exists but is not loaded!", name);
return;
}
worldProperties.get().setEnabled(false);
String newName = name + "_" + new SimpleDateFormat("yyyy-MM-dd_HH-mm-ss").format(new Date());
Sponge.getServer().renameWorld(worldProperties.get(), newName);
i18n.send(context, POSITIVE, "Old world moved to {name#folder}", newName);
}
WorldArchetype.Builder builder = WorldArchetype.builder().from(WorldArchetypes.OVERWORLD);
builder.keepsSpawnLoaded(spawnInMemory);
builder.loadsOnStartup(!noload);
if (seed != null)
{
try
{
builder.seed(Long.parseLong(seed));
}
catch (NumberFormatException ignore)
{
builder.seed(seed.hashCode());
}
}
builder.generator(type);
builder.dimension(dimension);
builder.usesMapFeatures(generateStructures);
builder.gameMode(gamemode);
if (generator != null)
{
builder.generatorModifiers(generator);
}
builder.difficulty(difficulty);
try
{
WorldProperties properties = Sponge.getServer().createWorldProperties(name, builder.build("org.cubeengine.customworld:" + UUID.randomUUID().toString(), name));
i18n.send(context, POSITIVE, "World {name} successfully created!", name);
i18n.send(context, NEUTRAL, "This world is not yet loaded! Click {txt#here} to load.",
i18n.translate(context, TextFormat.NONE, "here").toBuilder().onClick(TextActions.runCommand("/worlds load " + name)).build());
}
catch (IOException e)
{
i18n.send(context, NEGATIVE, "Could not create world!");
throw new IllegalStateException(e); // TODO handle exception better
}
}