/
CreeperPoweredScriptEvent.java
83 lines (74 loc) · 2.67 KB
/
CreeperPoweredScriptEvent.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
package com.denizenscript.denizen.events.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.CreeperPowerEvent;
public class CreeperPoweredScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// creeper powered (because <'cause'>)
//
// @Group Entity
//
// @Location true
//
// @Cancellable true
//
// @Triggers when a creeper is struck by lightning and turned into a powered creeper.
//
// @Context
// <context.entity> returns the EntityTag of the creeper.
// <context.lightning> returns the EntityTag of the lightning.
// <context.cause> returns an ElementTag of the cause for the creeper being powered. Refer to <@link url https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/entity/CreeperPowerEvent.PowerCause.html>.
//
// -->
public CreeperPoweredScriptEvent() {
instance = this;
registerCouldMatcher("creeper powered (because <'cause'>)");
}
public static CreeperPoweredScriptEvent instance;
public EntityTag lightning;
public EntityTag entity;
public ElementTag cause;
public CreeperPowerEvent event;
@Override
public boolean matches(ScriptPath path) {
if (path.eventArgLowerAt(2).equals("because")
&& !path.eventArgLowerAt(3).equals(CoreUtilities.toLowerCase(cause.toString()))) {
return false;
}
if (!runInCheck(path, entity.getLocation())) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "CreeperPowered";
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("entity")) {
return entity;
}
else if (name.equals("lightning") && lightning != null) {
return lightning;
}
else if (name.equals("cause")) {
return cause;
}
return super.getContext(name);
}
@EventHandler
public void onCreeperPowered(CreeperPowerEvent event) {
lightning = new EntityTag(event.getLightning());
entity = new EntityTag(event.getEntity());
cause = new ElementTag(event.getCause().name());
this.event = event;
fire(event);
}
}