Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added World command to set weather and time
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
1 parent
f057317
commit 1418475
Showing
2 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
src/main/java/net/aufdemrand/denizen/scripts/commands/core/WorldCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
|
||
} |