/
SitCommand.java
72 lines (58 loc) · 2.74 KB
/
SitCommand.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
package net.aufdemrand.denizen.scripts.commands.npc;
import net.aufdemrand.denizen.objects.dLocation;
import org.bukkit.entity.EntityType;
import net.aufdemrand.denizen.exceptions.CommandExecutionException;
import net.aufdemrand.denizen.exceptions.InvalidArgumentsException;
import net.aufdemrand.denizen.npc.traits.SittingTrait;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.scripts.commands.AbstractCommand;
import net.aufdemrand.denizen.objects.aH;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.debugging.dB.Messages;
import net.citizensnpcs.api.npc.NPC;
import org.bukkit.entity.Ocelot;
import org.bukkit.entity.Wolf;
public class SitCommand extends AbstractCommand {
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (aH.Argument arg : aH.interpret(scriptEntry.getArguments())) {
if (arg.matchesArgumentType(dLocation.class)
&& !scriptEntry.hasObject("location")) {
scriptEntry.addObject("location", arg.asType(dLocation.class));
}
else throw new InvalidArgumentsException(Messages.ERROR_UNKNOWN_ARGUMENT, arg.raw_value);
}
}
@Override
public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
dLocation location = (dLocation) scriptEntry.getObject("location");
if (scriptEntry.getNPC().getEntityType() != EntityType.PLAYER
&& scriptEntry.getNPC().getEntityType() != EntityType.OCELOT
&& scriptEntry.getNPC().getEntityType() != EntityType.WOLF) {
dB.echoError("...only Player, ocelot, or wolf type NPCs can sit!");
return;
}
if (scriptEntry.getNPC().getEntityType() == EntityType.OCELOT) {
((Ocelot)scriptEntry.getNPC().getEntity()).setSitting(true);
}
else if (scriptEntry.getNPC().getEntityType() == EntityType.WOLF) {
((Wolf)scriptEntry.getNPC().getEntity()).setSitting(true);
}
else {
SittingTrait trait = scriptEntry.getNPC().getCitizen().getTrait(SittingTrait.class);
if (!scriptEntry.getNPC().getCitizen().hasTrait(SittingTrait.class)) {
scriptEntry.getNPC().getCitizen().addTrait(SittingTrait.class);
dB.echoDebug("...added sitting trait");
}
if (trait.isSitting()) {
dB.echoError("...NPC is already sitting");
return;
}
if (location != null) {
trait.sit(location);
} else {
trait.sit();
}
}
}
}