Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add entity.marker tag and mechanism, fixes #1311
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityMarker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |