Package net.aufdemrand.denizen.objects.properties.entity

Source Code of net.aufdemrand.denizen.objects.properties.entity.EntitySkeleton

package net.aufdemrand.denizen.objects.properties.entity;

import net.aufdemrand.denizen.objects.Element;
import net.aufdemrand.denizen.objects.Mechanism;
import net.aufdemrand.denizen.objects.dEntity;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.objects.properties.Property;
import net.aufdemrand.denizen.tags.Attribute;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Skeleton;

public class EntitySkeleton implements Property {

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

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

        else return new EntitySkeleton((dEntity) entity);
    }

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

    private EntitySkeleton(dEntity entity) {
        skeleton = entity;
    }

    dEntity skeleton;

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

    @Override
    public String getPropertyString() {
        return ((Skeleton)skeleton.getBukkitEntity()).getSkeletonType().name();
    }

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

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

    @Override
    public String getAttribute(Attribute attribute) {

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

        // <--[tag]
        // @attribute <e@entity.skeleton_type>
        // @returns Element(Boolean)
        // @mechanism dEntity.skeleton
        // @group properties
        // @description
        // If the entity is a skeleton, returns what type of skeleton it is.
        // Can return NORMAL or WITHER.
        // -->
        if (attribute.startsWith("skeleton_type"))
            return new Element(((Skeleton)skeleton.getBukkitEntity())
                    .getSkeletonType().name()).getAttribute(attribute.fulfill(1));

        return null;
    }

    @Override
    public void adjust(Mechanism mechanism) {

        // <--[mechanism]
        // @object dEntity
        // @name skeleton
        // @input Element(Boolean)
        // @description
        // Changes whether a skeleton is a normal or wither type skeleton.
        // @tags
        // <e@entity.skeleton_type>
        // -->

        if (mechanism.matches("skeleton") && mechanism.requireEnum(false, Skeleton.SkeletonType.values())) {
            ((Skeleton)skeleton.getBukkitEntity()).setSkeletonType(
                    Skeleton.SkeletonType.valueOf(mechanism.getValue().asString().toUpperCase()));
        }
    }
}
TOP

Related Classes of net.aufdemrand.denizen.objects.properties.entity.EntitySkeleton

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.