Skip to content

Commit

Permalink
patch up despawn command a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Dec 1, 2020
1 parent 69fc9d3 commit 111607d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
Expand Up @@ -1473,16 +1473,8 @@ public void adjust(Mechanism mechanism) {
getCitizen().getNavigator().getDefaultParameters().speedModifier(mechanism.getValue().asFloat());
}

// <--[mechanism]
// @object NPCTag
// @name despawn
// @input None
// @description
// Despawns the NPC.
// @tags
// <NPCTag.is_spawned>
// -->
if (mechanism.matches("despawn")) {
Deprecations.npcDespawnMech.warn(mechanism.context);
getCitizen().despawn(DespawnReason.PLUGIN);
}

Expand Down
Expand Up @@ -35,9 +35,8 @@ public DespawnCommand() {
// @Group npc
//
// @Description
// This command will temporarily despawn either the linked NPC or
// a list of other NPCs. Despawning means they are no longer visible
// or interactable, but they still exist and can be respawned.
// This command will temporarily despawn either the linked NPC or a list of other NPCs.
// Despawning means they are no longer visible or interactable, but they still exist and can be respawned.
//
// @Tags
// <NPCTag.is_spawned>
Expand All @@ -53,9 +52,7 @@ public DespawnCommand() {

@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {

for (Argument arg : scriptEntry.getProcessedArgs()) {

if (!scriptEntry.hasObject("npcs")
&& arg.matchesArgumentList(NPCTag.class)) {
scriptEntry.addObject("npcs", arg.asType(ListTag.class).filter(NPCTag.class, scriptEntry));
Expand All @@ -64,7 +61,6 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
arg.reportUnhandled();
}
}

if (!scriptEntry.hasObject("npcs")) {
if (Utilities.entryHasNPC(scriptEntry)) {
scriptEntry.addObject("npcs", Arrays.asList(Utilities.getEntryNPC(scriptEntry)));
Expand All @@ -73,24 +69,21 @@ public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException
throw new InvalidArgumentsException("Must specify a valid list of NPCs!");
}
}

}

@SuppressWarnings("unchecked")
@Override
public void execute(final ScriptEntry scriptEntry) {
List<NPCTag> npcs = (List<NPCTag>) scriptEntry.getObject("npcs");

if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(),
ArgumentHelper.debugObj("NPCs", npcs.toString()));
}

for (NPCTag npc : npcs) {
if (npc.getCitizen().hasTrait(Spawned.class)) {
npc.getCitizen().getOrAddTrait(Spawned.class).setSpawned(false);
}
if (npc.isSpawned()) {
if (npc.getCitizen().hasTrait(Spawned.class)) {
npc.getCitizen().getOrAddTrait(Spawned.class).setSpawned(false);
}
npc.getCitizen().despawn(DespawnReason.PLUGIN);
}
}
Expand Down
Expand Up @@ -116,7 +116,7 @@ public void submit(CommandContext args, final CommandSender sender) throws Comma
// '-s' enables/disables stacktraces generated by Denizen. We might ask you to enable this when problems arise.
// '-b' enables/disables the ScriptBuilder debug. When enabled, Denizen will show info on script and argument creation.
// Warning: Can be spammy.
// '-n' enables/disables debug trimming. When enabled, messages longer than 512 characters will be 'snipped'.
// '-n' enables/disables debug trimming. When enabled, messages longer than 1024 characters will be 'snipped'.
// '-i' enables/disables source information. When enabled, debug will show where it came from (when possible).
// '-p' enables/disables packet debug logging. When enabled, all packets sent to players (from anywhere) will be logged to console.
// '-f' enables/disables showing of future warnings. When enabled, future warnings (such as upcoming deprecations) will be displayed in console logs.
Expand Down

0 comments on commit 111607d

Please sign in to comment.