Skip to content

Commit

Permalink
Update the time command
Browse files Browse the repository at this point in the history
Slightly better chance of working.
Also, use our fancy new ToLowerCase util method.
  • Loading branch information
mcmonkey4eva committed Nov 13, 2014
1 parent c7eab7f commit be3fd98
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.aufdemrand.denizen.utilities.SQLEscaper;
import net.aufdemrand.denizen.utilities.debugging.dB;

import net.aufdemrand.denizencore.utilities.CoreUtilities;
import org.bukkit.ChatColor;

// <--[language]
Expand Down Expand Up @@ -1323,7 +1324,7 @@ else if (element.toLowerCase().contains(contains.toLowerCase()))
// Returns the value of an element in all lowercase letters.
// -->
if (attribute.startsWith("to_lowercase") || attribute.startsWith("lower"))
return new Element(element.toLowerCase()).getAttribute(attribute.fulfill(1));
return new Element(CoreUtilities.toLowerCase(element)).getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <el@element.to_titlecase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ public String getAttribute(Attribute attribute) {
// @description
// Returns the compass direction between two locations.
// If no second location is specified, returns the direction of the location.
// Example returns include "north", "southwest", ...
// -->
if (attribute.startsWith("direction")) {
// Get the cardinal direction from this location to another
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2605,22 +2605,34 @@ public void registerCoreMembers() {

// <--[command]
// @Name Time
// @Syntax time [type:{global}/player] [<value>] (world:<name>)
// @Syntax time [{global}/player] [<time duration>] (<world>)
// @Required 1
// @Stable TODO: Document Command Details
// @Short Changes the current time in the minecraft world.
// @Author David Cernat
// @Author David Cernat, mcmonkey
// @Group world
// @Description
// Changes the current time in a world or the time that a player sees the world in.
// TODO: Document Command Details
// If no world is specified, defaults to the NPCs world. If no NPC is available,
// defaults to the player's world. If no player is available, an error will be thrown.
// @Tags
// <w@world.time>
// <w@world.time.period>
// @Usage
// Use to set the time in the NPC or Player's world.
// - time 500t
// @Usage
// Use to make the player see a different time than everyone else.
// - time player 500t
// @Usage
// Use to set the time in a specific world.
// - time 500t w@myworld
// @Usage
// TODO: Document Command Details
// -->
registerCoreMember(TimeCommand.class,
"TIME", "time [type:{global}/player] [<value>] (world:<name>)", 1);
"TIME", "time [{global}/player] [<time duration>] (<world>)", 1);

// <--[command]
// @Name Trait
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.aufdemrand.denizen.scripts.commands.world;

import net.aufdemrand.denizen.BukkitScriptEntryData;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizencore.exceptions.CommandExecutionException;
import net.aufdemrand.denizencore.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.scripts.ScriptEntry;
Expand All @@ -27,19 +28,16 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException

if (!scriptEntry.hasObject("type")
&& arg.matchesEnum(Type.values())) {

scriptEntry.addObject("type", Type.valueOf(arg.getValue().toUpperCase()));
scriptEntry.addObject("type", arg.asElement());
}

else if (!scriptEntry.hasObject("value")
&& arg.matchesArgumentType(Duration.class)) {

scriptEntry.addObject("value", arg.asType(Duration.class));
}

else if (!scriptEntry.hasObject("world")
&& arg.matchesArgumentType(dWorld.class)) {

scriptEntry.addObject("world", arg.asType(dWorld.class));
}

Expand All @@ -53,10 +51,15 @@ else if (!scriptEntry.hasObject("world")

// If the world has not been specified, try to use the NPC's or player's
// world, or default to "world" if necessary
if (!scriptEntry.hasObject("world")) {
scriptEntry.addObject("world",
((BukkitScriptEntryData) scriptEntry.entryData).hasNPC() ?
new dWorld(((BukkitScriptEntryData) scriptEntry.entryData).getNPC().getWorld()) :
(((BukkitScriptEntryData) scriptEntry.entryData).hasPlayer() ?
new dWorld(((BukkitScriptEntryData) scriptEntry.entryData).getPlayer().getWorld()) : null));
}

scriptEntry.defaultObject("world",
((BukkitScriptEntryData)scriptEntry.entryData).hasNPC() ? new dWorld(((BukkitScriptEntryData)scriptEntry.entryData).getNPC().getWorld()) : null,
((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer() ? new dWorld(((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getWorld()) : null);
scriptEntry.defaultObject("type", new Element("GLOBAL"));

if (!scriptEntry.hasObject("world"))
throw new InvalidArgumentsException("Must specify a valid world!");
Expand All @@ -67,22 +70,23 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
// Fetch objects
Duration value = (Duration) scriptEntry.getObject("value");
dWorld world = (dWorld) scriptEntry.getObject("world");
Type type = scriptEntry.hasObject("type") ?
(Type) scriptEntry.getObject("type") : Type.GLOBAL;
Element type_element = scriptEntry.getElement("type");
Type type = Type.valueOf(type_element.asString().toUpperCase());

// Report to dB
dB.report(scriptEntry, getName(), aH.debugObj("type", type.name()) +
(type.name().equalsIgnoreCase("player") ?
aH.debugObj("player", ((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()) : "") +
(type.name().equalsIgnoreCase("global") ?
aH.debugObj("world", world) : "") +
aH.debugObj("value", value));
dB.report(scriptEntry, getName(), type_element.debug()
+ value.debug()
+ world.debug());

if (type.equals(Type.GLOBAL)) {
world.getWorld().setTime(value.getTicks());
}
else {
((BukkitScriptEntryData)scriptEntry.entryData).getPlayer().getPlayerEntity().setPlayerTime(value.getTicks(), true);
if (!((BukkitScriptEntryData)scriptEntry.entryData).hasPlayer())
dB.echoError("Must have a valid player link!");
else
((BukkitScriptEntryData)scriptEntry.entryData).getPlayer()
.getPlayerEntity().setPlayerTime(value.getTicks(), true);
}
}
}

0 comments on commit be3fd98

Please sign in to comment.