Skip to content

Commit

Permalink
Split World command into Time and Weather commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jun 28, 2013
1 parent ece0841 commit 195ff51
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 127 deletions.
Expand Up @@ -258,6 +258,9 @@ public void registerCoreMembers() {
registerCoreMember(TeleportCommand.class,
"TELEPORT", "teleport (npc) [location:x,y,z,world] (target(s):[n@#]|[p@name])", 1);

registerCoreMember(TimeCommand.class,
"TIME", "time [type:{global}|player] [<#>]", 1);

registerCoreMember(TriggerCommand.class,
"TRIGGER", "trigger [name:trigger_name] [(toggle:true|false)|(cooldown:#.#)|(radius:#)]", 2);

Expand All @@ -269,10 +272,10 @@ public void registerCoreMembers() {

registerCoreMember(WalkToCommand.class,
"WALKTO", "walkto [location:x,y,z,world] (speed:#)", 1);

registerCoreMember(WorldCommand.class,
"WORLD", "world [type:global|player] (player:player.name) [action:sub_action]", 1);

registerCoreMember(WeatherCommand.class,
"WEATHER", "weather [type:{global}|player] [sunny|storm|thunder]", 1);

registerCoreMember(YamlCommand.class,
"YAML", "...", 1);

Expand Down
@@ -0,0 +1,60 @@
package net.aufdemrand.denizen.scripts.commands.world;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

/**
*
* Set the time in the world to a number of ticks.
*
*/
public class TimeCommand extends AbstractCommand {

private enum Type { GLOBAL, PLAYER }

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values()))
// add type
scriptEntry.addObject("type", arg.asElement());


else if (!scriptEntry.hasObject("value")
&& arg.matchesArgumentType(Duration.class))
// add value
scriptEntry.addObject("value", arg.asType(Duration.class));
}

// Check to make sure required arguments have been filled

if ((!scriptEntry.hasObject("value")))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "VALUE");
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch objects
Duration value = (Duration) scriptEntry.getObject("value");
Element type = (scriptEntry.hasObject("type") ?
(Element) scriptEntry.getObject("type") : new Element("player"));

// Report to dB
dB.report(getName(), type.debug()
+ (type.toString().equalsIgnoreCase("player") ? scriptEntry.getPlayer().debug() : "")
+ value.debug());

scriptEntry.getPlayer().getPlayerEntity().getWorld().setTime(value.getTicks());
}

}
@@ -0,0 +1,79 @@
package net.aufdemrand.denizen.scripts.commands.world;

import org.bukkit.Bukkit;
import org.bukkit.World;

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

/**
*
* Set the weather in the world.
*
*/
public class WeatherCommand extends AbstractCommand {

private enum Type { GLOBAL, PLAYER }
private enum Value { SUNNY, STORM, THUNDER }

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {

if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values()))
// add type
scriptEntry.addObject("type", arg.asElement());


else if (!scriptEntry.hasObject("value")
&& arg.matchesEnum(Value.values()))
// add value
scriptEntry.addObject("value", arg.asElement());
}

// Check to make sure required arguments have been filled

if ((!scriptEntry.hasObject("value")))
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "VALUE");
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch objects
Value value = Value.valueOf(((Element) scriptEntry.getObject("value"))
.asString().toUpperCase());
Element type = (scriptEntry.hasObject("type") ?
(Element) scriptEntry.getObject("type") : new Element("player"));
World world = scriptEntry.getPlayer().getPlayerEntity().getWorld();

// Report to dB
dB.report(getName(), type.debug()
+ (type.toString().equalsIgnoreCase("player") ? scriptEntry.getPlayer().debug() : "")
+ value.toString());

switch(value) {
case SUNNY:
world.setStorm(false);
world.setThundering(false);
break;

case STORM:
world.setStorm(true);
break;

case THUNDER:
// Note: setThundering always creates a storm
world.setThundering(true);
break;
}
}

}

This file was deleted.

0 comments on commit 195ff51

Please sign in to comment.