-
-
Notifications
You must be signed in to change notification settings - Fork 44
/
SentinelAttackScriptEvent.java
79 lines (69 loc) · 2.25 KB
/
SentinelAttackScriptEvent.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
package com.denizenscript.depenizen.bukkit.events.sentinel;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.NPCTag;
import com.denizenscript.denizen.objects.PlayerTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.mcmonkey.sentinel.SentinelTrait;
import org.mcmonkey.sentinel.events.SentinelAttackEvent;
public class SentinelAttackScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// sentinel npc attacks
//
// @Regex ^on sentinel npc attacks$
//
// @Cancellable true
//
// @Triggers when a Sentinel-powered NPC attacks a target.
//
// @Context
// <context.entity> returns the entity that the NPC is attacking.
//
// @Plugin Depenizen, Sentinel
//
// @NPC Always.
//
// @Player When the attacked entity is a player.
//
// @Group Depenizen
//
// -->
public SentinelAttackScriptEvent() {
instance = this;
}
public static SentinelAttackScriptEvent instance;
public SentinelAttackEvent event;
public ObjectTag entity;
public NPCTag npc;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("sentinel npc attacks");
}
@Override
public String getName() {
return "SentinelAttack";
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(entity instanceof PlayerTag ? (PlayerTag) entity : null, npc);
}
@Override
public ObjectTag getContext(String name) {
if (name.startsWith("entity")) {
return entity;
}
return super.getContext(name);
}
@EventHandler
public void onSentinelAttack(SentinelAttackEvent event) {
npc = new NPCTag(event.getNPC());
entity = new EntityTag(event.getNPC().getOrAddTrait(SentinelTrait.class).chasing).getDenizenObject();
this.event = event;
fire(event);
}
}