Skip to content

Commit

Permalink
Add World argument to Time and Weather commands.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidcernat committed Jul 4, 2013
1 parent 592a726 commit 3e434f8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void registerCoreMembers() {
"TELEPORT", "teleport (npc) [location:x,y,z,world] (target(s):[n@#]|[p@name])", 1);

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

registerCoreMember(TriggerCommand.class,
"TRIGGER", "trigger [name:trigger_name] [(toggle:true|false)|(cooldown:#.#)|(radius:#)]", 2);
Expand All @@ -283,7 +283,7 @@ public void registerCoreMembers() {
"WALK, WALKTO", "walk [location:x,y,z,world] (speed:#)", 1);

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

registerCoreMember(YamlCommand.class,
"YAML", "...", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public String getHelp() {
}

public String getUsage() {
return "run [script] (as:p@player|n@npc) (id:id_name) (delay:duration) (loop) (q:#)"
return "run [script] (as:p@player|n@npc) (id:id_name) (delay:duration) (loop) (q:#)";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
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.objects.dWorld;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

Expand All @@ -27,8 +27,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values()))
// add type
scriptEntry.addObject("type", arg.asElement());
scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));

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

else if (!scriptEntry.hasObject("value")
&& arg.matchesArgumentType(Duration.class))
Expand All @@ -40,21 +44,33 @@ else if (!scriptEntry.hasObject("value")

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

// Use default world if none has been specified

if (!scriptEntry.hasObject("world"))
scriptEntry.addObject("world", dWorld.valueOf("world"));
}

@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"));
dWorld world = (dWorld) scriptEntry.getObject("world");
Type type = scriptEntry.hasObject("type") ?
(Type) scriptEntry.getObject("type") : Type.GLOBAL;

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

scriptEntry.getPlayer().getPlayerEntity().getWorld().setTime(value.getTicks());
if (type.equals(Type.GLOBAL)) {
world.getWorld().setTime(value.getTicks());
}
else {
scriptEntry.getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
}
}

}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package net.aufdemrand.denizen.scripts.commands.world;

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

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.objects.dWorld;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;

Expand All @@ -30,8 +30,12 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values()))
// add type
scriptEntry.addObject("type", arg.asElement());
scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));

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

else if (!scriptEntry.hasObject("value")
&& arg.matchesEnum(Value.values()))
Expand All @@ -43,35 +47,58 @@ else if (!scriptEntry.hasObject("value")

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

// Use default world if none has been specified

if (!scriptEntry.hasObject("world"))
scriptEntry.addObject("world", dWorld.valueOf("world"));
}

@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();
dWorld world = (dWorld) scriptEntry.getObject("world");
Type type = scriptEntry.hasObject("type") ?
(Type) scriptEntry.getObject("type") : Type.GLOBAL;

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

switch(value) {
case SUNNY:
world.setStorm(false);
world.setThundering(false);
break;
if (type.equals(Type.GLOBAL)) {
world.getWorld().setStorm(false);
world.getWorld().setThundering(false);
}
else {
scriptEntry.getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.CLEAR);
}

break;

case STORM:
world.setStorm(true);
if (type.equals(Type.GLOBAL)) {
world.getWorld().setStorm(true);
}
else {
scriptEntry.getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.DOWNFALL);
}

break;

case THUNDER:
// Note: setThundering always creates a storm
world.setThundering(true);
if (type.equals(Type.GLOBAL)) {
world.getWorld().setThundering(true);
}
else {
scriptEntry.getPlayer().getPlayerEntity().setPlayerWeather(WeatherType.DOWNFALL);
}

break;
}
}
Expand Down

0 comments on commit 3e434f8

Please sign in to comment.