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
8140934
commit cc3613a
Showing
2 changed files
with
84 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
83 changes: 83 additions & 0 deletions
83
plugin/src/main/java/com/denizenscript/denizen/objects/properties/entity/EntityStrength.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,83 @@ | ||
package com.denizenscript.denizen.objects.properties.entity; | ||
|
||
import com.denizenscript.denizen.objects.EntityTag; | ||
import com.denizenscript.denizencore.objects.Mechanism; | ||
import com.denizenscript.denizencore.objects.ObjectTag; | ||
import com.denizenscript.denizencore.objects.core.ElementTag; | ||
import com.denizenscript.denizencore.objects.properties.Property; | ||
import com.denizenscript.denizencore.objects.properties.PropertyParser; | ||
import org.bukkit.entity.Llama; | ||
|
||
public class EntityStrength implements Property { | ||
|
||
public static boolean describes(ObjectTag entity) { | ||
return entity instanceof EntityTag && ((EntityTag) entity).getBukkitEntity() instanceof Llama; | ||
} | ||
|
||
public static EntityStrength getFrom(ObjectTag entity) { | ||
if (!describes(entity)) { | ||
return null; | ||
} | ||
else { | ||
return new EntityStrength((EntityTag) entity); | ||
} | ||
} | ||
|
||
public static final String[] handledMechs = new String[] { | ||
"strength" | ||
}; | ||
|
||
private EntityStrength(EntityTag entity) { | ||
this.entity = entity; | ||
} | ||
|
||
EntityTag entity; | ||
|
||
public ElementTag getStrength() { | ||
return new ElementTag(((Llama) entity.getBukkitEntity()).getStrength()); | ||
} | ||
|
||
@Override | ||
public String getPropertyString() { | ||
return getStrength().asString(); | ||
} | ||
|
||
@Override | ||
public String getPropertyId() { | ||
return "strength"; | ||
} | ||
|
||
public static void registerTags() { | ||
|
||
// <--[tag] | ||
// @attribute <EntityTag.strength> | ||
// @returns ElementTag | ||
// @mechanism EntityTag.strength | ||
// @group properties | ||
// @description | ||
// Returns the strength of a Llama. A llama's inventory contains (strength times three) slots. | ||
// Can be from 1 to 5 (inclusive). | ||
// --> | ||
PropertyParser.<EntityStrength, ElementTag>registerTag(ElementTag.class, "strength", (attribute, object) -> { | ||
return object.getStrength(); | ||
}); | ||
} | ||
|
||
@Override | ||
public void adjust(Mechanism mechanism) { | ||
|
||
// <--[mechanism] | ||
// @object EntityTag | ||
// @name strength | ||
// @input ElementTag(Boolean) | ||
// @description | ||
// Sets the strength of a Llama. A llama's inventory contains (strength times three) slots. | ||
// Can be from 1 to 5 (inclusive). | ||
// @tags | ||
// <EntityTag.strength> | ||
// --> | ||
if (mechanism.matches("strength") && mechanism.requireInteger()) { | ||
((Llama) entity.getBukkitEntity()).setStrength(mechanism.getValue().asInt()); | ||
} | ||
} | ||
} |