Search in sources :

Example 1 with Mechanism

use of net.aufdemrand.denizencore.objects.Mechanism in project Denizen-For-Bukkit by DenizenScript.

the class CreateCommand method execute.

@Override
public void execute(final ScriptEntry scriptEntry) throws CommandExecutionException {
    Element name = (Element) scriptEntry.getObject("name");
    dEntity type = (dEntity) scriptEntry.getObject("entity_type");
    dLocation loc = (dLocation) scriptEntry.getObject("spawn_location");
    dList traits = (dList) scriptEntry.getObject("traits");
    dB.report(scriptEntry, getName(), name.debug() + type.debug() + (loc != null ? loc.debug() : "") + (traits != null ? traits.debug() : ""));
    dNPC created;
    if (!type.isGeneric() && type.isCitizensNPC()) {
        created = new dNPC(type.getDenizenNPC().getCitizen().clone());
        created.getCitizen().setName(name.asString());
    } else {
        created = dNPC.mirrorCitizensNPC(CitizensAPI.getNPCRegistry().createNPC(type.getBukkitEntityType(), name.asString()));
    }
    // Add the created NPC into the script entry so it can be utilized if need be.
    scriptEntry.addObject("created_npc", created);
    if (created.isSpawned()) {
        if (loc != null) {
            created.getCitizen().teleport(loc, PlayerTeleportEvent.TeleportCause.PLUGIN);
        } else {
            created.getCitizen().despawn();
        }
    } else {
        if (loc != null) {
            created.getCitizen().spawn(loc);
        }
    }
    if (traits != null) {
        for (String trait_name : traits) {
            Trait trait = CitizensAPI.getTraitFactory().getTrait(trait_name);
            if (trait != null) {
                created.getCitizen().addTrait(trait);
            } else {
                dB.echoError(scriptEntry.getResidingQueue(), "Could not add trait to NPC: " + trait_name);
            }
        }
    }
    for (Mechanism mechanism : type.getWaitingMechanisms()) {
        created.adjust(mechanism);
    }
}
Also used : net.aufdemrand.denizen.objects.dNPC(net.aufdemrand.denizen.objects.dNPC) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) Element(net.aufdemrand.denizencore.objects.Element) net.aufdemrand.denizencore.objects.dList(net.aufdemrand.denizencore.objects.dList) Trait(net.citizensnpcs.api.trait.Trait) net.aufdemrand.denizen.objects.dLocation(net.aufdemrand.denizen.objects.dLocation) Mechanism(net.aufdemrand.denizencore.objects.Mechanism)

Example 2 with Mechanism

use of net.aufdemrand.denizencore.objects.Mechanism in project Denizen-For-Bukkit by DenizenScript.

the class EntityScriptContainer method getEntityFrom.

public dEntity getEntityFrom(dPlayer player, dNPC npc) {
    dEntity entity = null;
    try {
        if (contains("ENTITY_TYPE")) {
            String entityType = TagManager.tag((getString("ENTITY_TYPE", "")), new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
            entity = dEntity.valueOf(entityType);
        } else {
            throw new Exception("Missing entity_type argument!");
        }
        Set<StringHolder> strings = getConfigurationSection("").getKeys(false);
        for (StringHolder string : strings) {
            if (!string.low.equals("entity_type") && !string.low.equals("type")) {
                String value = TagManager.tag((getString(string.low, "")), new BukkitTagContext(player, npc, false, null, shouldDebug(), new dScript(this)));
                entity.adjust(new Mechanism(new Element(string.low), new Element(value)));
            }
        }
        if (entity == null || entity.isUnique()) {
            return null;
        }
        entity.setEntityScript(getName());
    } catch (Exception e) {
        dB.echoError("Woah! An exception has been called with this entity script!");
        dB.echoError(e);
        entity = null;
    }
    return entity;
}
Also used : StringHolder(net.aufdemrand.denizencore.utilities.text.StringHolder) BukkitTagContext(net.aufdemrand.denizen.tags.BukkitTagContext) net.aufdemrand.denizen.objects.dEntity(net.aufdemrand.denizen.objects.dEntity) net.aufdemrand.denizencore.objects.dScript(net.aufdemrand.denizencore.objects.dScript) Element(net.aufdemrand.denizencore.objects.Element) Mechanism(net.aufdemrand.denizencore.objects.Mechanism)

Aggregations

net.aufdemrand.denizen.objects.dEntity (net.aufdemrand.denizen.objects.dEntity)2 Element (net.aufdemrand.denizencore.objects.Element)2 Mechanism (net.aufdemrand.denizencore.objects.Mechanism)2 net.aufdemrand.denizen.objects.dLocation (net.aufdemrand.denizen.objects.dLocation)1 net.aufdemrand.denizen.objects.dNPC (net.aufdemrand.denizen.objects.dNPC)1 BukkitTagContext (net.aufdemrand.denizen.tags.BukkitTagContext)1 net.aufdemrand.denizencore.objects.dList (net.aufdemrand.denizencore.objects.dList)1 net.aufdemrand.denizencore.objects.dScript (net.aufdemrand.denizencore.objects.dScript)1 StringHolder (net.aufdemrand.denizencore.utilities.text.StringHolder)1 Trait (net.citizensnpcs.api.trait.Trait)1