Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/aufdemrand/Denizen
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jul 31, 2013
2 parents 5a67dd7 + 741b98d commit 67d7b04
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 43 deletions.
9 changes: 2 additions & 7 deletions src/main/java/net/aufdemrand/denizen/CommandHandler.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
package net.aufdemrand.denizen;

import java.util.ArrayList;
import java.util.List;

import java.util.Map;
import java.util.Set;

import net.aufdemrand.denizen.listeners.AbstractListener;
import net.aufdemrand.denizen.npc.traits.*;
import net.aufdemrand.denizen.objects.dNPC;
import net.aufdemrand.denizen.objects.dPlayer;
import net.aufdemrand.denizen.scripts.ScriptBuilder;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.ScriptHelper;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.scripts.containers.ScriptContainer;
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.ScriptRepo;
Expand All @@ -29,8 +24,8 @@
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.api.util.Paginator;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Paginator;

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.util.Paginator;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Paginator;
import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.LivingEntity;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.util.Paginator;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Paginator;
import org.bukkit.command.CommandSender;
import org.bukkit.event.EventHandler;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.util.Paginator;
import net.citizensnpcs.util.Messages;
import net.citizensnpcs.util.Paginator;
import org.bukkit.command.CommandSender;
import org.bukkit.event.Listener;

Expand Down
2 changes: 0 additions & 2 deletions src/main/java/net/aufdemrand/denizen/objects/aH.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package net.aufdemrand.denizen.objects;

import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.scripts.ScriptRegistry;
import net.aufdemrand.denizen.utilities.debugging.dB;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.entity.EntityType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void registerCoreMembers() {
"ANCHOR", "anchor [id:<name>] [assume/add/remove/walkto/walknear] (range:<#>)", 2);

registerCoreMember(AnimateCommand.class,
"ANIMATE", "animate [entities:<entity>|...] [animation:<name>]", 1);
"ANIMATE", "animate [<entity>|...] [animation:<name>]", 1);

registerCoreMember(AnimateChestCommand.class,
"ANIMATECHEST", "animatechest [<location>] ({open}/close) (sound:{true}/false)", 1);
Expand All @@ -71,16 +71,16 @@ public void registerCoreMembers() {
"ASSIGNMENT", "assignment [{set}/remove] (script:<name>)", 1);

registerCoreMember(AttackCommand.class,
"ATTACK", "attack (cancel) (entities:<entity>|...) (target:<entity>)", 0);
"ATTACK", "attack (cancel) (<entity>|...) (target:<entity>)", 0);

registerCoreMember(BreakCommand.class,
"BREAK", "break [<location>] (entity:<entity>) (radius:<#.#>)", 1);

registerCoreMember(BurnCommand.class,
"BURN", "burn [entities:<entity>|...] (duration:<value>)", 1);
"BURN", "burn [<entity>|...] (duration:<value>)", 1);

registerCoreMember(CastCommand.class,
"CAST", "cast [<effect>] (duration:<#>) (power:<#>) (entities:<entity>|...)", 1);
"CAST", "cast [<effect>] (duration:<value>) (power:<#>) (<entity>|...)", 1);

registerCoreMember(ChatCommand.class,
"CHAT", "chat [\"<text>\"] (targets:<entity>|...)", 1);
Expand All @@ -89,7 +89,7 @@ public void registerCoreMembers() {
"CHUNKLOAD", "chunkload ({add}/remove/removeall) [<location>] (duration:<value>)", 1);

registerCoreMember(CooldownCommand.class,
"COOLDOWN", "cooldown (duration:<#>) (global) (script:<name>)", 1);
"COOLDOWN", "cooldown (duration:<value>) (global) (script:<name>)", 1);

registerCoreMember(CopyBlockCommand.class,
"COPYBLOCK", "copyblock [location:<location>] [to:<location>]", 1);
Expand All @@ -107,13 +107,13 @@ public void registerCoreMembers() {
"DISENGAGE", "disengage", 0);

registerCoreMember(DisplayItemCommand.class,
"DISPLAYITEM", "displayitem (remove) [<item>] [<location>] (duration:<#>)", 2);
"DISPLAYITEM", "displayitem (remove) [<item>] [<location>] (duration:<value>)", 2);

registerCoreMember(DropCommand.class,
"DROP", "drop [<item>/<entity>/<xp>] [<location>] (qty:<#>)", 1);

registerCoreMember(EngageCommand.class,
"ENGAGE", "engage (duration:<#>)", 0);
"ENGAGE", "engage (duration:<value>)", 0);

registerCoreMember(EngraveCommand.class,
"ENGRAVE", "engrave (set/remove)", 0);
Expand Down Expand Up @@ -146,10 +146,10 @@ public void registerCoreMembers() {
"FISH", "fish (catchfish) (stop) (<location>) (catchpercent:<#>)", 1);

