Skip to content

Commit

Permalink
Add duration.add, duration.sub
Browse files Browse the repository at this point in the history
<util.date.time.duration.sub[<p@mcmonkey4eva.last_played>].in_hours>
with '5.6875'.
  • Loading branch information
mcmonkey4eva committed Nov 26, 2014
1 parent 6d240b6 commit 3935a9a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Expand Up @@ -6,6 +6,7 @@
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.citizensnpcs.api.event.NPCSpawnEvent;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreatureSpawnEvent;
Expand Down Expand Up @@ -97,7 +98,9 @@ public void breakDown() {
// -->
@EventHandler
public void npcSpawn(NPCSpawnEvent event) {
creatureSpawn(new CreatureSpawnEvent(event.getNPC().getBukkitEntity(), CreatureSpawnEvent.SpawnReason.CUSTOM));
if (event.getNPC().getEntity() instanceof LivingEntity)
creatureSpawn(new CreatureSpawnEvent((LivingEntity)event.getNPC().getEntity(),
CreatureSpawnEvent.SpawnReason.CUSTOM));
}

@EventHandler
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/Duration.java
Expand Up @@ -419,6 +419,27 @@ public String getAttribute(Attribute attribute) {
return new Element(getTicks())
.getAttribute(attribute.fulfill(1));

// <--[tag]
// @attribute <d@duration.sub[<duration>]>
// @returns Element(Number)
// @description
// returns this duration minus another.
// -->
if (attribute.startsWith("sub") && attribute.hasContext(1)) {
return new Duration(getTicks() - Duration.valueOf(attribute.getContext(1)).getTicks())
.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <d@duration.sub[<duration>]>
// @returns Element(Number)
// @description
// returns this duration plus another.
// -->
if (attribute.startsWith("add") && attribute.hasContext(1)) {
return new Duration(getTicks() + Duration.valueOf(attribute.getContext(1)).getTicks())
.getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <d@duration.time>
// @returns Element(Number)
Expand Down

0 comments on commit 3935a9a

Please sign in to comment.