Skip to content

Commit

Permalink
Added World command to set weather and time
Browse files Browse the repository at this point in the history
This can already be done using Essentials commands or checking for
downfall, but in a future Bukkit PR it will be possible to set the
weather for a specific player, where this is coming in handy
  • Loading branch information
spaceemotion committed Mar 23, 2013
1 parent f057317 commit 1418475
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
Expand Up @@ -210,6 +210,9 @@ public void registerCoreMembers() {

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

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

registerCoreMember(ZapCommand.class,
"ZAP", "zap [#|step:step_name] (script:script_name{current_script}) (duration:#)", 0);
Expand Down
@@ -0,0 +1,121 @@
package net.aufdemrand.denizen.scripts.commands.core;

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.utilities.arguments.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

/**
* Various world based commands.
* Such as: weather and times
*
* @author spaceemotion
*/
public class WorldCommand extends AbstractCommand {

private enum Action { WEATHER, TIME }

private enum SubAction {
// Time actions
DAY, NIGHT, DUSK, DAWN,

// Weather actions
THUNDERING, STORM, SUNNY, THUNDERSTORM
}

private enum Type { GLOBAL, PLAYER } // TODO: Player type will come when Bukkit PR gets accepted

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
Type type = Type.GLOBAL;
Action action = null;
SubAction sub = null;
Player player = scriptEntry.getPlayer();

for (String arg : scriptEntry.getArguments()) {
if (aH.matchesArg("player", arg)) {
player = Bukkit.getServer().getPlayer(aH.getStringFrom("player"));
type = Type.PLAYER;

} else if (aH.matchesArg("weather", arg)) {
action = Action.WEATHER;
sub = SubAction.valueOf(aH.getStringFrom("weather"));
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for WEATHER!");

} else if (aH.matchesArg("time", arg)) {
action = Action.TIME;
sub = SubAction.valueOf(aH.getStringFrom("time"));
if(sub == null) throw new InvalidArgumentsException("Invalid sub action for TIME!");

} else throw new InvalidArgumentsException(dB.Messages.ERROR_UNKNOWN_ARGUMENT, arg);
}

if (type == null)
throw new InvalidArgumentsException("Must specify an action! Valid: WEATHER, TIME");


scriptEntry.addObject("type", type);
scriptEntry.addObject("action", action);
scriptEntry.addObject("subaction", sub);
scriptEntry.addObject("player", player);
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
Type type = (Type) scriptEntry.getObject("time");
Action action = (Action) scriptEntry.getObject("action");
SubAction sub = (SubAction) scriptEntry.getObject("subaction");
Player player = (Player) scriptEntry.getObject("player");

dB.report(getName(),
aH.debugObj("Type", type.name())
+ aH.debugObj("Action", action.name())
+ aH.debugObj("Sub-Action", sub.name())
+ ((type == Type.PLAYER) ? aH.debugObj("Player", player.getName()) : ""));

switch(action) {
case WEATHER:
switch(sub) {
case SUNNY:
player.getWorld().setThundering(false);
player.getWorld().setStorm(false);
break;

case THUNDERSTORM:
player.getWorld().setThundering(true);

case STORM:
player.getWorld().setStorm(true);
break;

case THUNDERING:
player.getWorld().setThundering(true);
}

break;

case TIME:
switch(sub) {
case DAY:
player.getWorld().setTime(0);
break;

case NIGHT:
player.getWorld().setTime(13500);
break;

case DUSK:
player.getWorld().setTime(12500);
break;

case DAWN:
player.getWorld().setTime(23000);
}
}
}

}

0 comments on commit 1418475

Please sign in to comment.