Skip to content

Commit

Permalink
Add dentity.carries_chest property for #1005
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Apr 7, 2015
1 parent 54b7934 commit 9347140
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ public void onEnable() {
propertyParser.registerProperty(EntityAge.class, dEntity.class);
propertyParser.registerProperty(EntityAI.class, dEntity.class);
propertyParser.registerProperty(EntityAngry.class, dEntity.class);
propertyParser.registerProperty(EntityChestCarrier.class, dEntity.class);
propertyParser.registerProperty(EntityColor.class, dEntity.class);
propertyParser.registerProperty(EntityCritical.class, dEntity.class);
propertyParser.registerProperty(EntityElder.class, dEntity.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizencore.objects.Element;
import net.aufdemrand.denizencore.objects.Mechanism;
import net.aufdemrand.denizencore.objects.dObject;
import net.aufdemrand.denizencore.objects.properties.Property;
import net.aufdemrand.denizencore.tags.Attribute;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Horse;

public class EntityChestCarrier implements Property {

public static boolean describes(dObject entity) {
return entity instanceof dEntity
&& ((dEntity)entity).getBukkitEntityType() == EntityType.HORSE;
}

public static EntityChestCarrier getFrom(dObject entity) {
if (!describes(entity)) return null;

else return new EntityChestCarrier((dEntity) entity);
}

///////////////////
// Instance Fields and Methods
/////////////

private EntityChestCarrier(dEntity entity) {
this.entity = entity;
}

dEntity entity;

/////////
// Property Methods
///////

@Override
public String getPropertyString() {
return ((Horse)entity.getBukkitEntity()).isCarryingChest() ? "true": "false";
}

@Override
public String getPropertyId() {
return "carries_chest";
}

///////////
// dObject Attributes
////////

@Override
public String getAttribute(Attribute attribute) {

if (attribute == null) return "null";

// <--[tag]
// @attribute <e@entity.carries_chest>
// @returns Element(Boolean)
// @mechanism dEntity.carries_chest
// @group properties
// @description
// If the entity is an horse, returns whether it is carrying a chest.
// -->
if (attribute.startsWith("carries_chest"))
return new Element(((Horse)entity.getBukkitEntity()).isCarryingChest())
.getAttribute(attribute.fulfill(1));

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name carries_chest
// @input Element(Boolean)
// @description
// Changes whether a Horse carries a chest.
// @tags
// <e@entity.carries_chest>
// -->

if (mechanism.matches("carries_chest") && mechanism.requireBoolean()) {
((Horse)entity.getBukkitEntity()).setCarryingChest(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit 9347140

Please sign in to comment.