-
-
Notifications
You must be signed in to change notification settings - Fork 302
/
SnowmanTrait.java
69 lines (60 loc) · 2.11 KB
/
SnowmanTrait.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
package net.citizensnpcs.trait.versioned;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Snowman;
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.command.exception.CommandUsageException;
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("snowmantrait")
public class SnowmanTrait extends Trait {
@Persist("derp")
private boolean derp;
public SnowmanTrait() {
super("snowmantrait");
}
public boolean isDerp() {
return derp;
}
@Override
public void run() {
if (npc.getEntity() instanceof Snowman) {
((Snowman) npc.getEntity()).setDerp(derp);
}
}
public void setDerp(boolean derp) {
this.derp = derp;
}
public boolean toggleDerp() {
return this.derp = !this.derp;
}
@Command(
aliases = { "npc" },
usage = "snowman (-d[erp])",
desc = "Sets snowman modifiers.",
modifiers = { "snowman" },
min = 1,
max = 1,
flags = "d",
permission = "citizens.npc.snowman")
@Requirements(selected = true, ownership = true, types = { EntityType.SNOWMAN })
public static void snowman(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
SnowmanTrait trait = npc.getOrAddTrait(SnowmanTrait.class);
boolean hasArg = false;
if (args.hasFlag('d')) {
boolean isDerp = trait.toggleDerp();
Messaging.sendTr(sender, isDerp ? Messages.SNOWMAN_DERP_SET : Messages.SNOWMAN_DERP_STOPPED, npc.getName());
hasArg = true;
}
if (!hasArg) {
throw new CommandUsageException();
}
}
}