/
PlayerBeaconEffectScriptEvent.java
116 lines (104 loc) · 3.79 KB
/
PlayerBeaconEffectScriptEvent.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.denizenscript.denizen.paper.events;
import com.denizenscript.denizen.events.BukkitScriptEvent;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.objects.properties.item.ItemPotion;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.implementation.BukkitScriptEntryData;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.scripts.ScriptEntryData;
import com.destroystokyo.paper.event.block.BeaconEffectEvent;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
public class PlayerBeaconEffectScriptEvent extends BukkitScriptEvent implements Listener {
// <--[event]
// @Events
// player beacon effect applied
//
// @Regex ^on player beacon effect applied$
//
// @Location true
//
// @Plugin Paper
//
// @Group Paper
//
// @Cancellable true
//
// @Triggers when a beacon applies an effect to a player.
//
// @Context
// <context.location> returns the LocationTag of the beacon applying an effect.
// <context.effect> returns an ElementTag of the potion effect (in the same format as <@link tag EntityTag.list_effects>).
// <context.effect_type> returns an ElementTag of the effect type.
// <context.is_primary> returns an ElementTag(Boolean) of whether the beacon effect is the primary effect.
//
// @Determine
// ElementTag to change the applied potion effect (in the same format as <@link tag EntityTag.list_effects>).
//
// @Player Always.
//
// -->
public PlayerBeaconEffectScriptEvent() {
instance = this;
}
public static PlayerBeaconEffectScriptEvent instance;
public BeaconEffectEvent event;
@Override
public boolean couldMatch(ScriptPath path) {
return path.eventLower.startsWith("player beacon effect applied");
}
@Override
public boolean matches(ScriptPath path) {
if (!runInCheck(path, event.getPlayer().getLocation())) {
return false;
}
return super.matches(path);
}
@Override
public String getName() {
return "PlayerBeaconEffect";
}
@Override
public boolean applyDetermination(ScriptPath path, ObjectTag determinationObj) {
if (!isDefaultDetermination(determinationObj)) {
try {
event.setEffect(ItemPotion.parseEffect(determinationObj.toString()));
}
catch (Exception e) {
Debug.echoError(e);
}
return true;
}
return super.applyDetermination(path, determinationObj);
}
@Override
public ScriptEntryData getScriptEntryData() {
return new BukkitScriptEntryData(event.getPlayer());
}
@Override
public ObjectTag getContext(String name) {
if (name.equals("location")) {
return new LocationTag(event.getBlock().getLocation());
}
else if (name.equals("effect")) {
return new ElementTag(ItemPotion.stringifyEffect(event.getEffect()));
}
else if (name.equals("effect_type")) {
return new ElementTag(event.getEffect().getType().getName());
}
else if (name.equals("is_primary")) {
return new ElementTag(event.isPrimary());
}
return super.getContext(name);
}
@EventHandler
public void beaconEffectEvent(BeaconEffectEvent event) {
if (EntityTag.isNPC(event.getPlayer())) {
return;
}
this.event = event;
fire(event);
}
}