Commits

DerFrZocker authored and md_5 committed ed2cdfc3d47
#1070: Make Attribute an interface and align names with the new minecraft ones
No tags

src/main/java/org/bukkit/attribute/Attribute.java

Modified
1 1 package org.bukkit.attribute;
2 2
3 +import com.google.common.base.Preconditions;
4 +import com.google.common.collect.Lists;
5 +import java.util.Locale;
3 6 import org.bukkit.Bukkit;
4 7 import org.bukkit.Keyed;
5 8 import org.bukkit.NamespacedKey;
9 +import org.bukkit.Registry;
6 10 import org.bukkit.Translatable;
11 +import org.bukkit.util.OldEnum;
7 12 import org.jetbrains.annotations.NotNull;
8 13
9 14 /**
10 15 * Types of attributes which may be present on an {@link Attributable}.
11 16 */
12 -public enum Attribute implements Keyed, Translatable {
17 +public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable {
13 18
14 19 /**
15 20 * Maximum health of an Entity.
16 21 */
17 - GENERIC_MAX_HEALTH("max_health"),
22 + Attribute MAX_HEALTH = getAttribute("max_health");
18 23 /**
19 24 * Range at which an Entity will follow others.
20 25 */
21 - GENERIC_FOLLOW_RANGE("follow_range"),
26 + Attribute FOLLOW_RANGE = getAttribute("follow_range");
22 27 /**
23 28 * Resistance of an Entity to knockback.
24 29 */
25 - GENERIC_KNOCKBACK_RESISTANCE("knockback_resistance"),
30 + Attribute KNOCKBACK_RESISTANCE = getAttribute("knockback_resistance");
26 31 /**
27 32 * Movement speed of an Entity.
28 33 */
29 - GENERIC_MOVEMENT_SPEED("movement_speed"),
34 + Attribute MOVEMENT_SPEED = getAttribute("movement_speed");
30 35 /**
31 36 * Flying speed of an Entity.
32 37 */
33 - GENERIC_FLYING_SPEED("flying_speed"),
38 + Attribute FLYING_SPEED = getAttribute("flying_speed");
34 39 /**
35 40 * Attack damage of an Entity.
36 41 */
37 - GENERIC_ATTACK_DAMAGE("attack_damage"),
42 + Attribute ATTACK_DAMAGE = getAttribute("attack_damage");
38 43 /**
39 44 * Attack knockback of an Entity.
40 45 */
41 - GENERIC_ATTACK_KNOCKBACK("attack_knockback"),
46 + Attribute ATTACK_KNOCKBACK = getAttribute("attack_knockback");
42 47 /**
43 48 * Attack speed of an Entity.
44 49 */
45 - GENERIC_ATTACK_SPEED("attack_speed"),
50 + Attribute ATTACK_SPEED = getAttribute("attack_speed");
46 51 /**
47 52 * Armor bonus of an Entity.
48 53 */
49 - GENERIC_ARMOR("armor"),
54 + Attribute ARMOR = getAttribute("armor");
50 55 /**
51 56 * Armor durability bonus of an Entity.
52 57 */
53 - GENERIC_ARMOR_TOUGHNESS("armor_toughness"),
58 + Attribute ARMOR_TOUGHNESS = getAttribute("armor_toughness");
54 59 /**
55 60 * The fall damage multiplier of an Entity.
56 61 */
57 - GENERIC_FALL_DAMAGE_MULTIPLIER("fall_damage_multiplier"),
62 + Attribute FALL_DAMAGE_MULTIPLIER = getAttribute("fall_damage_multiplier");
58 63 /**
59 64 * Luck bonus of an Entity.
60 65 */
61 - GENERIC_LUCK("luck"),
66 + Attribute LUCK = getAttribute("luck");
62 67 /**
63 68 * Maximum absorption of an Entity.
64 69 */
65 - GENERIC_MAX_ABSORPTION("max_absorption"),
70 + Attribute MAX_ABSORPTION = getAttribute("max_absorption");
66 71 /**
67 72 * The distance which an Entity can fall without damage.
68 73 */
69 - GENERIC_SAFE_FALL_DISTANCE("safe_fall_distance"),
74 + Attribute SAFE_FALL_DISTANCE = getAttribute("safe_fall_distance");
70 75 /**
71 76 * The relative scale of an Entity.
72 77 */
73 - GENERIC_SCALE("scale"),
78 + Attribute SCALE = getAttribute("scale");
74 79 /**
75 80 * The height which an Entity can walk over.
76 81 */
77 - GENERIC_STEP_HEIGHT("step_height"),
82 + Attribute STEP_HEIGHT = getAttribute("step_height");
78 83 /**
79 84 * The gravity applied to an Entity.
80 85 */
81 - GENERIC_GRAVITY("gravity"),
86 + Attribute GRAVITY = getAttribute("gravity");
82 87 /**
83 88 * Strength with which an Entity will jump.
84 89 */
85 - GENERIC_JUMP_STRENGTH("jump_strength"),
90 + Attribute JUMP_STRENGTH = getAttribute("jump_strength");
86 91 /**
87 92 * How long an entity remains burning after ingition.
88 93 */
89 - GENERIC_BURNING_TIME("burning_time"),
94 + Attribute BURNING_TIME = getAttribute("burning_time");
90 95 /**
91 96 * Resistance to knockback from explosions.
92 97 */
93 - GENERIC_EXPLOSION_KNOCKBACK_RESISTANCE("explosion_knockback_resistance"),
98 + Attribute EXPLOSION_KNOCKBACK_RESISTANCE = getAttribute("explosion_knockback_resistance");
94 99 /**
95 100 * Movement speed through difficult terrain.
96 101 */
97 - GENERIC_MOVEMENT_EFFICIENCY("movement_efficiency"),
102 + Attribute MOVEMENT_EFFICIENCY = getAttribute("movement_efficiency");
98 103 /**
99 104 * Oxygen use underwater.
100 105 */
101 - GENERIC_OXYGEN_BONUS("oxygen_bonus"),
106 + Attribute OXYGEN_BONUS = getAttribute("oxygen_bonus");
102 107 /**
103 108 * Movement speed through water.
104 109 */
105 - GENERIC_WATER_MOVEMENT_EFFICIENCY("water_movement_efficiency"),
110 + Attribute WATER_MOVEMENT_EFFICIENCY = getAttribute("water_movement_efficiency");
106 111 /**
107 112 * Range at which mobs will be tempted by items.
108 113 */
109 - GENERIC_TEMPT_RANGE("tempt_range"),
114 + Attribute TEMPT_RANGE = getAttribute("tempt_range");
110 115 /**
111 116 * The block reach distance of a Player.
112 117 */
113 - PLAYER_BLOCK_INTERACTION_RANGE("block_interaction_range"),
118 + Attribute BLOCK_INTERACTION_RANGE = getAttribute("block_interaction_range");
114 119 /**
115 120 * The entity reach distance of a Player.
116 121 */
117 - PLAYER_ENTITY_INTERACTION_RANGE("entity_interaction_range"),
122 + Attribute ENTITY_INTERACTION_RANGE = getAttribute("entity_interaction_range");
118 123 /**
119 124 * Block break speed of a Player.
120 125 */
121 - PLAYER_BLOCK_BREAK_SPEED("block_break_speed"),
126 + Attribute BLOCK_BREAK_SPEED = getAttribute("block_break_speed");
122 127 /**
123 128 * Mining speed for correct tools.
124 129 */
125 - PLAYER_MINING_EFFICIENCY("mining_efficiency"),
130 + Attribute MINING_EFFICIENCY = getAttribute("mining_efficiency");
126 131 /**
127 132 * Sneaking speed.
128 133 */
129 - PLAYER_SNEAKING_SPEED("sneaking_speed"),
134 + Attribute SNEAKING_SPEED = getAttribute("sneaking_speed");
130 135 /**
131 136 * Underwater mining speed.
132 137 */
133 - PLAYER_SUBMERGED_MINING_SPEED("submerged_mining_speed"),
138 + Attribute SUBMERGED_MINING_SPEED = getAttribute("submerged_mining_speed");
134 139 /**
135 140 * Sweeping damage.
136 141 */
137 - PLAYER_SWEEPING_DAMAGE_RATIO("sweeping_damage_ratio"),
142 + Attribute SWEEPING_DAMAGE_RATIO = getAttribute("sweeping_damage_ratio");
138 143 /**
139 144 * Chance of a zombie to spawn reinforcements.
140 145 */
141 - ZOMBIE_SPAWN_REINFORCEMENTS("spawn_reinforcements");
146 + Attribute SPAWN_REINFORCEMENTS = getAttribute("spawn_reinforcements");
142 147
143 - private final NamespacedKey key;
144 -
145 - private Attribute(String key) {
146 - this.key = NamespacedKey.minecraft(key);
148 + @NotNull
149 + private static Attribute getAttribute(@NotNull String key) {
150 + return Registry.ATTRIBUTE.getOrThrow(NamespacedKey.minecraft(key));
147 151 }
148 152
153 + /**
154 + * @param name of the attribute.
155 + * @return the attribute with the given name.
156 + * @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
157 + */
149 158 @NotNull
150 - @Override
151 - public NamespacedKey getKey() {
152 - return key;
159 + @Deprecated(since = "1.21.3")
160 + static Attribute valueOf(@NotNull String name) {
161 + Attribute attribute = Bukkit.getUnsafe().get(Registry.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
162 + Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name);
163 + return attribute;
153 164 }
154 165
166 + /**
167 + * @return an array of all known attributes.
168 + * @deprecated use {@link Registry#iterator()}.
169 + */
155 170 @NotNull
156 - @Override
157 - public String getTranslationKey() {
158 - return Bukkit.getUnsafe().getTranslationKey(this);
171 + @Deprecated(since = "1.21.3")
172 + static Attribute[] values() {
173 + return Lists.newArrayList(Registry.ATTRIBUTE).toArray(new Attribute[0]);
159 174 }
160 175 }

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut