Skip to content

Commit

Permalink
Add an environment argument to createworld
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Mar 7, 2016
1 parent 8e9ab3c commit 7504675
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Expand Up @@ -757,7 +757,7 @@ public void registerCoreMembers() {

// <--[command]
// @Name CreateWorld
// @Syntax createworld [<name>] (g:<generator>) (worldtype:<type>)
// @Syntax createworld [<name>] (g:<generator>) (worldtype:<type>) (environment:<environment>)
// @Required 1
// @Stable unstable
// @Short Creates a new world
Expand All @@ -770,18 +770,22 @@ public void registerCoreMembers() {
// If a worldtype is not specified it will create a world with a worldtype of NORMAL.
// Recognised world type are NORMAL (creates a normal world), FLAT (creates a world with flat terrain),
// LARGE_BIOMES (creates a normal world with 16x larger biomes) and AMPLIFIED (creates a world with tall
// mountain-like terrain)
// mountain-like terrain).
// An environment is expected and will be defaulted to NORMAL. Alternatives are NETHER and THE_END.
// @Tags
// <server.list_worlds>
// @Usage
// Use to create a normal world with name survival
// Use to create a normal world with name 'survival'
// - createworld survival
// @Usage
// Use to create a flat world with the name superflat
// Use to create a flat world with the name 'superflat'
// - createworld superflat worldtype:FLAT
// @Usage
// Use to create an end world with the name 'space'
// - createworld space environment:THE_END
// -->
registerCoreMember(CreateWorldCommand.class,
"CREATEWORLD", "createworld [<name>] (g:<generator>) (worldtype:<type>)", 1);
"CREATEWORLD", "createworld [<name>] (g:<generator>) (worldtype:<type>) (environment:<environment>)", 1);


// <--[command]
Expand Down
Expand Up @@ -32,6 +32,12 @@ else if (!scriptEntry.hasObject("worldtype")
scriptEntry.addObject("worldtype", arg.asElement());
}

else if (!scriptEntry.hasObject("environment")
&& arg.matchesPrefix("environment")
&& arg.matchesEnum(World.Environment.values())) {
scriptEntry.addObject("environment", arg.asElement());
}

else if (!scriptEntry.hasObject("world_name")) {
scriptEntry.addObject("world_name", arg.asElement());
}
Expand All @@ -49,16 +55,20 @@ else if (!scriptEntry.hasObject("world_name")) {
if (!scriptEntry.hasObject("worldtype")) {
scriptEntry.addObject("worldtype", new Element("NORMAL"));
}

scriptEntry.defaultObject("environment", new Element("normal"));
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Element World_Name = scriptEntry.getElement("world_name");
Element Generator = scriptEntry.getElement("generator");
Element worldType = scriptEntry.getElement("worldtype");
Element environment = scriptEntry.getElement("environment");

dB.report(scriptEntry, getName(), World_Name.debug() +
(Generator != null ? Generator.debug() : "") +
environment.debug() +
worldType.debug());

World world;
Expand All @@ -67,17 +77,19 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
world = Bukkit.getServer().createWorld(WorldCreator
.name(World_Name.asString())
.generator(Generator.asString())
.environment(World.Environment.valueOf(environment.asString().toUpperCase()))
.type(WorldType.valueOf(worldType.asString().toUpperCase())));
}

else {
world = Bukkit.getServer().createWorld(WorldCreator
.name(World_Name.asString())
.environment(World.Environment.valueOf(environment.asString().toUpperCase()))
.type(WorldType.valueOf(worldType.asString().toUpperCase())));
}

if (world == null) {
dB.echoDebug(scriptEntry, "World is null! :(");
dB.echoDebug(scriptEntry, "World is null, something went wrong in creation!");
}

}
Expand Down

0 comments on commit 7504675

Please sign in to comment.