Skip to content

Commit

Permalink
EntityTag.strength property
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 6, 2021
1 parent 8140934 commit cc3613a
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
Expand Up @@ -124,6 +124,7 @@ public static void registerMainProperties() {
PropertyParser.registerProperty(EntitySize.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpeed.class, EntityTag.class);
PropertyParser.registerProperty(EntitySpell.class, EntityTag.class);
PropertyParser.registerProperty(EntityStrength.class, EntityTag.class);
PropertyParser.registerProperty(EntityTame.class, EntityTag.class);
PropertyParser.registerProperty(EntityTrades.class, EntityTag.class);
PropertyParser.registerProperty(EntityVillagerExperience.class, EntityTag.class);
Expand Down
@@ -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());
}
}
}

0 comments on commit cc3613a

Please sign in to comment.