forked from elBukkit/EffectLib
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPlotEffect.java
More file actions
111 lines (85 loc) · 2.9 KB
/
PlotEffect.java
File metadata and controls
111 lines (85 loc) · 2.9 KB
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
package de.slikey.effectlib.effect;
import java.util.Set;
import java.util.Arrays;
import java.util.HashSet;
import org.bukkit.Particle;
import org.bukkit.Location;
import de.slikey.effectlib.Effect;
import de.slikey.effectlib.EffectType;
import de.slikey.effectlib.EffectManager;
import de.slikey.effectlib.math.EquationStore;
import de.slikey.effectlib.math.EquationTransform;
public class PlotEffect extends Effect {
private final static String[] _variables = {"t", "i"};
private final static Set<String> variables = new HashSet<>(Arrays.asList(_variables));
/**
* The equation to use for x-values. If not set, the iteration count will be used.
*/
public String xEquation;
/**
* The equation to use for y-values. If not set, the iteration count will be used.
*/
public String yEquation;
/**
* The equation to use for y-values. If not set, 0 will be used.
*/
public String zEquation;
/**
* This is a shortcut to quickly scaling the x value.
*/
public double xScale = 1.0;
/**
* This is a shortcut to quickly scaling the y value.
*/
public double yScale = 1.0;
/**
* This is a shortcut to quickly scaling the z value.
*/
public double zScale = 1.0;
/**
* This will re-spawn particles as the plot moves to make a solid line.
*/
public boolean persistent = true;
private int step = 0;
public PlotEffect(EffectManager effectManager) {
super(effectManager);
type = EffectType.REPEATING;
particle = Particle.DUST;
period = 1;
iterations = 100;
}
@Override
public void onRun() {
int base = persistent ? 0 : step;
Location location;
if (getLocation() == null) {
cancel();
return;
}
double xOffset;
double yOffset;
double zOffset;
EquationTransform transform;
for (int i = base; i <= step; i++) {
location = getLocation().clone();
xOffset = step;
yOffset = step;
zOffset = 0;
if (xEquation != null && !xEquation.isEmpty()) {
transform = EquationStore.getInstance().getTransform(xEquation, variables);
xOffset = transform.get(i, maxIterations);
}
if (yEquation != null && !yEquation.isEmpty()) {
transform = EquationStore.getInstance().getTransform(yEquation, variables);
yOffset = transform.get(i, maxIterations);
}
if (zEquation != null && !zEquation.isEmpty()) {
transform = EquationStore.getInstance().getTransform(zEquation, variables);
zOffset = transform.get(i, maxIterations);
}
location.add(xOffset * xScale, yOffset * yScale, zOffset * zScale);
display(particle, location);
}
step++;
}
}