Commits
DerFrZocker authored and md_5 committed 6dd5810888a
1 1 | package org.bukkit; |
2 2 | |
3 + | import com.google.common.base.Preconditions; |
4 + | import com.google.common.collect.Lists; |
3 5 | import java.util.Locale; |
6 + | import org.bukkit.util.OldEnum; |
4 7 | import org.jetbrains.annotations.NotNull; |
5 8 | |
6 9 | /** |
7 10 | * Represents a fluid type. |
8 11 | */ |
9 - | public enum Fluid implements Keyed { |
12 + | public interface Fluid extends OldEnum<Fluid>, Keyed { |
10 13 | |
14 + | /** |
15 + | * No fluid. |
16 + | */ |
17 + | Fluid EMPTY = getFluid("empty"); |
11 18 | /** |
12 19 | * Stationary water. |
13 20 | */ |
14 - | WATER, |
21 + | Fluid WATER = getFluid("water"); |
15 22 | /** |
16 23 | * Flowing water. |
17 24 | */ |
18 - | FLOWING_WATER, |
25 + | Fluid FLOWING_WATER = getFluid("flowing_water"); |
19 26 | /** |
20 27 | * Stationary lava. |
21 28 | */ |
22 - | LAVA, |
29 + | Fluid LAVA = getFluid("lava"); |
23 30 | /** |
24 31 | * Flowing lava. |
25 32 | */ |
26 - | FLOWING_LAVA; |
33 + | Fluid FLOWING_LAVA = getFluid("flowing_lava"); |
27 34 | |
28 - | private final NamespacedKey key; |
35 + | |
36 + | private static Fluid getFluid( String key) { |
37 + | return Registry.FLUID.getOrThrow(NamespacedKey.minecraft(key)); |
38 + | } |
29 39 | |
30 - | private Fluid() { |
31 - | this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT)); |
40 + | /** |
41 + | * @param name of the fluid. |
42 + | * @return the fluid with the given name. |
43 + | * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead. |
44 + | */ |
45 + | |
46 + | since = "1.21.3") ( |
47 + | static Fluid valueOf(String name) { |
48 + | Fluid fluid = Bukkit.getUnsafe().get(Registry.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); |
49 + | Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name); |
50 + | return fluid; |
32 51 | } |
33 52 | |
53 + | /** |
54 + | * @return an array of all known fluids. |
55 + | * @deprecated use {@link Registry#iterator()}. |
56 + | */ |
34 57 | |
35 - | |
36 - | public NamespacedKey getKey() { |
37 - | return key; |
58 + | since = "1.21.3") ( |
59 + | static Fluid[] values() { |
60 + | return Lists.newArrayList(Registry.FLUID).toArray(new Fluid[0]); |
38 61 | } |
39 62 | } |