Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void registerCitizensCommands() {
registerCommand(FishCommand.class);
registerCommand(LookcloseCommand.class);
registerCommand(PauseCommand.class);
registerCommand(PauseCommand.ResumeCommand.class);
registerCommand(ResumeCommand.class);
registerCommand(PoseCommand.class);
registerCommand(PushableCommand.class);
registerCommand(SitCommand.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsRuntimeException;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear;
import com.denizenscript.denizencore.scripts.commands.generator.ArgName;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import net.citizensnpcs.trait.waypoint.Waypoints;
Expand All @@ -17,19 +18,12 @@

public class PauseCommand extends AbstractCommand {

public static class ResumeCommand extends PauseCommand {

public ResumeCommand() {
setName("resume");
setSyntax("resume [waypoints/activity] (<duration>)");
}
}

public PauseCommand() {
setName("pause");
setSyntax("pause [waypoints/activity] (<duration>)");
setRequiredArguments(1, 2);
isProcedural = false;
autoCompile();
}

// <--[command]
Expand Down Expand Up @@ -68,101 +62,53 @@ public PauseCommand() {
// - resume waypoints
// -->

// <--[command]
// @Name Resume
// @Syntax resume [waypoints/activity] (<duration>)
// @Required 1
// @Plugin Citizens
// @Short Resumes an NPC's waypoint navigation or goal activity temporarily or indefinitely.
// @Group npc
//
// @Description
// The resume command resumes an NPC's waypoint navigation or goal activity temporarily or indefinitely.
// This works along side <@link command pause>.
// See the documentation of the pause command for more details.
//
// @Tags
// <NPCTag.is_navigating>
//
// @Usage
// Use to pause an NPC's waypoint navigation and then resume it.
// - pause waypoints
// - resume waypoints
// -->
public static final Map<NPCData, Integer> durations = new HashMap<>();

private Map<String, Integer> durations = new HashMap<>();
public enum Type { ACTIVITY, WAYPOINTS, NAVIGATION }

enum PauseType {ACTIVITY, WAYPOINTS, NAVIGATION}

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry) {
if (arg.matchesArgumentType(DurationTag.class)
&& !scriptEntry.hasObject("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
}
else if (!scriptEntry.hasObject("pause_type")
&& arg.matchesEnum(PauseType.class)) {
scriptEntry.addObject("pause_type", arg.asElement());
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("pause_type")) {
throw new InvalidArgumentsException("Must specify a pause type!");
}
public static void autoExecute(ScriptEntry scriptEntry,
@ArgName("action") Type type,
@ArgName("duration") @ArgLinear @ArgDefaultNull DurationTag duration) {
executeToggle(scriptEntry, type, duration, true);
}

@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);
public static void executeToggle(ScriptEntry scriptEntry, Type type, DurationTag duration, boolean pause) {
if (!Utilities.entryHasNPC(scriptEntry)) {
throw new InvalidArgumentsRuntimeException("Need to provide an NPC");
}
pause(npc, pauseType, !scriptEntry.getCommandName().equalsIgnoreCase("RESUME"));
NPCData data = new NPCData(Utilities.getEntryNPC(scriptEntry), type);
toggle(data, pause);
if (duration != null) {
if (durations.containsKey(npc.getCitizen().getId() + pauseType.name())) {
if (durations.containsKey(data)) {
try {
Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(npc.getCitizen().getId() + pauseType.name()));
Denizen.getInstance().getServer().getScheduler().cancelTask(durations.get(data));
}
catch (Exception e) {
Debug.echoError(scriptEntry, "There was an error pausing that!");
Debug.echoError(scriptEntry, e);
}
}
Debug.echoDebug(scriptEntry, "Running delayed task: Unpause " + pauseType);
final NPCTag theNpc = npc;
final ScriptEntry se = scriptEntry;
durations.put(npc.getId() + pauseType.name(), Denizen.getInstance()
durations.put(data, Denizen.getInstance()
.getServer().getScheduler().scheduleSyncDelayedTask(Denizen.getInstance(),
() -> {
Debug.echoDebug(se, "Running delayed task: Pausing " + pauseType);
pause(theNpc, pauseType, false);

Debug.echoDebug(scriptEntry, "Running delayed task: " + (!pause ? "Pausing" : "Resuming") + " " + type);
toggle(data, !pause);
}, duration.getTicks()));
}
}

public void pause(NPCTag denizen, PauseType pauseType, boolean pause) {
switch (pauseType) {
case WAYPOINTS:
denizen.getCitizen().getOrAddTrait(Waypoints.class).getCurrentProvider().setPaused(pause);
public static void toggle(NPCData data, boolean pause) {
switch (data.type) {
case WAYPOINTS -> {
data.npc.getCitizen().getOrAddTrait(Waypoints.class).getCurrentProvider().setPaused(pause);
if (pause) {
denizen.getNavigator().cancelNavigation();
data.npc.getNavigator().cancelNavigation();
}
return;
case ACTIVITY:
denizen.getCitizen().getDefaultBehaviorController().setPaused(pause);
return;
case NAVIGATION:
// TODO: Finish this
}
case ACTIVITY -> data.npc.getCitizen().getDefaultBehaviorController().setPaused(pause);
case NAVIGATION -> { /* TODO IMPLEMENT */ }
}
}

public record NPCData(NPCTag npc, Type type) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.denizenscript.denizen.scripts.commands.npc;

import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.scripts.commands.generator.ArgDefaultNull;
import com.denizenscript.denizencore.scripts.commands.generator.ArgLinear;
import com.denizenscript.denizencore.scripts.commands.generator.ArgName;

public class ResumeCommand extends AbstractCommand {

public ResumeCommand() {
setName("resume");
setSyntax("resume [waypoints/activity] (<duration>)");
setRequiredArguments(1, 2);
isProcedural = false;
autoCompile();
}

// <--[command]
// @Name Resume
// @Syntax resume [waypoints/activity] (<duration>)
// @Required 1
// @Plugin Citizens
// @Short Resumes an NPC's waypoint navigation or goal activity temporarily or indefinitely.
// @Group npc
//
// @Description
// The resume command resumes an NPC's waypoint navigation or goal activity temporarily or indefinitely.
// This works along side <@link command pause>.
// See the documentation of the pause command for more details.
//
// @Tags
// <NPCTag.is_navigating>
//
// @Usage
// Use to pause an NPC's waypoint navigation and then resume it.
// - pause waypoints
// - resume waypoints
// -->

public static void autoExecute(ScriptEntry scriptEntry,
@ArgName("action") PauseCommand.Type type,
@ArgName("duration") @ArgLinear @ArgDefaultNull DurationTag duration) {
PauseCommand.executeToggle(scriptEntry, type, duration, false);
}
}