/
StandCommand.java
87 lines (79 loc) · 3.11 KB
/
StandCommand.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.denizenscript.denizen.scripts.commands.npc;
import com.denizenscript.denizen.npc.traits.SleepingTrait;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.npc.traits.SittingTrait;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.denizencore.objects.ArgumentHelper;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import org.bukkit.entity.*;
public class StandCommand extends AbstractCommand {
public StandCommand() {
setName("stand");
setSyntax("stand");
setRequiredArguments(0, 0);
isProcedural = false;
}
// <--[command]
// @Name Stand
// @Syntax stand
// @Required 0
// @Maximum 0
// @Plugin Citizens
// @Short Causes the NPC to stand up from sitting or sleeping.
// @Group npc
//
// @Description
// Makes the linked NPC stop sitting or sleeping.
// To make them sit, see <@link command Sit>.
// To make them sleep, see <@link command Sleep>.
//
// @Tags
// None
//
// @Usage
// Make the linked NPC stand up.
// - stand
//
// -->
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
//stand should have no additional arguments
for (Argument arg : scriptEntry.getProcessedArgs()) {
arg.reportUnhandled();
}
if (!Utilities.entryHasNPC(scriptEntry)) {
throw new InvalidArgumentsException("This command requires a linked NPC!");
}
}
@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().getName() + " cannot sit or sleep.");
return;
}
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), ArgumentHelper.debugObj("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().getTrait(SittingTrait.class);
trait.stand();
npc.getCitizen().removeTrait(SittingTrait.class);
}
if (npc.getCitizen().hasTrait(SleepingTrait.class)) {
SleepingTrait trait = npc.getCitizen().getTrait(SleepingTrait.class);
trait.wakeUp();
npc.getCitizen().removeTrait(SleepingTrait.class);
}
}
}
}