-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
InvisibleTrait.java
62 lines (44 loc) · 1.75 KB
/
InvisibleTrait.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
package net.aufdemrand.denizen.npc.traits;
import net.citizensnpcs.api.persistence.Persist;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.trait.Toggleable;
import org.bukkit.event.Listener;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
// <--[language]
// @name Invisible Trait
// @group npc traits
// @description
// The invisible trait will allow a NPC to remain invisible, even after a server restart. It permanently applies
// the invisible potion effect. Use '/trait invisible' or the 'invisible' command to toggle this trait.
//
// Note that player-type NPCs must have '/npc playerlist' toggled to be turned invisible. This does not apply
// to mob-type NPCs. Once invisible, the player-type NPCs can be taken off the playerlist.
// -->
public class InvisibleTrait extends Trait implements Listener, Toggleable {
@Persist("")
private boolean invisible = false;
PotionEffect invis = new PotionEffect(PotionEffectType.INVISIBILITY, Integer.MAX_VALUE, 1);
public InvisibleTrait() {
super("invisible");
}
public void setInvisible(boolean invisible) {
this.invisible = invisible;
if (invisible) setInvisible();
else if (npc.isSpawned())
if (npc.getBukkitEntity().hasPotionEffect(PotionEffectType.INVISIBILITY))
npc.getBukkitEntity().removePotionEffect(PotionEffectType.INVISIBILITY);
}
private void setInvisible() {
invis.apply(npc.getBukkitEntity());
}
@Override
public void onSpawn() {
if (invisible) setInvisible();
}
@Override
public boolean toggle() {
setInvisible(!invisible);
return invisible;
}
}