From 822d06fd4b3305a2f57b36816723e0d187c4cdac Mon Sep 17 00:00:00 2001 From: Bukkit/Spigot Date: Tue, 30 Apr 2019 21:12:59 +1000 Subject: [PATCH] SPIGOT-4819: Continue refactoring of Arrow-related APIs By: md_5 --- .../java/org/bukkit/entity/AbstractArrow.java | 114 ++++++++++++ .../main/java/org/bukkit/entity/Arrow.java | 167 ++++++++---------- .../java/org/bukkit/entity/EntityType.java | 2 +- .../java/org/bukkit/entity/SpectralArrow.java | 2 +- .../java/org/bukkit/entity/TippedArrow.java | 101 +---------- .../main/java/org/bukkit/entity/Trident.java | 2 +- 6 files changed, 198 insertions(+), 190 deletions(-) create mode 100644 paper-api/src/main/java/org/bukkit/entity/AbstractArrow.java diff --git a/paper-api/src/main/java/org/bukkit/entity/AbstractArrow.java b/paper-api/src/main/java/org/bukkit/entity/AbstractArrow.java new file mode 100644 index 0000000000..4460f6c9e6 --- /dev/null +++ b/paper-api/src/main/java/org/bukkit/entity/AbstractArrow.java @@ -0,0 +1,114 @@ +package org.bukkit.entity; + +import org.bukkit.block.Block; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Represents an arrow. + */ +public interface AbstractArrow extends Projectile { + + /** + * Gets the knockback strength for an arrow, which is the + * {@link org.bukkit.enchantments.Enchantment#KNOCKBACK KnockBack} level + * of the bow that shot it. + * + * @return the knockback strength value + */ + public int getKnockbackStrength(); + + /** + * Sets the knockback strength for an arrow. + * + * @param knockbackStrength the knockback strength value + */ + public void setKnockbackStrength(int knockbackStrength); + + /** + * Gets the base amount of damage this arrow will do. + * + * Defaults to 2.0 for a normal arrow with + * 0.5 * (1 + power level) added for arrows fired from + * enchanted bows. + * + * @return base damage amount + */ + public double getDamage(); + + /** + * Sets the base amount of damage this arrow will do. + * + * @param damage new damage amount + */ + public void setDamage(double damage); + + /** + * Gets whether this arrow is critical. + *

+ * Critical arrows have increased damage and cause particle effects. + *

+ * Critical arrows generally occur when a player fully draws a bow before + * firing. + * + * @return true if it is critical + */ + public boolean isCritical(); + + /** + * Sets whether or not this arrow should be critical. + * + * @param critical whether or not it should be critical + */ + public void setCritical(boolean critical); + + /** + * Gets whether this arrow is in a block or not. + *

+ * Arrows in a block are motionless and may be picked up by players. + * + * @return true if in a block + */ + public boolean isInBlock(); + + /** + * Gets the block to which this arrow is attached. + * + * @return the attached block or null if not attached + */ + @Nullable + public Block getAttachedBlock(); + + /** + * Gets the current pickup status of this arrow. + * + * @return the pickup status of this arrow. + */ + @NotNull + public PickupStatus getPickupStatus(); + + /** + * Sets the current pickup status of this arrow. + * + * @param status new pickup status of this arrow. + */ + public void setPickupStatus(@NotNull PickupStatus status); + + /** + * Represents the pickup status of this arrow. + */ + public enum PickupStatus { + /** + * The arrow cannot be picked up. + */ + DISALLOWED, + /** + * The arrow can be picked up. + */ + ALLOWED, + /** + * The arrow can only be picked up by players in creative mode. + */ + CREATIVE_ONLY + } +} diff --git a/paper-api/src/main/java/org/bukkit/entity/Arrow.java b/paper-api/src/main/java/org/bukkit/entity/Arrow.java index ef6e348b5f..ec8443b670 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Arrow.java +++ b/paper-api/src/main/java/org/bukkit/entity/Arrow.java @@ -1,114 +1,97 @@ package org.bukkit.entity; -import org.bukkit.block.Block; +import java.util.List; +import org.bukkit.Color; +import org.bukkit.potion.PotionData; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -/** - * Represents an arrow. - */ -public interface Arrow extends Projectile { +public interface Arrow extends AbstractArrow { /** - * Gets the knockback strength for an arrow, which is the - * {@link org.bukkit.enchantments.Enchantment#KNOCKBACK KnockBack} level - * of the bow that shot it. + * Sets the underlying potion data * - * @return the knockback strength value + * @param data PotionData to set the base potion state to */ - public int getKnockbackStrength(); + void setBasePotionData(@NotNull PotionData data); /** - * Sets the knockback strength for an arrow. + * Returns the potion data about the base potion * - * @param knockbackStrength the knockback strength value - */ - public void setKnockbackStrength(int knockbackStrength); - - /** - * Gets the base amount of damage this arrow will do. - * - * Defaults to 2.0 for a normal arrow with - * 0.5 * (1 + power level) added for arrows fired from - * enchanted bows. - * - * @return base damage amount - */ - public double getDamage(); - - /** - * Sets the base amount of damage this arrow will do. - * - * @param damage new damage amount - */ - public void setDamage(double damage); - - /** - * Gets whether this arrow is critical. - *

- * Critical arrows have increased damage and cause particle effects. - *

- * Critical arrows generally occur when a player fully draws a bow before - * firing. - * - * @return true if it is critical - */ - public boolean isCritical(); - - /** - * Sets whether or not this arrow should be critical. - * - * @param critical whether or not it should be critical - */ - public void setCritical(boolean critical); - - /** - * Gets whether this arrow is in a block or not. - *

- * Arrows in a block are motionless and may be picked up by players. - * - * @return true if in a block - */ - public boolean isInBlock(); - - /** - * Gets the block to which this arrow is attached. - * - * @return the attached block or null if not attached - */ - @Nullable - public Block getAttachedBlock(); - - /** - * Gets the current pickup status of this arrow. - * - * @return the pickup status of this arrow. + * @return a PotionData object */ @NotNull - public PickupStatus getPickupStatus(); + PotionData getBasePotionData(); /** - * Sets the current pickup status of this arrow. + * Gets the color of this arrow. * - * @param status new pickup status of this arrow. + * @return arrow color */ - public void setPickupStatus(@NotNull PickupStatus status); + @NotNull + Color getColor(); /** - * Represents the pickup status of this arrow. + * Sets the color of this arrow. Will be applied as a tint to its particles. + * + * @param color arrow color */ - public enum PickupStatus { - /** - * The arrow cannot be picked up. - */ - DISALLOWED, - /** - * The arrow can be picked up. - */ - ALLOWED, - /** - * The arrow can only be picked up by players in creative mode. - */ - CREATIVE_ONLY - } + void setColor(@NotNull Color color); + + /** + * Checks for the presence of custom potion effects. + * + * @return true if custom potion effects are applied + */ + boolean hasCustomEffects(); + + /** + * Gets an immutable list containing all custom potion effects applied to + * this arrow. + *

+ * Plugins should check that hasCustomEffects() returns true before calling + * this method. + * + * @return the immutable list of custom potion effects + */ + @NotNull + List getCustomEffects(); + + /** + * Adds a custom potion effect to this arrow. + * + * @param effect the potion effect to add + * @param overwrite true if any existing effect of the same type should be + * overwritten + * @return true if the effect was added as a result of this call + */ + boolean addCustomEffect(@NotNull PotionEffect effect, boolean overwrite); + + /** + * Removes a custom potion effect from this arrow. + * + * @param type the potion effect type to remove + * @return true if the an effect was removed as a result of this call + * @throws IllegalArgumentException if this operation would leave the Arrow + * in a state with no Custom Effects and PotionType.UNCRAFTABLE + */ + boolean removeCustomEffect(@NotNull PotionEffectType type); + + /** + * Checks for a specific custom potion effect type on this arrow. + * + * @param type the potion effect type to check for + * @return true if the potion has this effect + */ + boolean hasCustomEffect(@Nullable PotionEffectType type); + + /** + * Removes all custom potion effects from this arrow. + * + * @throws IllegalArgumentException if this operation would leave the Arrow + * in a state with no Custom Effects and PotionType.UNCRAFTABLE + */ + void clearCustomEffects(); } diff --git a/paper-api/src/main/java/org/bukkit/entity/EntityType.java b/paper-api/src/main/java/org/bukkit/entity/EntityType.java index 86a185a330..527cb045f3 100644 --- a/paper-api/src/main/java/org/bukkit/entity/EntityType.java +++ b/paper-api/src/main/java/org/bukkit/entity/EntityType.java @@ -65,7 +65,7 @@ public enum EntityType implements Keyed { /** * An arrow projectile; may get stuck in the ground. */ - ARROW("arrow", TippedArrow.class, 10), + ARROW("arrow", Arrow.class, 10), /** * A flying snowball. */ diff --git a/paper-api/src/main/java/org/bukkit/entity/SpectralArrow.java b/paper-api/src/main/java/org/bukkit/entity/SpectralArrow.java index 274c7304aa..b02ec168b5 100644 --- a/paper-api/src/main/java/org/bukkit/entity/SpectralArrow.java +++ b/paper-api/src/main/java/org/bukkit/entity/SpectralArrow.java @@ -3,7 +3,7 @@ package org.bukkit.entity; /** * Represents a spectral arrow. */ -public interface SpectralArrow extends Arrow { +public interface SpectralArrow extends AbstractArrow { /** * Returns the amount of time that this arrow will apply diff --git a/paper-api/src/main/java/org/bukkit/entity/TippedArrow.java b/paper-api/src/main/java/org/bukkit/entity/TippedArrow.java index 61846e8b7a..3193cc8a04 100644 --- a/paper-api/src/main/java/org/bukkit/entity/TippedArrow.java +++ b/paper-api/src/main/java/org/bukkit/entity/TippedArrow.java @@ -1,97 +1,8 @@ package org.bukkit.entity; -import java.util.List; -import org.bukkit.Color; -import org.bukkit.potion.PotionData; -import org.bukkit.potion.PotionEffect; -import org.bukkit.potion.PotionEffectType; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -public interface TippedArrow extends Arrow { - - /** - * Sets the underlying potion data - * - * @param data PotionData to set the base potion state to - */ - void setBasePotionData(@NotNull PotionData data); - - /** - * Returns the potion data about the base potion - * - * @return a PotionData object - */ - @NotNull - PotionData getBasePotionData(); - - /** - * Gets the color of this arrow. - * - * @return arrow color - */ - @NotNull - Color getColor(); - - /** - * Sets the color of this arrow. Will be applied as a tint to its particles. - * - * @param color arrow color - */ - void setColor(@NotNull Color color); - - /** - * Checks for the presence of custom potion effects. - * - * @return true if custom potion effects are applied - */ - boolean hasCustomEffects(); - - /** - * Gets an immutable list containing all custom potion effects applied to - * this arrow. - *

- * Plugins should check that hasCustomEffects() returns true before calling - * this method. - * - * @return the immutable list of custom potion effects - */ - @NotNull - List getCustomEffects(); - - /** - * Adds a custom potion effect to this arrow. - * - * @param effect the potion effect to add - * @param overwrite true if any existing effect of the same type should be - * overwritten - * @return true if the effect was added as a result of this call - */ - boolean addCustomEffect(@NotNull PotionEffect effect, boolean overwrite); - - /** - * Removes a custom potion effect from this arrow. - * - * @param type the potion effect type to remove - * @return true if the an effect was removed as a result of this call - * @throws IllegalArgumentException if this operation would leave the Arrow - * in a state with no Custom Effects and PotionType.UNCRAFTABLE - */ - boolean removeCustomEffect(@NotNull PotionEffectType type); - - /** - * Checks for a specific custom potion effect type on this arrow. - * - * @param type the potion effect type to check for - * @return true if the potion has this effect - */ - boolean hasCustomEffect(@Nullable PotionEffectType type); - - /** - * Removes all custom potion effects from this arrow. - * - * @throws IllegalArgumentException if this operation would leave the Arrow - * in a state with no Custom Effects and PotionType.UNCRAFTABLE - */ - void clearCustomEffects(); -} +/** + * @deprecated tipped status depends only on base potion type not being + * UNCRAFTABLE and effects being empty. + */ +@Deprecated +public interface TippedArrow extends Arrow { } diff --git a/paper-api/src/main/java/org/bukkit/entity/Trident.java b/paper-api/src/main/java/org/bukkit/entity/Trident.java index 7af949eacd..3379ef9bac 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Trident.java +++ b/paper-api/src/main/java/org/bukkit/entity/Trident.java @@ -3,4 +3,4 @@ package org.bukkit.entity; /** * Represents a thrown trident. */ -public interface Trident extends Arrow { } +public interface Trident extends AbstractArrow { }