Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
500a42c
commit 0e7f1e2
Showing
3 changed files
with
93 additions
and
26 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
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
92 changes: 92 additions & 0 deletions
92
src/main/java/net/aufdemrand/denizen/objects/properties/entity/EntityAI.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,92 @@ | ||
package net.aufdemrand.denizen.objects.properties.entity; | ||
|
||
import net.aufdemrand.denizen.objects.dEntity; | ||
import net.aufdemrand.denizen.utilities.entity.EntityMovement; | ||
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; | ||
|
||
public class EntityAI implements Property { | ||
|
||
public static boolean describes(dObject entity) { | ||
return entity instanceof dEntity | ||
&& ((dEntity) entity).isLivingEntity(); | ||
} | ||
|
||
public static EntityAI getFrom(dObject entity) { | ||
if (!describes(entity)) return null; | ||
|
||
else return new EntityAI((dEntity) entity); | ||
} | ||
|
||
|
||
/////////////////// | ||
// Instance Fields and Methods | ||
///////////// | ||
|
||
private EntityAI(dEntity ent) { | ||
entity = ent; | ||
} | ||
|
||
dEntity entity; | ||
|
||
///////// | ||
// Property Methods | ||
/////// | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return String.valueOf(!EntityMovement.isAIDisabled(entity.getBukkitEntity())); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "has_ai"; | ||
} | ||
|
||
|
||
/////////// | ||
// dObject Attributes | ||
//////// | ||
|
||
@Override | ||
public String getAttribute(Attribute attribute) { | ||
|
||
if (attribute == null) return "null"; | ||
|
||
// <--[tag] | ||
// @attribute <e@entity.has_ai> | ||
// @returns Element(Boolean) | ||
// @group attributes | ||
// @description | ||
// Returns whether the entity uses the default Minecraft | ||
// AI to roam and look around. | ||
// --> | ||
if (attribute.startsWith("has_ai")) | ||
return new Element(!EntityMovement.isAIDisabled(entity.getBukkitEntity())) | ||
.getAttribute(attribute.fulfill(1)); | ||
|
||
|
||
return null; | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object dEntity | ||
// @name has_ai | ||
// @input Element(Boolean) | ||
// @description | ||
// Sets whether this entity will use the default | ||
// Minecraft AI to roam and look around. | ||
// @tags | ||
// <e@entity.has_ai> | ||
// --> | ||
if ((mechanism.matches("has_ai") || mechanism.matches("toggle_ai")) && mechanism.requireBoolean()) { | ||
EntityMovement.toggleAI(entity.getBukkitEntity(), mechanism.getValue().asBoolean()); | ||
} | ||
} | ||
} |