use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class PauseCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
DurationTag duration = scriptEntry.getObjectTag("duration");
ElementTag pauseTypeElement = scriptEntry.getElement("pause_type");
PauseType pauseType = PauseType.valueOf(pauseTypeElement.asString().toUpperCase());
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), duration, pauseTypeElement);
}
NPCTag npc = null;
if (Utilities.getEntryNPC(scriptEntry) != null) {
npc = Utilities.getEntryNPC(scriptEntry);
}
pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
if (duration != null) {
if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
try {
Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(npc.getCitizen().getId() + pauseType.name()));
} catch (Exception e) {
Debug.echoError(scriptEntry, "There was an error pausing that!");
Debug.echoError(scriptEntry, e);
}
}
Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType.toString());
final NPCTag theNpc = npc;
final ScriptEntry se = scriptEntry;
durations.put(npc.getId() + pauseType.name(), Denizen.getInstance().getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(), () -> {
Debug.echoDebug(se, "Running delayed task: Pausing " + pauseType.toString());
pause(theNpc, pauseType, false);
}, duration.getTicks()));
}
}
use of com.denizenscript.denizen.objects.NPCTag 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.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class TraitCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag toggle = scriptEntry.getElement("state");
ElementTag traitName = scriptEntry.getElement("trait");
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), traitName, toggle, db("npc", npcs));
}
Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(traitName.asString());
if (trait == null) {
Debug.echoError(scriptEntry, "Trait not found: " + traitName.asString());
return;
}
for (NPCTag npcTag : npcs) {
NPC npc = npcTag.getCitizen();
switch(Toggle.valueOf(toggle.asString())) {
case TRUE:
case ON:
if (npc.hasTrait(trait)) {
Debug.echoError(scriptEntry, "NPC already has trait '" + traitName.asString() + "'");
} else {
npc.addTrait(trait);
}
break;
case FALSE:
case OFF:
if (!npc.hasTrait(trait)) {
Debug.echoError(scriptEntry, "NPC does not have trait '" + traitName.asString() + "'");
} else {
npc.removeTrait(trait);
}
break;
case TOGGLE:
if (npc.hasTrait(trait)) {
npc.removeTrait(trait);
} else {
npc.addTrait(trait);
}
break;
}
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class WalkCommandCitizensEvents method checkHeld.
public void checkHeld(NavigationEvent e) {
if (e.getNPC() == null) {
return;
}
for (int i = 0; i < WalkCommand.held.size(); i++) {
ScriptEntry entry = WalkCommand.held.get(i);
List<NPCTag> tally = (List<NPCTag>) entry.getObject("tally");
if (tally == null) {
WalkCommand.held.remove(i--);
continue;
}
for (int x = 0; x < tally.size(); x++) {
if (!tally.get(x).isSpawned()) {
tally.remove(x--);
}
}
tally.remove(new NPCTag(e.getNPC()));
if (tally.isEmpty()) {
Bukkit.getScheduler().runTaskLater(Denizen.getInstance(), () -> entry.setFinished(true), 1);
WalkCommand.held.remove(i--);
}
}
}
use of com.denizenscript.denizen.objects.NPCTag in project Denizen-For-Bukkit by DenizenScript.
the class SitCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
LocationTag location = scriptEntry.getObjectTag("location");
NPCTag npc = Utilities.getEntryNPC(scriptEntry);
if (!(npc.getEntity() instanceof Player || npc.getEntity() instanceof Sittable)) {
Debug.echoError("Entities of type " + npc.getEntityType().getName() + " cannot sit.");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), npc, location);
}
Entity entity = npc.getEntity();
if (entity instanceof Sittable) {
((Sittable) entity).setSitting(true);
} else {
SittingTrait trait = npc.getCitizen().getOrAddTrait(SittingTrait.class);
if (location != null) {
trait.sit(location);
} else {
trait.sit();
}
}
}
Aggregations