|
4 | 4 | import org.bukkit.FireworkEffect; |
5 | 5 | import org.bukkit.FireworkEffect.Builder; |
6 | 6 | import org.bukkit.Location; |
| 7 | +import org.bukkit.Sound; |
7 | 8 | import org.bukkit.entity.EntityType; |
8 | 9 | import org.bukkit.entity.Firework; |
9 | | -import org.bukkit.event.Cancellable; |
10 | | -import org.bukkit.event.Event; |
11 | 10 | import org.bukkit.inventory.meta.FireworkMeta; |
| 11 | +import org.bukkit.util.Vector; |
12 | 12 |
|
13 | 13 | import de.slikey.effectlib.EffectManager; |
14 | 14 | import de.slikey.effectlib.EffectType; |
| 15 | +import de.slikey.effectlib.util.RandomUtils; |
15 | 16 |
|
16 | 17 | public class BigBangLocationEffect extends LocationEffect { |
17 | 18 |
|
| 19 | + public FireworkEffect firework; |
| 20 | + public int intensity = 2; |
| 21 | + public float radius = 2; |
| 22 | + public int explosions = 10; |
| 23 | + public int soundInterval = 5; |
| 24 | + protected int step = 0; |
| 25 | + |
18 | 26 | public BigBangLocationEffect(EffectManager effectManager, Location location) { |
19 | 27 | super(effectManager, location); |
20 | 28 | type = EffectType.REPEATING; |
21 | | - period = 40; |
22 | | - iterations = 20; |
23 | | - } |
| 29 | + period = 2; |
| 30 | + iterations = 400; |
24 | 31 |
|
25 | | - @Override |
26 | | - public void onRun() { |
27 | 32 | Builder b = FireworkEffect.builder(); |
28 | 33 | b.withColor(Color.RED).withColor(Color.ORANGE).withColor(Color.BLACK); |
29 | 34 | b.withFade(Color.BLACK); |
30 | 35 | b.trail(true); |
31 | | - FireworkEffect fe = b.build(); |
| 36 | + firework = b.build(); |
| 37 | + } |
32 | 38 |
|
33 | | - final Firework fw = (Firework) location.getWorld().spawnEntity(location, EntityType.FIREWORK); |
34 | | - fw.playEffect(org.bukkit.EntityEffect.WOLF_HEARTS); |
| 39 | + @Override |
| 40 | + public void onRun() { |
| 41 | + for (int i = 0; i < explosions; i++) { |
| 42 | + Vector v = RandomUtils.getRandomVector().multiply(radius); |
| 43 | + detonate(v); |
| 44 | + if (step % soundInterval == 0) |
| 45 | + location.getWorld().playSound(location, Sound.EXPLODE, 100, 1); |
| 46 | + } |
| 47 | + step++; |
| 48 | + } |
| 49 | + |
| 50 | + protected void detonate(Vector v) { |
| 51 | + final Firework fw = (Firework) location.getWorld().spawnEntity(location.add(v), EntityType.FIREWORK); |
| 52 | + location.subtract(v); |
35 | 53 | FireworkMeta meta = fw.getFireworkMeta(); |
36 | | - meta.setPower(10); |
37 | | - meta.addEffect(fe); |
| 54 | + meta.setPower(0); |
| 55 | + for (int i = 0; i < intensity; i++) { |
| 56 | + meta.addEffect(firework); |
| 57 | + } |
38 | 58 | fw.setFireworkMeta(meta); |
39 | | - |
40 | 59 | fw.detonate(); |
41 | 60 | } |
42 | | - |
43 | 61 | } |
0 commit comments