Skip to content

Commit

Permalink
Add <e@entity.list_effects>
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Jun 25, 2015
1 parent ae51bee commit 1cfd873
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/main/java/net/aufdemrand/denizen/objects/dEntity.java
Expand Up @@ -1821,18 +1821,37 @@ else return new Element("null")
// Returns whether the entity has a specified effect.
// If no effect is specified, returns whether the entity has any effect.
// -->
// TODO: add list_effects ?
if (attribute.startsWith("has_effect")) {
Boolean returnElement = false;
boolean returnElement = false;
if (attribute.hasContext(1)) {
for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects())
if (effect.getType().equals(PotionEffectType.getByName(attribute.getContext(1))))
PotionEffectType effectType = PotionEffectType.getByName(attribute.getContext(1));
for (org.bukkit.potion.PotionEffect effect : getLivingEntity().getActivePotionEffects()) {
if (effect.getType().equals(effectType)) {
returnElement = true;
}
}
}
else if (!getLivingEntity().getActivePotionEffects().isEmpty()){
returnElement = true;
}
else if (!getLivingEntity().getActivePotionEffects().isEmpty()) returnElement = true;
return new Element(returnElement).getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <e@entity.list_effects>
// @returns dList
// @group attribute
// Returns the list of active potion effects on the entity, in the format
// li@TYPE,AMPLIFIER,DURATION|...
// -->
if (attribute.startsWith("list_effects")) {
dList effects = new dList();
for (PotionEffect effect : getLivingEntity().getActivePotionEffects()) {
effects.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + effect.getDuration() + "t");
}
return effects.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <e@entity.can_breed>
// @returns Element(Boolean)
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -31,6 +31,7 @@
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.map.MapView;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.BlockIterator;

import java.util.*;
Expand Down Expand Up @@ -811,6 +812,15 @@ else if (dEntity.matches(ent)) {
return null;
}

// workaround for <e@entity.list_effects>
if (attribute.startsWith("list_effects")) {
dList effects = new dList();
for (PotionEffect effect : getPlayerEntity().getActivePotionEffects()) {
effects.add(effect.getType().getName() + "," + effect.getAmplifier() + "," + effect.getDuration() + "t");
}
return effects.getAttribute(attribute.fulfill(1));
}

// <--[tag]
// @attribute <p@player.list>
// @returns dList(dPlayer)
Expand Down

0 comments on commit 1cfd873

Please sign in to comment.