Skip to content

Commit

Permalink
Update look command to 0.9 syntax. - look (entity) [location] // Note…
Browse files Browse the repository at this point in the history
…: not specifying entity will default to attached NPC.
  • Loading branch information
aufdemrand committed Jul 15, 2013
1 parent 65d8928 commit 3f9bd6a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 157 deletions.
Expand Up @@ -191,7 +191,7 @@ public void registerCoreMembers() {
"LOG", "log [<text>] (type:severe/info/warning/fine/finer/finest) [file:<name>]", 2);

registerCoreMember(LookCommand.class,
"LOOK", "look (player/npc) [<location>]", 1);
"LOOK", "look (entity) [location] // Note: not specifying entity will default to attached NPC", 1);

This comment has been minimized.

Copy link
@davidcernat

davidcernat Jul 15, 2013

Contributor

auf, didn't we agree to use <> in command syntaxes to show custom values as opposed to static arguments?

<davidcernat> Basically, a lot of commands have ":name" in their syntaxes.
<davidcernat> And I thought we could change that into ":<name>" to clean them up.
<davidcernat> For instance
<davidcernat> - spawn [entity:name] (location:x,y,z,world)
<davidcernat> Could be
<davidcernat> - spawn [entity:<name>] (location:x,y,z,world)
<aufdemrand2> - spawn [<entity>] [<location>]
<davidcernat> :p
<davidcernat> Fair enough.
<aufdemrand2> i'm cool with that
<aufdemrand2> it would help..
<aufdemrand2> for like
<davidcernat> - narrate [\"narration text\"] (player:name) (format:name)
<davidcernat> Could be
<aufdemrand2> - chat (target:<player>) [text]
<davidcernat> narrate [\"narration text\"] (player:<name>) (format:<name>)
<davidcernat> Yeah
<davidcernat> So I can add < > to syntaxes then. :)
<davidcernat> Yay.
<aufdemrand2> yes...

Also, can we please not have notes like that? It would mean every command needs a note for default values. I think it would be better to just document that in the handbook or on the wiki.

This comment has been minimized.

Copy link
@aufdemrand

aufdemrand via email Jul 16, 2013

Author Contributor

registerCoreMember(LookcloseCommand.class,
"LOOKCLOSE", "lookclose [state:true/false]", 1);
Expand Down
@@ -1,5 +1,10 @@
package net.aufdemrand.denizen.scripts.commands.entity;

import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dLocation;
import net.aufdemrand.denizen.objects.dNPC;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.Location;
import org.bukkit.entity.LivingEntity;

Expand All @@ -22,134 +27,47 @@

public class LookCommand extends AbstractCommand {

// TODO: Finish

/* LOOK [[DIRECTION]|[BOOKMARK]:'LOCATION BOOKMARK'|[CLOSE|AWAY]]*/

/* Arguments: [] - Required, () - Optional
*
* [Requires one of the below]
* DIRECTION - Valid Directions: UP DOWN LEFT RIGHT NORTH SOUTH EAST WEST BACK AT
* LOCATION BOOKMARK - gets Yaw/Pitch from a location bookmark.
* CLOSE/AWAY - toggles the NPC's LookClose trait
*
* Modifiers:
* (NPCID:#) Changes the Denizen to the Citizens2 NPCID
* (DURATION:#) Reverts to the previous head position after # amount of seconds.
*/

private enum TargetType { NPC, PLAYER }
private enum Direction { UP, DOWN, LEFT, RIGHT, NORTH, SOUTH, EAST, WEST, BACK, AT, CLOSE, AWAY }


// look (e@entity) [l@location] // Note: not specifying entity will default to attached NPC
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

TargetType targetType = TargetType.NPC;
Integer duration = null;
Direction direction = null;
Location location = null;

for (String arg : scriptEntry.getArguments()) {

// If argument is a duration
if (aH.matchesDuration(arg)) {
duration = aH.getIntegerFrom(arg);
dB.echoDebug("...look duration set to '%s'.", arg);
}

else if (aH.matchesArg("PLAYER", arg)) {
targetType = TargetType.PLAYER;
dB.echoDebug("... will affect the player!");
}

// If argument is a LOCATION modifier
else if (aH.matchesLocation(arg)) {
location = aH.getLocationFrom(arg);
dB.echoDebug("...location set");
}

// If argument is a Direction
else {
for (Direction thisDirection : Direction.values()) {
if (arg.toUpperCase().equals(thisDirection.name())) {
direction = Direction.valueOf(arg);
dB.echoDebug("...set look direction '%s'.", arg);
}
}
}
}

// If TARGET is NPC/PLAYER and no NPC/PLAYER available, throw exception.
if (targetType == TargetType.PLAYER && scriptEntry.getPlayer() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_PLAYER);
else if (targetType == TargetType.NPC && scriptEntry.getNPC() == null) throw new InvalidArgumentsException(Messages.ERROR_NO_NPCID);
scriptEntry.addObject("target", targetType)
.addObject("location", location);
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

TargetType target = (TargetType) scriptEntry.getObject("target");
Location location = (Location) scriptEntry.getObject("location");
LivingEntity entity = null;

if (target.name().matches("NPC")) {
entity = scriptEntry.getNPC().getCitizen().getBukkitEntity();

// Turn off the NPC's lookclose
scriptEntry.getNPC().getCitizen().getTrait(LookClose.class).lookClose(false);
}
else {
entity = scriptEntry.getPlayer().getPlayerEntity();
}

if (location != null) {
Rotation.faceLocation(entity, location);
}


}

for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {



/*
// MADE IT THIS FAR
if (!scriptEntry.hasObject("location")
&& arg.matchesArgumentType(dLocation.class))
scriptEntry.addObject("location", arg.asType(dLocation.class));

if (theDenizen == null) {
aH.echoError("Seems this was sent from a TASK-type script. Must use NPCID:# to specify a Denizen NPC!");
return false;
}
if (!scriptEntry.hasObject("entity")
&& arg.matchesArgumentType(dEntity.class))
scriptEntry.addObject("entity", arg.asType(dEntity.class));

if (theLocation != null) {
look(theEntity, theDenizen, direction, duration, theLocation);
return true;
}
}

if (theEntity == null) theEntity = (LivingEntity) theEntry.getPlayer();
if (direction != null) look(theEntity, theDenizen, direction, duration, theLocation);
if (!scriptEntry.hasObject("entity")
&& scriptEntry.hasNPC()
&& scriptEntry.getNPC().isSpawned())
scriptEntry.addObject("entity", new dEntity(scriptEntry.getNPC().getEntity()));

return true;
if (!scriptEntry.hasObject("location") || !scriptEntry.hasObject("entity"))
throw new InvalidArgumentsException("Must specify a location and spawned entity!");
}

@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {

dLocation loc = (dLocation) scriptEntry.getObject("location");
dEntity ent = (dEntity) scriptEntry.getObject("entity");

private void look(LivingEntity theEntity, dNPC theDenizen, Direction lookDir, Integer duration, Location lookLoc) {
dB.report(getName(), loc.debug() + ent.debug());

Location restoreLocation = theDenizen.getEntity().getLocation();
dNPC restoreDenizen = theDenizen;
Boolean restoreLookClose = theDenizen.isLookingClose();
String lookWhere = "NOWHERE";
Rotation.faceLocation(ent.getLivingEntity(), loc);

if (lookDir != null) lookWhere = lookDir.name();
}

if (lookWhere.equals("CLOSE")) {
theDenizen.lookClose(true);
}

else if (lookWhere.equals("AWAY")) {
theDenizen.lookClose(false);
}


/*
else if (lookWhere.equals("LEFT")) {
theDenizen.lookClose(false);
Expand Down Expand Up @@ -205,49 +123,6 @@ else if (lookWhere.equals("EAST")) {
theDenizen.getHandle().az = theDenizen.getHandle().yaw;
}
else if (lookWhere.equals("AT")) {
theDenizen.lookClose(false);
faceEntity(theDenizen.getEntity(), theEntity);
}
else if (lookLoc != null) {
theDenizen.lookClose(false);
theDenizen.getHandle().pitch = lookLoc.getPitch();
theDenizen.getHandle().yaw = lookLoc.getYaw();
theDenizen.getHandle().az = theDenizen.getHandle().yaw;
}
// If duration is set...
if (duration != null) {
if (taskMap.containsKey(theDenizen.getCitizensEntity().getId())) {
try {
plugin.getServer().getScheduler().cancelTask(taskMap.get(theDenizen.getId()));
} catch (Exception e) { }
}
aH.echoDebug("Setting delayed task: RESET LOOK");
taskMap.put(theDenizen.getCitizensEntity().getId(), plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new FourItemRunnable<dNPC, Location, Boolean, Float>(restoreDenizen, restoreLocation, restoreLookClose, theDenizen.getLocation().getYaw()) {
@Override
public void run(dNPC denizen, Location location, Boolean lookClose, Float checkYaw) {
aH.echoDebug(ChatColor.YELLOW + "//DELAYED//" + ChatColor.WHITE + " Running delayed task: RESET LOOK.");
denizen.lookClose(lookClose);
// if (denizen.getLocation().getYaw() == checkYaw) {
denizen.getHandle().yaw = location.getYaw();
denizen.getHandle().pitch = location.getPitch();
denizen.getHandle().az = denizen.getHandle().yaw;
// }
}
}, duration * 20));
}
}
*/
}

0 comments on commit 3f9bd6a

Please sign in to comment.