registerCoreMember(FlagCommand.class,
"FLAG", "flag ({player}/npc/global) [<name>([<#>])](:<action>)[:<value>] (duration:<#>)", 1);
"FLAG", "flag ({player}/npc/global) [<name>([<#>])](:<action>)[:<value>] (duration:<value>)", 1);

registerCoreMember(FlyCommand.class,
"FLY", "fly (cancel) [entities:<entity>|...] (origin:<location>) (destinations:<location>|...) (speed:<#.#>)", 1);
"FLY", "fly (cancel) [<entity>|...] (origin:<location>) (destinations:<location>|...) (speed:<#.#>)", 1);

registerCoreMember(FollowCommand.class,
"FOLLOW", "follow (stop) (lead:<#.#>)", 0);
Expand All @@ -167,13 +167,13 @@ public void registerCoreMembers() {
"HEAD", "head (player) [skin:<name>]", 0);

registerCoreMember(HealCommand.class,
"HEAL", "heal (<#.#>) (entities:<entity>|...)", 0);
"HEAL", "heal (<#.#>) (<entity>|...)", 0);

registerCoreMember(HealthCommand.class,
"HEALTH", "health (state:true/false/toggle) (set_max:<#>)", 1);

registerCoreMember(HurtCommand.class,
"HURT", "hurt (<#.#>) (entities:<entity>|...)", 0);
"HURT", "hurt (<#.#>) (<entity>|...)", 0);

registerCoreMember(IfCommand.class,
"IF", "if [<value>] (!)(<operator> <value>) (&&/|| ...) [<commands>] (else <commands>)", 2);
Expand All @@ -200,7 +200,7 @@ public void registerCoreMembers() {
"MIDI", "midi [file:<name>] [<location>/listeners:<player>|...] (tempo:<#.#>)", 1);

registerCoreMember(MountCommand.class,
"MOUNT", "mount (cancel) [entities:<entity>|...] (<location>)", 0);
"MOUNT", "mount (cancel) [<entity>|...] (<location>)", 0);

registerCoreMember(ModifyBlockCommand.class,
"MODIFYBLOCK", "modifyblock [<location>] [<block>] (radius:<#>) (height:<#>) (depth:<#>)", 2);
Expand Down Expand Up @@ -239,7 +239,7 @@ public void registerCoreMembers() {
"RANDOM", "random [<#>]", 1);

registerCoreMember(RemoveCommand.class,
"REMOVE", "remove [entities:<entity>|...] (region:<name>)", 0);
"REMOVE", "remove [<entity>|...] (region:<name>)", 0);

registerCoreMember(RenameCommand.class,
"RENAME", "rename [<npc>] [<name>]", 1);
Expand All @@ -248,7 +248,7 @@ public void registerCoreMembers() {
"RESET", "reset [fails/finishes/cooldown] (script:<name>)", 1);

registerCoreMember(RunCommand.class,
"RUN", "run [<script>] (path:<name>) (as:<player>/<npc>) (define:<element>|...) (id:<name>) (delay:<duration>) (loop) (qty:<#>)", 1);
"RUN", "run [<script>] (path:<name>) (as:<player>/<npc>) (define:<element>|...) (id:<name>) (delay:<value>) (loop) (qty:<#>)", 1);

registerCoreMember(RuntaskCommand.class,
"RUNTASK", "runtask [<name>] (instantly) (queue(:<name>)) (delay:<#>) (define:<element>|...)", 1);
Expand All @@ -260,7 +260,7 @@ public void registerCoreMembers() {
"SCRIBE", "scribe [script:<name>] (give/drop/equip) (<item>) (<location>)", 1);

registerCoreMember(ShootCommand.class,
"SHOOT", "shoot [entities:<entity>|...] (origin:<player>/<npc>) (destination:<location>) (speed:<#.#>) (script:<name>)", 1);
"SHOOT", "shoot [<entity>|...] (origin:<player>/<npc>) (destination:<location>) (speed:<#.#>) (duration:<value>) (script:<name>)", 1);

registerCoreMember(ShowFakeCommand.class,
"SHOWFAKE", "showfake [<material>] [<location>|...] (d:<duration>{10s})", 2);
Expand All @@ -272,7 +272,7 @@ public void registerCoreMembers() {
"SIT", "sit (<location>)", 0);

registerCoreMember(SpawnCommand.class,
"SPAWN", "spawn [entities:<entity>|...] (<location>) (target:<entity>)", 1);
"SPAWN", "spawn [<entity>|...] (<location>) (target:<entity>)", 1);

registerCoreMember(StandCommand.class,
"STAND", "stand", 0);
Expand All @@ -281,13 +281,13 @@ public void registerCoreMembers() {
"STRIKE", "strike (no_damage) [<location>]", 1);

registerCoreMember(SwitchCommand.class,
"SWITCH", "switch [<location>] (state:[{toggle}/on/off]) (duration:<#>)", 1);
"SWITCH", "switch [<location>] (state:[{toggle}/on/off]) (duration:<value>)", 1);

