use of com.denizenscript.denizencore.scripts.ScriptEntry in project Denizen-For-Bukkit by DenizenScript.
the class WalkCommand method checkHeld.
public void checkHeld(EntityTag entity) {
for (int i = 0; i < held.size(); i++) {
ScriptEntry entry = held.get(i);
List<EntityTag> waitForEntities = (List<EntityTag>) entry.getObject("entities");
if (waitForEntities == null) {
continue;
}
waitForEntities.remove(entity);
if (waitForEntities.isEmpty()) {
if (!entry.hasObject("tally") || ((List<NPCTag>) entry.getObject("tally")).isEmpty()) {
entry.setFinished(true);
held.remove(i);
i--;
}
}
}
}
use of com.denizenscript.denizencore.scripts.ScriptEntry 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.denizencore.scripts.ScriptEntry 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--);
}
}
}
Aggregations