Skip to content

Commit

Permalink
Add entity.marker tag and mechanism, fixes #1311
Browse files Browse the repository at this point in the history
  • Loading branch information
Morphan1 committed Mar 9, 2016
1 parent 06a48d6 commit 450739e
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/main/java/net/aufdemrand/denizen/Denizen.java
Expand Up @@ -778,6 +778,7 @@ public void onEnable() {
propertyParser.registerProperty(EntityItem.class, dEntity.class);
propertyParser.registerProperty(EntityJumpStrength.class, dEntity.class);
propertyParser.registerProperty(EntityKnockback.class, dEntity.class);
propertyParser.registerProperty(EntityMarker.class, dEntity.class);
propertyParser.registerProperty(EntityPainting.class, dEntity.class);
propertyParser.registerProperty(EntityPotion.class, dEntity.class);
propertyParser.registerProperty(EntityPowered.class, dEntity.class);
Expand Down
@@ -0,0 +1,101 @@
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.ArmorStand;
import org.bukkit.entity.EntityType;

public class EntityMarker implements Property {

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

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

else {
return new EntityMarker((dEntity) entity);
}
}

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

private EntityMarker(dEntity entity) {
dentity = entity;
}

dEntity dentity;

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

@Override
public String getPropertyString() {
if (!((ArmorStand) dentity.getBukkitEntity()).isMarker()) {
return null;
}
else {
return "true";
}
}

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

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

@Override
public String getAttribute(Attribute attribute) {

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

// <--[tag]
// @attribute <e@entity.marker>
// @returns Element(Boolean)
// @mechanism dEntity.marker
// @group properties
// @description
// If the entity is an armor stand, returns whether the armor stand is a marker.
// -->
if (attribute.startsWith("marker")) {
return new Element(((ArmorStand) dentity.getBukkitEntity()).isMarker())
.getAttribute(attribute.fulfill(1));
}

return null;
}

@Override
public void adjust(Mechanism mechanism) {

// <--[mechanism]
// @object dEntity
// @name marker
// @input Element(Boolean)
// @description
// Changes the marker state of an armor stand.
// @tags
// <e@entity.marker>
// -->

if (mechanism.matches("marker") && mechanism.requireBoolean()) {
((ArmorStand) dentity.getBukkitEntity()).setMarker(mechanism.getValue().asBoolean());
}
}
}

0 comments on commit 450739e

Please sign in to comment.