Skip to content

Commit

Permalink
Add Speed argument to Shoot and Fly commands. Example usage: - fly en…
Browse files Browse the repository at this point in the history
…tities:<player>|ocelot,siamese_cat speed:0.9
  • Loading branch information
davidcernat committed Jul 10, 2013
1 parent 91e8cd4 commit 64be76c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 12 deletions.
Expand Up @@ -146,7 +146,7 @@ public void registerCoreMembers() {
"FLAG", "flag ({player}|npc|global) [name([#])](:action)[:value] (duration:#)", 1);

registerCoreMember(FlyCommand.class,
"FLY", "fly (cancel) [entities:<entity>|...] (origin:<x,y,z,world>) (destination(s):<x,y,z,world>|...)", 1);
"FLY", "fly (cancel) [entities:<entity>|...] (origin:<x,y,z,world>) (destination(s):<x,y,z,world>|...) (speed:<#>)", 1);

registerCoreMember(FollowCommand.class,
"FOLLOW", "follow (stop)", 0);
Expand Down Expand Up @@ -215,7 +215,7 @@ public void registerCoreMembers() {
"OXYGEN", "oxygen (type:maximum|remaining) (mode:set|add|remove) [qty:<#>]", 1);

registerCoreMember(PlayEffectCommand.class,
"PLAYEFFECT", "playeffect [location:<x,y,z,world>] [effect:<name>] (volume:<#>) (pitch:<#>)", 2);
"PLAYEFFECT", "playeffect [location:<x,y,z,world>] [effect:<name>] (data:<#>) (radius:<#>)", 2);

registerCoreMember(PlaySoundCommand.class,
"PLAYSOUND", "playsound [location:<x,y,z,world>] [sound:<name>] (volume:<#>) (pitch:<#>)", 2);
Expand Down Expand Up @@ -257,7 +257,7 @@ public void registerCoreMembers() {
"SCRIBE", "scribe [script:book_script] (give|{drop}|equip) (location:x,y,z,world) OR scribe [item:id.name] [script:book_script]", 1);

registerCoreMember(ShootCommand.class,
"SHOOT", "shoot [projectile(s):<entity>|...] (origin:p@<name>/n@<id>) (destination:<x,y,z,world>) (script:<name>)", 1);
"SHOOT", "shoot [projectile(s):<entity>|...] (origin:p@<name>/n@<id>) (destination:<x,y,z,world>) (speed:<#>) (script:<name>)", 1);

registerCoreMember(SignCommand.class,
"SIGN", "sign (type:{sign_post}/wall_sign) [\"<text>|<text>|<text>|<text>\"] [location:<x,y,z,world>]", 1);
Expand Down
Expand Up @@ -5,6 +5,7 @@

import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dList;
Expand Down Expand Up @@ -63,6 +64,12 @@ else if (!scriptEntry.hasObject("entities")
// Entity arg
scriptEntry.addObject("entities", ((dList) arg.asType(dList.class)).filter(dEntity.class));
}

else if (!scriptEntry.hasObject("speed")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)) {
// Add value
scriptEntry.addObject("speed", arg.asElement());
}
}

// Check to make sure required arguments have been filled
Expand All @@ -81,6 +88,12 @@ else if (scriptEntry.hasPlayer())
else
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ORIGIN");
}

// Use a default speed of 1.5 if one is not specified

if ((!scriptEntry.hasObject("speed"))) {
scriptEntry.addObject("speed", 1.5);
}
}

@SuppressWarnings("unchecked")
Expand All @@ -92,7 +105,9 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
final List<dLocation> destinations = scriptEntry.hasObject("destinations") ?
(List<dLocation>) scriptEntry.getObject("destinations") :
new ArrayList<dLocation>();
new ArrayList<dLocation>();

final Element speed = (Element) scriptEntry.getObject("speed");
Boolean cancel = scriptEntry.hasObject("cancel") ?
true :
false;
Expand All @@ -101,6 +116,7 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
dB.report(getName(), (cancel == true ? "cancel, " : "") +
aH.debugObj("origin", origin) +
aH.debugObj("entities", entities.toString()) +
aH.debugObj("speed", speed) +
(destinations.size() > 0 ? aH.debugObj("destinations", destinations.toString()) : ""));

// Mount or dismount all of the entities
Expand Down Expand Up @@ -177,7 +193,7 @@ public void run() {

Vector v1 = entity.getLocation().toVector();
Vector v2 = location.toVector();
Vector v3 = v2.clone().subtract(v1).normalize().multiply(1.5);
Vector v3 = v2.clone().subtract(v1).normalize().multiply(speed.asDouble());

entity.setVelocity(v3);

Expand Down
Expand Up @@ -7,6 +7,7 @@
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dList;
Expand Down Expand Up @@ -61,10 +62,10 @@ else if (!scriptEntry.hasObject("destination")
scriptEntry.addObject("destination", arg.asType(dLocation.class));
}

else if (!scriptEntry.hasObject("duration")
&& arg.matchesArgumentType(Duration.class)) {
// add value
scriptEntry.addObject("duration", arg.asType(Duration.class));
else if (!scriptEntry.hasObject("speed")
&& arg.matchesPrimitive(aH.PrimitiveType.Double)) {
// Add value
scriptEntry.addObject("speed", arg.asElement());
}

else if (!scriptEntry.hasObject("script")
Expand All @@ -90,6 +91,12 @@ else if (scriptEntry.hasPlayer())
else
throw new InvalidArgumentsException(Messages.ERROR_MISSING_OTHER, "ORIGIN");
}

// Use a default speed of 1.5 if one is not specified

if ((!scriptEntry.hasObject("speed"))) {
scriptEntry.addObject("speed", 1.5);
}
}

@SuppressWarnings("unchecked")
Expand All @@ -106,12 +113,14 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
.multiply(40)));

List<dEntity> projectiles = (List<dEntity>) scriptEntry.getObject("projectiles");
final Element speed = (Element) scriptEntry.getObject("speed");
final dScript script = (dScript) scriptEntry.getObject("script");

// Report to dB
dB.report(getName(), aH.debugObj("origin", shooter) +
aH.debugObj("projectiles", projectiles.toString()) +
aH.debugObj("destination", destination) +
aH.debugObj("speed", speed) +
(script != null ? aH.debugObj("script", script) : ""));

// If the shooter is an NPC, always rotate it to face the destination
Expand Down Expand Up @@ -160,7 +169,7 @@ public void run() {
{
Vector v1 = lastProjectile.getLocation().toVector();
Vector v2 = destination.toVector();
Vector v3 = v2.clone().subtract(v1).normalize().multiply(1.5);
Vector v3 = v2.clone().subtract(v1).normalize().multiply(speed.asDouble());

lastProjectile.setVelocity(v3);
runs++;
Expand Down
Expand Up @@ -68,8 +68,8 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept

// Report to dB
dB.report(getName(), type.name() + ", "
+ location.debug()
+ text.debug());
+ aH.debugObj("location", location)
+ aH.debugObj("text", text));

Block sign = location.getBlock();
sign.setType(Material.valueOf(type.name()));
Expand Down

0 comments on commit 64be76c

Please sign in to comment.