-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFireworkUtils.java
More file actions
69 lines (65 loc) · 2.03 KB
/
Copy pathFireworkUtils.java
File metadata and controls
69 lines (65 loc) · 2.03 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
package ru.cwcode.cwutils.entity;
import org.bukkit.Color;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.entity.Firework;
import org.bukkit.inventory.meta.FireworkMeta;
import ru.cwcode.cwutils.collections.CollectionUtils;
import ru.cwcode.cwutils.numbers.Rand;
public class FireworkUtils {
public static void spawnRandomFirework(final Location loc) {
final Firework firework = loc.getWorld().spawn(loc, Firework.class);
final FireworkMeta fireworkMeta = firework.getFireworkMeta();
final FireworkEffect effect = FireworkEffect.builder()
.with(CollectionUtils.getRandomArrayEntry(Type.values()))
.withColor(getColor(Rand.ofInt(17) + 1))
.withFade(getColor(Rand.ofInt(17) + 1))
.flicker(Rand.bool())
.trail(Rand.bool())
.build();
fireworkMeta.addEffect(effect);
fireworkMeta.setPower(Rand.ofInt(2) + 1);
firework.setFireworkMeta(fireworkMeta);
}
private static Color getColor(final int i) {
switch (i) {
case 1:
return Color.AQUA;
case 2:
return Color.BLACK;
case 3:
return Color.BLUE;
case 4:
return Color.FUCHSIA;
case 5:
return Color.GRAY;
case 6:
return Color.GREEN;
case 7:
return Color.LIME;
case 8:
return Color.MAROON;
case 9:
return Color.NAVY;
case 10:
return Color.OLIVE;
case 11:
return Color.ORANGE;
case 12:
return Color.PURPLE;
case 13:
return Color.RED;
case 14:
return Color.SILVER;
case 15:
return Color.TEAL;
case 16:
return Color.WHITE;
case 17:
return Color.YELLOW;
default:
return null;
}
}
}