use of com.denizenscript.denizen.npc.traits.SleepingTrait in project Denizen-For-Bukkit by DenizenScript.
the class SleepCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (npc.getEntityType() != EntityType.PLAYER && !(npc.getEntity() instanceof Villager)) {
Debug.echoError("Only Player or villager type NPCs can sit!");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, location);
}
SleepingTrait trait = npc.getCitizen().getOrAddTrait(SleepingTrait.class);
if (location != null) {
trait.toSleep(location);
} else {
trait.toSleep();
}
if (!trait.isSleeping()) {
npc.getCitizen().removeTrait(SleepingTrait.class);
}
}
use of com.denizenscript.denizen.npc.traits.SleepingTrait in project Denizen-For-Bukkit by DenizenScript.
the class StandCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (!(npc.getEntity() instanceof Player || npc.getEntity() instanceof Sittable || npc.getEntity() instanceof Villager)) {
Debug.echoError("Entities of type " + npc.getEntityType().name() + " cannot sit or sleep.");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), db("npc", Utilities.getEntryNPC(scriptEntry)));
}
Entity entity = npc.getEntity();
if (entity instanceof Sittable) {
((Sittable) entity).setSitting(false);
} else {
if (npc.getCitizen().hasTrait(SittingTrait.class)) {
SittingTrait trait = npc.getCitizen().getOrAddTrait(SittingTrait.class);
trait.stand();
npc.getCitizen().removeTrait(SittingTrait.class);
}
if (npc.getCitizen().hasTrait(SleepingTrait.class)) {
SleepingTrait trait = npc.getCitizen().getOrAddTrait(SleepingTrait.class);
trait.wakeUp();
npc.getCitizen().removeTrait(SleepingTrait.class);
}
}
}
Aggregations