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);
}
}
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;
}
Aggregations