|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Jake Potrebic <jake.m.potrebic@gmail.com> |
| 3 | +Date: Thu, 27 May 2021 21:58:33 -0700 |
| 4 | +Subject: [PATCH] More PotionEffectType API |
| 5 | + |
| 6 | + |
| 7 | +diff --git a/src/main/java/org/bukkit/Registry.java b/src/main/java/org/bukkit/Registry.java |
| 8 | +index a696fcaffa03af9e6c92e2ef3e12b38eb59e5db4..6242336de18fdd708cc3d7b745cbbace13140bc0 100644 |
| 9 | +--- a/src/main/java/org/bukkit/Registry.java |
| 10 | ++++ b/src/main/java/org/bukkit/Registry.java |
| 11 | +@@ -189,6 +189,27 @@ public interface Registry<T extends Keyed> extends Iterable<T> { |
| 12 | + return GameEvent.getByKey(key); |
| 13 | + } |
| 14 | + }; |
| 15 | ++ // Paper start |
| 16 | ++ /** |
| 17 | ++ * Potion effect types. |
| 18 | ++ * |
| 19 | ++ * @see org.bukkit.potion.PotionEffectType |
| 20 | ++ */ |
| 21 | ++ Registry<org.bukkit.potion.PotionEffectType> POTION_EFFECT_TYPE = new Registry<org.bukkit.potion.PotionEffectType>() { |
| 22 | ++ |
| 23 | ++ @Nullable |
| 24 | ++ @Override |
| 25 | ++ public org.bukkit.potion.PotionEffectType get(@NotNull NamespacedKey key) { |
| 26 | ++ return org.bukkit.potion.PotionEffectType.getByKey(key); |
| 27 | ++ } |
| 28 | ++ |
| 29 | ++ @NotNull |
| 30 | ++ @Override |
| 31 | ++ public Iterator<org.bukkit.potion.PotionEffectType> iterator() { |
| 32 | ++ return Arrays.stream(org.bukkit.potion.PotionEffectType.values()).iterator(); |
| 33 | ++ } |
| 34 | ++ }; |
| 35 | ++ // Paper end |
| 36 | + |
| 37 | + /** |
| 38 | + * Get the object by its key. |
| 39 | +diff --git a/src/main/java/org/bukkit/potion/PotionEffectType.java b/src/main/java/org/bukkit/potion/PotionEffectType.java |
| 40 | +index 22c28a503732671bc84c51372262e909d035c1fa..06e0f13d658b63b1fa984abb515eb0de704f9215 100644 |
| 41 | +--- a/src/main/java/org/bukkit/potion/PotionEffectType.java |
| 42 | ++++ b/src/main/java/org/bukkit/potion/PotionEffectType.java |
| 43 | +@@ -14,7 +14,7 @@ import org.jetbrains.annotations.Nullable; |
| 44 | + /** |
| 45 | + * Represents a type of potion and its effect on an entity. |
| 46 | + */ |
| 47 | +-public abstract class PotionEffectType implements Keyed { |
| 48 | ++public abstract class PotionEffectType implements Keyed, net.kyori.adventure.translation.Translatable { // Paper - implement Translatable |
| 49 | + /** |
| 50 | + * Increases movement speed. |
| 51 | + */ |
| 52 | +@@ -358,4 +358,56 @@ public abstract class PotionEffectType implements Keyed { |
| 53 | + public static PotionEffectType[] values() { |
| 54 | + return Arrays.copyOfRange(byId, 1, byId.length); |
| 55 | + } |
| 56 | ++ // Paper start |
| 57 | ++ /** |
| 58 | ++ * Gets the effect attributes in an immutable map. |
| 59 | ++ * |
| 60 | ++ * @return the attribute map |
| 61 | ++ */ |
| 62 | ++ public abstract @NotNull Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> getEffectAttributes(); |
| 63 | ++ |
| 64 | ++ /** |
| 65 | ++ * Gets the true modifier amount based on the effect amplifier. |
| 66 | ++ * |
| 67 | ++ * @param attribute the attribute |
| 68 | ++ * @param effectAmplifier the effect amplifier (0 indexed) |
| 69 | ++ * @return the modifier amount |
| 70 | ++ * @throws IllegalArgumentException if the supplied attribute is not present in the map from {@link #getEffectAttributes()} |
| 71 | ++ */ |
| 72 | ++ public abstract double getAttributeModifierAmount(@NotNull org.bukkit.attribute.Attribute attribute, int effectAmplifier); |
| 73 | ++ |
| 74 | ++ /** |
| 75 | ++ * Gets the category of this effect |
| 76 | ++ * |
| 77 | ++ * @return the category |
| 78 | ++ */ |
| 79 | ++ public abstract @NotNull PotionEffectType.Category getEffectCategory(); |
| 80 | ++ |
| 81 | ++ /** |
| 82 | ++ * Category of {@link PotionEffectType}s |
| 83 | ++ */ |
| 84 | ++ public enum Category { |
| 85 | ++ |
| 86 | ++ BENEFICIAL(net.kyori.adventure.text.format.NamedTextColor.BLUE), |
| 87 | ++ HARMFUL(net.kyori.adventure.text.format.NamedTextColor.RED), |
| 88 | ++ NEUTRAL(net.kyori.adventure.text.format.NamedTextColor.BLUE); |
| 89 | ++ |
| 90 | ++ private final net.kyori.adventure.text.format.TextColor color; |
| 91 | ++ |
| 92 | ++ Category(net.kyori.adventure.text.format.TextColor color) { |
| 93 | ++ this.color = color; |
| 94 | ++ } |
| 95 | ++ |
| 96 | ++ /** |
| 97 | ++ * Gets the text color used when displaying potions |
| 98 | ++ * of this category. |
| 99 | ++ * |
| 100 | ++ * @return the text color |
| 101 | ++ */ |
| 102 | ++ @NotNull |
| 103 | ++ public net.kyori.adventure.text.format.TextColor getColor() { |
| 104 | ++ return color; |
| 105 | ++ } |
| 106 | ++ } |
| 107 | ++ // Paper end |
| 108 | + } |
| 109 | +diff --git a/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java b/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java |
| 110 | +index c3a86bb1910158a8d13a675dfa7236dd6a3f397c..a7653806c0fa76f4b3342ea199fe892c514a4c27 100644 |
| 111 | +--- a/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java |
| 112 | ++++ b/src/main/java/org/bukkit/potion/PotionEffectTypeWrapper.java |
| 113 | +@@ -40,4 +40,30 @@ public class PotionEffectTypeWrapper extends PotionEffectType { |
| 114 | + public Color getColor() { |
| 115 | + return getType().getColor(); |
| 116 | + } |
| 117 | ++ // Paper start |
| 118 | ++ @Override |
| 119 | ++ public @NotNull org.bukkit.NamespacedKey getKey() { |
| 120 | ++ return this.getType().getKey(); |
| 121 | ++ } |
| 122 | ++ |
| 123 | ++ @Override |
| 124 | ++ public @NotNull java.util.Map<org.bukkit.attribute.Attribute, org.bukkit.attribute.AttributeModifier> getEffectAttributes() { |
| 125 | ++ return this.getType().getEffectAttributes(); |
| 126 | ++ } |
| 127 | ++ |
| 128 | ++ @Override |
| 129 | ++ public double getAttributeModifierAmount(@NotNull org.bukkit.attribute.Attribute attribute, int effectAmplifier) { |
| 130 | ++ return this.getType().getAttributeModifierAmount(attribute, effectAmplifier); |
| 131 | ++ } |
| 132 | ++ |
| 133 | ++ @Override |
| 134 | ++ public @NotNull PotionEffectType.Category getEffectCategory() { |
| 135 | ++ return this.getType().getEffectCategory(); |
| 136 | ++ } |
| 137 | ++ |
| 138 | ++ @Override |
| 139 | ++ public @NotNull String translationKey() { |
| 140 | ++ return this.getType().translationKey(); |
| 141 | ++ } |
| 142 | ++ // Paper end |
| 143 | + } |
0 commit comments