Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split World command into Time and Weather commands.
- Loading branch information
1 parent
ece0841
commit 195ff51
Showing
4 changed files
with
145 additions
and
127 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
60 changes: 60 additions & 0 deletions
60
src/main/java/net/aufdemrand/denizen/scripts/commands/world/TimeCommand.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,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()); | ||
} | ||
|
||
} |
79 changes: 79 additions & 0 deletions
79
src/main/java/net/aufdemrand/denizen/scripts/commands/world/WeatherCommand.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,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; | ||
} | ||
} | ||
|
||
} |
124 changes: 0 additions & 124 deletions
124
src/main/java/net/aufdemrand/denizen/scripts/commands/world/WorldCommand.java
This file was deleted.
Oops, something went wrong.