-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
GoatTrait.java
94 lines (83 loc) · 2.75 KB
/
GoatTrait.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
88
89
90
91
92
93
94
package net.citizensnpcs.trait.versioned;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Goat;
import net.citizensnpcs.api.command.Command;
import net.citizensnpcs.api.command.CommandContext;
import net.citizensnpcs.api.command.Requirements;
import net.citizensnpcs.api.command.exception.CommandException;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.TraitName;
import net.citizensnpcs.api.util.Messaging;
import net.citizensnpcs.util.Messages;
@TraitName("goattrait")
public class GoatTrait extends Trait {
@Persist
private boolean leftHorn = true;
@Persist
private boolean rightHorn = true;
public GoatTrait() {
super("goattrait");
}
public boolean isLeftHorn() {
return leftHorn;
}
public boolean isRightHorn() {
return rightHorn;
}
@Override
public void run() {
if (npc.isSpawned() && npc.getEntity() instanceof Goat) {
Goat goat = (Goat) npc.getEntity();
if (SUPPORTS_HORNS) {
try {
goat.setRightHorn(rightHorn);
goat.setLeftHorn(leftHorn);
} catch (Throwable t) {
SUPPORTS_HORNS = false;
}
}
}
}
public void setLeftHorn(boolean horn) {
this.leftHorn = horn;
}
public void setRightHorn(boolean horn) {
this.rightHorn = horn;
}
@Command(
aliases = { "npc" },
usage = "goat -l(eft) -r(ight) -n(either) -b(oth) horn",
desc = "Sets goat modifiers",
modifiers = { "goat" },
flags = "lrnb",
min = 1,
max = 1,
permission = "citizens.npc.goat")
@Requirements(selected = true, ownership = true, types = EntityType.GOAT)
public static void goat(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
GoatTrait trait = npc.getOrAddTrait(GoatTrait.class);
boolean left = trait.isLeftHorn(), right = trait.isRightHorn();
if (args.hasFlag('l')) {
left = !left;
}
if (args.hasFlag('r')) {
right = !right;
}
if (args.hasFlag('b')) {
left = right = true;
}
if (args.hasFlag('n')) {
left = right = false;
}
trait.setLeftHorn(left);
trait.setRightHorn(right);
String output = Messaging.tr(Messages.NPC_GOAT_HORNS_SET, npc.getName(), left, right);
if (!output.isEmpty()) {
Messaging.send(sender, output);
}
}
private static boolean SUPPORTS_HORNS = true;
}