/
EffectLibCommand.java
211 lines (174 loc) · 7.18 KB
/
EffectLibCommand.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
package com.denizenscript.depenizen.bukkit.commands.effectlib;
import com.denizenscript.denizencore.objects.Argument;
import com.denizenscript.depenizen.bukkit.bridges.EffectLibBridge;
import de.slikey.effectlib.EffectManager;
import de.slikey.effectlib.effect.ArcEffect;
import de.slikey.effectlib.effect.AtomEffect;
import de.slikey.effectlib.effect.BleedEffect;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizen.utilities.Utilities;
import com.denizenscript.denizencore.exceptions.InvalidArgumentsException;
import com.denizenscript.denizencore.objects.core.DurationTag;
import com.denizenscript.denizencore.scripts.ScriptEntry;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import org.bukkit.Location;
public class EffectLibCommand extends AbstractCommand {
// <--[command]
// @Name effectlib
// @Syntax effectlib (type:<effect name>) (duration:<duration>) (target:<entity>)
// @Group Depenizen
// @Plugin Depenizen, EffectLib
// @Required 1
// @Short Show custom effects using EffectLib
//
// @Description
// Use to show custom effects in a easier way using the config file in EffectLib.
// The effect names comes from the config file.
// Specify a location instead of a target to show the effect at a location instead.
//
// @Tags
// None
//
// @Usage
// Use to show a effect on the attached player in queue.
// - effeclib bleed duration:10s
//
// @Usage
// Use to show a effect on a target entity.
// - effeclib atom target:<player.target> duration:10s
//
// @Usage
// Use to show effect at a position of the player.
// - effeclib type:atom duration:10s location:<player.location>
//
// -->
private enum Action {
BLEED, ARC, ATOM
}
@Override
public void parseArgs(ScriptEntry scriptEntry) throws InvalidArgumentsException {
for (Argument arg : scriptEntry.getProcessedArgs()) {
if (!scriptEntry.hasObject("target")
&& arg.matchesPrefix("target")) {
scriptEntry.addObject("target", arg.asType(EntityTag.class));
}
else if (!scriptEntry.hasObject("duration")
&& arg.matchesPrefix("duration")) {
scriptEntry.addObject("duration", arg.asType(DurationTag.class));
}
else if (!scriptEntry.hasObject("location")
&& arg.matchesPrefix("location")) {
scriptEntry.addObject("location", arg.asElement());
}
else if (!scriptEntry.hasObject("action")
&& arg.matchesEnum(Action.values())) {
scriptEntry.addObject("action", Action.valueOf(arg.getValue().toUpperCase()));
}
else {
arg.reportUnhandled();
}
}
if (!scriptEntry.hasObject("action")) {
throw new InvalidArgumentsException("Effect not specified!");
}
if (!scriptEntry.hasObject("duration")) {
throw new InvalidArgumentsException("Duration not specified!");
}
if (!scriptEntry.hasObject("target")) {
if (Utilities.entryHasPlayer(scriptEntry)) {
scriptEntry.addObject("target", Utilities.getEntryPlayer(scriptEntry).getDenizenEntity());
}
}
}
@Override
public void execute(final ScriptEntry scriptEntry) {
EntityTag target = (EntityTag) scriptEntry.getObject("target");
Action action = (Action) scriptEntry.getObject("action");
DurationTag duration = (DurationTag) scriptEntry.getObject("duration");
LocationTag location = (LocationTag) scriptEntry.getObject("location");
// Report to dB
Debug.report(scriptEntry, getName(), (target != null ? target.debug() : "")
+ (action != null ? action.toString() : "")
+ (duration != null ? duration.debug() : "")
+ (location != null ? location.debug() : ""));
if (target == null && location == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Target not found!");
return;
}
if (action == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Effect type not specified!");
return;
}
if (duration == null) {
Debug.echoError(scriptEntry.getResidingQueue(), "Duration not specified!");
return;
}
int ticks = duration.getTicksAsInt();
EffectManager effectManager = new EffectManager(EffectLibBridge.instance.plugin);
// TODO: Find a better way to handle all effects and add custom ones as well
switch (action) {
case BLEED: {
BleedEffect effect = new BleedEffect(effectManager);
if (location == null) {
effect.setEntity(target.getBukkitEntity());
}
else {
effect.setLocation(new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()));
}
// Add a callback to the effect
effect.callback = new Runnable() {
@Override
public void run() {
scriptEntry.setFinished(true);
}
};
effect.iterations = ticks;
effect.start();
return;
}
case ARC: {
ArcEffect effect = new ArcEffect(effectManager);
if (location == null) {
effect.setEntity(target.getBukkitEntity());
}
else {
effect.setLocation(new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()));
}
// Add a callback to the effect
effect.callback = new Runnable() {
@Override
public void run() {
scriptEntry.setFinished(true);
}
};
effect.iterations = ticks;
effect.start();
return;
}
case ATOM: {
AtomEffect effect = new AtomEffect(effectManager);
if (location == null) {
effect.setEntity(target.getBukkitEntity());
}
else {
effect.setLocation(new Location(location.getWorld(), location.getX(), location.getY(), location.getZ()));
}
// Add a callback to the effect
effect.callback = new Runnable() {
@Override
public void run() {
scriptEntry.setFinished(true);
}
};
effect.iterations = ticks;
effect.start();
return;
}
default: {
Debug.echoError(scriptEntry.getResidingQueue(), "Effect type not found!");
}
}
}
}