From f6e7cce2277db85da27ef1489d0f05f776dcacc5 Mon Sep 17 00:00:00 2001 From: Aikar Date: Tue, 26 Jun 2018 22:00:49 -0400 Subject: [PATCH] RangedEntity API Allows you to determine if an entity is capable of ranged attacks, and to perform an attack. --- .../paper/entity/CraftRangedEntity.java | 20 +++++++++++++++++++ .../entity/CraftAbstractSkeleton.java | 8 +++++++- .../craftbukkit/entity/CraftDrowned.java | 2 +- .../craftbukkit/entity/CraftIllusioner.java | 2 +- .../bukkit/craftbukkit/entity/CraftLlama.java | 2 +- .../craftbukkit/entity/CraftPiglin.java | 2 +- .../craftbukkit/entity/CraftPillager.java | 2 +- .../craftbukkit/entity/CraftSnowman.java | 2 +- .../bukkit/craftbukkit/entity/CraftWitch.java | 2 +- .../craftbukkit/entity/CraftWither.java | 2 +- 10 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 paper-server/src/main/java/com/destroystokyo/paper/entity/CraftRangedEntity.java diff --git a/paper-server/src/main/java/com/destroystokyo/paper/entity/CraftRangedEntity.java b/paper-server/src/main/java/com/destroystokyo/paper/entity/CraftRangedEntity.java new file mode 100644 index 0000000000..d7a8eb1b8f --- /dev/null +++ b/paper-server/src/main/java/com/destroystokyo/paper/entity/CraftRangedEntity.java @@ -0,0 +1,20 @@ +package com.destroystokyo.paper.entity; + +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.monster.RangedAttackMob; +import org.bukkit.craftbukkit.entity.CraftLivingEntity; +import org.bukkit.entity.LivingEntity; + +public interface CraftRangedEntity extends RangedEntity { + T getHandle(); + + @Override + default void rangedAttack(LivingEntity target, float charge) { + getHandle().performRangedAttack(((CraftLivingEntity) target).getHandle(), charge); + } + + @Override + default void setChargingAttack(boolean raiseHands) { + getHandle().setAggressive(raiseHands); + } +} diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java index db6ad6eea8..5ff5661864 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftAbstractSkeleton.java @@ -4,7 +4,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.AbstractSkeleton; import org.bukkit.entity.Skeleton; -public abstract class CraftAbstractSkeleton extends CraftMonster implements AbstractSkeleton { +public abstract class CraftAbstractSkeleton extends CraftMonster implements AbstractSkeleton, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftAbstractSkeleton(CraftServer server, net.minecraft.world.entity.monster.AbstractSkeleton entity) { super(server, entity); @@ -14,4 +14,10 @@ public abstract class CraftAbstractSkeleton extends CraftMonster implements Abst public void setSkeletonType(Skeleton.SkeletonType type) { throw new UnsupportedOperationException("Not supported."); } + // Paper start + @Override + public net.minecraft.world.entity.monster.AbstractSkeleton getHandle() { + return (net.minecraft.world.entity.monster.AbstractSkeleton) super.getHandle(); + } + // Paper end } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java index c0e59845a7..51fc4acae9 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftDrowned.java @@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.entity; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Drowned; -public class CraftDrowned extends CraftZombie implements Drowned { +public class CraftDrowned extends CraftZombie implements Drowned, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftDrowned(CraftServer server, net.minecraft.world.entity.monster.Drowned entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftIllusioner.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftIllusioner.java index 995c77ee53..5b2af80e58 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftIllusioner.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftIllusioner.java @@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.entity; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Illusioner; -public class CraftIllusioner extends CraftSpellcaster implements Illusioner { +public class CraftIllusioner extends CraftSpellcaster implements Illusioner, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftIllusioner(CraftServer server, net.minecraft.world.entity.monster.Illusioner entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java index 189b5ac97f..bf297388c7 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftLlama.java @@ -8,7 +8,7 @@ import org.bukkit.entity.Llama; import org.bukkit.entity.Llama.Color; import org.bukkit.inventory.LlamaInventory; -public class CraftLlama extends CraftChestedHorse implements Llama { +public class CraftLlama extends CraftChestedHorse implements Llama, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftLlama(CraftServer server, net.minecraft.world.entity.animal.horse.Llama entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java index 9426395c17..f5ecb8c1dc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPiglin.java @@ -12,7 +12,7 @@ import org.bukkit.craftbukkit.inventory.CraftItemType; import org.bukkit.entity.Piglin; import org.bukkit.inventory.Inventory; -public class CraftPiglin extends CraftPiglinAbstract implements Piglin { +public class CraftPiglin extends CraftPiglinAbstract implements Piglin, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftPiglin(CraftServer server, net.minecraft.world.entity.monster.piglin.Piglin entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPillager.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPillager.java index d82cea48d9..2638c341bc 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPillager.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPillager.java @@ -5,7 +5,7 @@ import org.bukkit.craftbukkit.inventory.CraftInventory; import org.bukkit.entity.Pillager; import org.bukkit.inventory.Inventory; -public class CraftPillager extends CraftIllager implements Pillager { +public class CraftPillager extends CraftIllager implements Pillager, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftPillager(CraftServer server, net.minecraft.world.entity.monster.Pillager entity) { super(server, entity); diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java index 1f373896cc..1e9807b8f4 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSnowman.java @@ -4,7 +4,7 @@ import net.minecraft.world.entity.animal.SnowGolem; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Snowman; -public class CraftSnowman extends CraftGolem implements Snowman { +public class CraftSnowman extends CraftGolem implements Snowman, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftSnowman(CraftServer server, SnowGolem entity) { super(server, entity); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWitch.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWitch.java index bf6acf783d..524b5ba599 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWitch.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWitch.java @@ -3,7 +3,7 @@ package org.bukkit.craftbukkit.entity; import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Witch; -public class CraftWitch extends CraftRaider implements Witch { +public class CraftWitch extends CraftRaider implements Witch, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper public CraftWitch(CraftServer server, net.minecraft.world.entity.monster.Witch entity) { super(server, entity); } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java index 59bdb36ca1..1113533d28 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftWither.java @@ -9,7 +9,7 @@ import org.bukkit.craftbukkit.boss.CraftBossBar; import org.bukkit.entity.LivingEntity; import org.bukkit.entity.Wither; -public class CraftWither extends CraftMonster implements Wither { +public class CraftWither extends CraftMonster implements Wither, com.destroystokyo.paper.entity.CraftRangedEntity { // Paper private BossBar bossBar;