SPIGOT-4819: Continue refactoring of Arrow-related APIs

This commit is contained in:
md_5 2019-04-30 21:23:11 +10:00
parent 9926d780c4
commit 29b90d2410
5 changed files with 10 additions and 12 deletions

View File

@ -116,6 +116,7 @@ import org.bukkit.craftbukkit.metadata.BlockMetadataStore;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.craftbukkit.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.util.CraftRayTraceResult;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.AbstractHorse;
import org.bukkit.entity.AbstractVillager;
import org.bukkit.entity.Ambient;
@ -1295,7 +1296,7 @@ public class CraftWorld implements World {
entity = new EntitySnowball(world, x, y, z);
} else if (Egg.class.isAssignableFrom(clazz)) {
entity = new EntityEgg(world, x, y, z);
} else if (Arrow.class.isAssignableFrom(clazz)) {
} else if (AbstractArrow.class.isAssignableFrom(clazz)) {
if (TippedArrow.class.isAssignableFrom(clazz)) {
entity = EntityTypes.ARROW.a(world);
((EntityTippedArrow) entity).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));

View File

@ -6,12 +6,12 @@ import net.minecraft.server.EntityArrow;
import org.apache.commons.lang.Validate;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.projectiles.ProjectileSource;
public class CraftArrow extends AbstractProjectile implements Arrow {
public class CraftArrow extends AbstractProjectile implements AbstractArrow {
public CraftArrow(CraftServer server, EntityArrow entity) {
super(server, entity);

View File

@ -46,7 +46,7 @@ import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.inventory.CraftEntityEquipment;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.DragonFireball;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
@ -369,7 +369,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity {
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EntityEnderPearl(world, getHandle());
((EntityProjectile) launch).a(getHandle(), getHandle().pitch, getHandle().yaw, 0.0F, 1.5F, 1.0F); // ItemEnderPearl
} else if (Arrow.class.isAssignableFrom(projectile)) {
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new EntityTippedArrow(world, getHandle());
((EntityTippedArrow) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));

View File

@ -9,14 +9,13 @@ import org.apache.commons.lang.Validate;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.TippedArrow;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
public class CraftTippedArrow extends CraftArrow implements TippedArrow {
public class CraftTippedArrow extends CraftArrow implements Arrow {
public CraftTippedArrow(CraftServer server, EntityTippedArrow entity) {
super(server, entity);
@ -59,7 +58,6 @@ public class CraftTippedArrow extends CraftArrow implements TippedArrow {
@Override
public void clearCustomEffects() {
Validate.isTrue(getBasePotionData().getType() != PotionType.UNCRAFTABLE, "Tipped Arrows must have at least 1 effect");
getHandle().effects.clear();
getHandle().refreshEffects();
}
@ -100,7 +98,6 @@ public class CraftTippedArrow extends CraftArrow implements TippedArrow {
if (existing == null) {
return false;
}
Validate.isTrue(getBasePotionData().getType() != PotionType.UNCRAFTABLE || !getHandle().effects.isEmpty(), "Tipped Arrows must have at least 1 effect");
getHandle().effects.remove(existing);
getHandle().refreshEffects();
return true;
@ -109,7 +106,6 @@ public class CraftTippedArrow extends CraftArrow implements TippedArrow {
@Override
public void setBasePotionData(PotionData data) {
Validate.notNull(data, "PotionData cannot be null");
Validate.isTrue(data.getType() != PotionType.UNCRAFTABLE || !getHandle().effects.isEmpty(), "Tipped Arrows must have at least 1 effect");
getHandle().setType(CraftPotionUtil.fromBukkit(data));
}

View File

@ -25,6 +25,7 @@ import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AbstractArrow;
import org.bukkit.entity.Arrow;
import org.bukkit.entity.Egg;
import org.bukkit.entity.EnderPearl;
@ -89,7 +90,7 @@ public class CraftBlockProjectileSource implements BlockProjectileSource {
launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (Arrow.class.isAssignableFrom(projectile)) {
} else if (AbstractArrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityTippedArrow) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));