From c8a0abe8fdafe3af6ea722b0cff9fc4abf34e538 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 26 Jun 2018 21:34:40 -0400 Subject: [PATCH] RangedEntity API Allows you to determine if an entity is capable of ranged attacks, and to perform an attack. --- .../paper/entity/RangedEntity.java | 36 +++++++++++++++++++ .../org/bukkit/entity/AbstractSkeleton.java | 2 +- .../main/java/org/bukkit/entity/Drowned.java | 4 ++- .../java/org/bukkit/entity/Illusioner.java | 6 +++- .../main/java/org/bukkit/entity/Llama.java | 3 +- .../main/java/org/bukkit/entity/Piglin.java | 2 +- .../main/java/org/bukkit/entity/Pillager.java | 4 ++- .../main/java/org/bukkit/entity/Snowman.java | 4 ++- .../main/java/org/bukkit/entity/Witch.java | 4 ++- .../main/java/org/bukkit/entity/Wither.java | 2 +- 10 files changed, 58 insertions(+), 9 deletions(-) create mode 100644 paper-api/src/main/java/com/destroystokyo/paper/entity/RangedEntity.java diff --git a/paper-api/src/main/java/com/destroystokyo/paper/entity/RangedEntity.java b/paper-api/src/main/java/com/destroystokyo/paper/entity/RangedEntity.java new file mode 100644 index 0000000000..09c82908f6 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/entity/RangedEntity.java @@ -0,0 +1,36 @@ +package com.destroystokyo.paper.entity; + +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Mob; +import org.jspecify.annotations.NullMarked; + +@NullMarked +public interface RangedEntity extends Mob { + /** + * Attack the specified entity using a ranged attack. + * + * @param target the entity to target + * @param charge How "charged" the attack is (how far back the bow was pulled for Bow attacks). + * This should be a value between 0 and 1, represented as targetDistance/maxDistance. + */ + void rangedAttack(LivingEntity target, float charge); + + /** + * Sets that the Entity is "charging" up an attack, by raising its hands + * + * @param raiseHands Whether the entities hands are raised to charge attack + * @deprecated use {@link #setAggressive(boolean)} + */ + @Deprecated(since = "1.19.2") + void setChargingAttack(boolean raiseHands); + + /** + * Alias to {@link LivingEntity#isHandRaised()}, if the entity is charging an attack + * @return If entities hands are raised + * @deprecated use {@link #isHandRaised()} + */ + @Deprecated(since = "1.19.2") + default boolean isChargingAttack() { + return this.isHandRaised(); + } +} diff --git a/paper-api/src/main/java/org/bukkit/entity/AbstractSkeleton.java b/paper-api/src/main/java/org/bukkit/entity/AbstractSkeleton.java index 6ffacd3af2..2d81d07701 100644 --- a/paper-api/src/main/java/org/bukkit/entity/AbstractSkeleton.java +++ b/paper-api/src/main/java/org/bukkit/entity/AbstractSkeleton.java @@ -13,7 +13,7 @@ import org.jetbrains.annotations.NotNull; * of this type, instanceOf checks against the specific subtypes listed prior * are recommended. */ -public interface AbstractSkeleton extends Monster { +public interface AbstractSkeleton extends Monster, com.destroystokyo.paper.entity.RangedEntity { // Paper /** * Gets the current type of this skeleton. diff --git a/paper-api/src/main/java/org/bukkit/entity/Drowned.java b/paper-api/src/main/java/org/bukkit/entity/Drowned.java index 1dee177ae6..8d1ad9ef75 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Drowned.java +++ b/paper-api/src/main/java/org/bukkit/entity/Drowned.java @@ -1,6 +1,8 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; + /** * Drowned zombie. */ -public interface Drowned extends Zombie { } +public interface Drowned extends Zombie, RangedEntity { } // Paper diff --git a/paper-api/src/main/java/org/bukkit/entity/Illusioner.java b/paper-api/src/main/java/org/bukkit/entity/Illusioner.java index 7c92c431b3..14e6c5ee06 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Illusioner.java +++ b/paper-api/src/main/java/org/bukkit/entity/Illusioner.java @@ -1,6 +1,10 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; + /** * Represents an Illusioner "Illager". */ -public interface Illusioner extends Spellcaster { } +public interface Illusioner extends Spellcaster, RangedEntity { // Paper + +} diff --git a/paper-api/src/main/java/org/bukkit/entity/Llama.java b/paper-api/src/main/java/org/bukkit/entity/Llama.java index c438542985..d23226ccb0 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Llama.java +++ b/paper-api/src/main/java/org/bukkit/entity/Llama.java @@ -1,12 +1,13 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; import org.bukkit.inventory.LlamaInventory; import org.jetbrains.annotations.NotNull; /** * Represents a Llama. */ -public interface Llama extends ChestedHorse { +public interface Llama extends ChestedHorse, RangedEntity { // Paper /** * Represents the base color that the llama has. diff --git a/paper-api/src/main/java/org/bukkit/entity/Piglin.java b/paper-api/src/main/java/org/bukkit/entity/Piglin.java index b96e575522..6fdc0e0bb6 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Piglin.java +++ b/paper-api/src/main/java/org/bukkit/entity/Piglin.java @@ -8,7 +8,7 @@ import org.jetbrains.annotations.NotNull; /** * Represents a Piglin. */ -public interface Piglin extends PiglinAbstract, InventoryHolder { +public interface Piglin extends PiglinAbstract, InventoryHolder, com.destroystokyo.paper.entity.RangedEntity { // Paper /** * Get whether the piglin is able to hunt hoglins. diff --git a/paper-api/src/main/java/org/bukkit/entity/Pillager.java b/paper-api/src/main/java/org/bukkit/entity/Pillager.java index 9a2252fef5..11f38187fc 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Pillager.java +++ b/paper-api/src/main/java/org/bukkit/entity/Pillager.java @@ -1,8 +1,10 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; // Paper + import org.bukkit.inventory.InventoryHolder; /** * Illager entity. */ -public interface Pillager extends Illager, InventoryHolder { } +public interface Pillager extends Illager, InventoryHolder, RangedEntity { } // Paper diff --git a/paper-api/src/main/java/org/bukkit/entity/Snowman.java b/paper-api/src/main/java/org/bukkit/entity/Snowman.java index 818efe2a4d..10f8f6d45a 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Snowman.java +++ b/paper-api/src/main/java/org/bukkit/entity/Snowman.java @@ -1,9 +1,11 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; + /** * Represents a snowman entity */ -public interface Snowman extends Golem { +public interface Snowman extends Golem, RangedEntity { // Paper /** * Gets whether this snowman is in "derp mode", meaning it is not wearing a diff --git a/paper-api/src/main/java/org/bukkit/entity/Witch.java b/paper-api/src/main/java/org/bukkit/entity/Witch.java index 0ebd54df0b..6618f2129e 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Witch.java +++ b/paper-api/src/main/java/org/bukkit/entity/Witch.java @@ -1,9 +1,11 @@ package org.bukkit.entity; +import com.destroystokyo.paper.entity.RangedEntity; + /** * Represents a Witch */ -public interface Witch extends Raider { +public interface Witch extends Raider, RangedEntity { // Paper /** * Gets whether the witch is drinking a potion diff --git a/paper-api/src/main/java/org/bukkit/entity/Wither.java b/paper-api/src/main/java/org/bukkit/entity/Wither.java index b3a5d7a91e..87a814f63c 100644 --- a/paper-api/src/main/java/org/bukkit/entity/Wither.java +++ b/paper-api/src/main/java/org/bukkit/entity/Wither.java @@ -6,7 +6,7 @@ import org.jetbrains.annotations.Nullable; /** * Represents a Wither boss */ -public interface Wither extends Monster, Boss { +public interface Wither extends Monster, Boss, com.destroystokyo.paper.entity.RangedEntity { // Paper /** * {@inheritDoc}