registerCoreMember(TakeCommand.class,
"TAKE", "take [money/iteminhand/<item>] (qty:<#>)", 1);

registerCoreMember(TeleportCommand.class,
"TELEPORT", "teleport (entities:<entity>|...) (<location>)", 1);
"TELEPORT", "teleport (<entity>|...) (<location>)", 1);

registerCoreMember(TimeCommand.class,
"TIME", "time [type:{global}/player] [<value>] (world:<name>)", 1);
Expand All @@ -302,7 +302,7 @@ public void registerCoreMembers() {
"VULNERABLE", "vulnerable (state:{true}/false/toggle)", 0);

registerCoreMember(WaitCommand.class,
"WAIT", "wait (duration:<#>) (queue:<name>)", 0);
"WAIT", "wait (duration:<value>) (queue:<name>)", 0);

registerCoreMember(WalkCommand.class,
"WALK, WALKTO", "walk [<location>] (speed:<#>) (auto_range)", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,27 @@ else if (!scriptEntry.hasObject("destination")
scriptEntry.addObject("destination", arg.asType(dLocation.class));
}

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

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

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

else if (!scriptEntry.hasObject("script")
&& arg.matchesArgumentType(dScript.class)) {
// add value
Expand All @@ -84,6 +99,8 @@ else if (!scriptEntry.hasObject("script")
// Use a default speed of 1.5 if one is not specified

scriptEntry.defaultObject("speed", new Element(1.5));
scriptEntry.defaultObject("height", new Element(0));
scriptEntry.defaultObject("duration", Duration.valueOf("80t"));

// Check to make sure required arguments have been filled

Expand All @@ -110,6 +127,8 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
List<dEntity> entities = (List<dEntity>) scriptEntry.getObject("entities");
final Element speed = (Element) scriptEntry.getObject("speed");
final dScript script = (dScript) scriptEntry.getObject("script");
final double height = ((Element) scriptEntry.getObject("height")).asDouble();
final int maxTicks = ((Duration) scriptEntry.getObject("duration")).getTicksAsInt() / 2;

// Report to dB
dB.report(getName(), aH.debugObj("origin", shooter) +
Expand Down Expand Up @@ -159,8 +178,8 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
int runs = 0;

public void run() {
if (runs < 40 && lastEntity.isValid())

if (runs < maxTicks && lastEntity.isValid())
{
Vector v1 = lastEntity.getLocation().toVector();
Vector v2 = destination.toVector();
Expand All @@ -174,15 +193,15 @@ public void run() {
if (Math.abs(v2.getX() - v1.getX()) < 2 && Math.abs(v2.getY() - v1.getY()) < 2
&& Math.abs(v2.getZ() - v1.getZ()) < 2) {

runs = 40;
runs = maxTicks;
}

// Check if the entity has collided with something
// using the most basic possible calculation

if (lastEntity.getLocation().add(v3).getBlock().getType().toString().equals("AIR") == false) {

runs = 40;
runs = maxTicks;
}
}
else {
Expand All @@ -194,9 +213,10 @@ public void run() {
{
Map<String, String> context = new HashMap<String, String>();
context.put("1", lastEntity.getLocation().getX() + "," + lastEntity.getLocation().getY() + "," + lastEntity.getLocation().getZ() + "," + lastEntity.getLocation().getWorld().getName());

context.put("2", "e@" + lastEntity.getEntityId());

((TaskScriptContainer) script.getContainer()).setSpeed(new Duration(0))
.runTaskScript(scriptEntry.getPlayer(), scriptEntry.getNPC(), context);
.runTaskScript(scriptEntry.getPlayer(), scriptEntry.getNPC(), context);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -722,15 +722,32 @@ public void entityShootBow(EntityShootBowEvent event) {

Map<String, Object> context = new HashMap<String, Object>();
Entity entity = event.getEntity();
String entityType = entity.getType().name();
Entity projectile = event.getProjectile();
context.put("entity", new dEntity(entity));

Player player = null;
dNPC npc = null;

if (CitizensAPI.getNPCRegistry().isNPC(entity)) {
npc = DenizenAPI.getDenizenNPC(CitizensAPI.getNPCRegistry().getNPC(entity));
context.put("entity", npc);
entityType = "npc";
}
else if (entity instanceof Player) {
player = (Player) entity;
context.put("entity", new dPlayer((Player) entity));
}
else {
context.put("entity", new dEntity(entity));
}

context.put("bow", new dItem(event.getBow()));
context.put("projectile", new dEntity(projectile));

String determination = doEvents(Arrays.asList
("entity shoots bow",
entity.getType().name() + " shoots bow"),
null, null, context);
entityType + " shoots bow"),
npc, player, context);

if (determination.toUpperCase().startsWith("CANCELLED")) {
event.setCancelled(true);
Expand Down

0 comments on commit 67d7b04

Please sign in to comment.