-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
SneakingTrait.java
74 lines (60 loc) · 1.64 KB
/
SneakingTrait.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
package com.denizenscript.denizen.npc.traits;
import com.denizenscript.denizen.nms.NMSHandler;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.utilities.DenizenAPI;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Player;
import org.bukkit.event.Listener;
public class SneakingTrait extends Trait implements Listener {
@Persist("sneaking")
private boolean sneaking = false;
@Override
public void onSpawn() {
if (sneaking) {
sneak();
}
}
// <--[action]
// @Actions
// sneak
//
// @Triggers when the NPC starts sneaking.
//
// @Context
// None
//
// -->
/**
* Makes the NPC sneak
*/
public void sneak() {
new NPCTag(npc).action("sneak", null);
if (npc.getEntity().getType() != EntityType.PLAYER) {
return;
}
NMSHandler.getEntityHelper().setSneaking(((Player) npc.getEntity()), true);
sneaking = true;
}
/**
* Makes the NPC stand
*/
public void stand() {
// Notated in SittingTrait
new NPCTag(npc).action("stand", null);
NMSHandler.getEntityHelper().setSneaking(((Player) npc.getEntity()), false);
sneaking = false;
}
/**
* Checks if the NPC is currently sneaking
*
* @return boolean
*/
public boolean isSneaking() {
return sneaking;
}
public SneakingTrait() {
super("sneaking");
}
}