From b0bf52751f2bb2e62735884aed44d5b8bd987be5 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Fri, 7 Jan 2011 16:26:08 -0800 Subject: [PATCH] Added passenger methods to Vehicle/LivingEntity. By: sk89q --- .../org/bukkit/craftbukkit/CraftEntity.java | 1 + .../bukkit/craftbukkit/CraftLivingEntity.java | 28 ++++++++++++++++++- .../org/bukkit/craftbukkit/CraftVehicle.java | 14 ++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java index 535db3905b..909bfae89c 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftEntity.java @@ -5,6 +5,7 @@ import net.minecraft.server.Entity; import net.minecraft.server.WorldServer; import org.bukkit.Location; import org.bukkit.Vector; +import org.bukkit.Vehicle; import org.bukkit.World; public abstract class CraftEntity implements org.bukkit.Entity { diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java index 50a297f618..449ea62fe8 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftLivingEntity.java @@ -11,6 +11,7 @@ import org.bukkit.Arrow; import org.bukkit.Egg; import org.bukkit.LivingEntity; import org.bukkit.Snowball; +import org.bukkit.Vehicle; public class CraftLivingEntity extends CraftEntity implements LivingEntity { private EntityLiving entity; @@ -61,11 +62,36 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { return new CraftSnowball(server, snowball); } - @Override public Arrow shootArrow() { net.minecraft.server.World world = ((CraftWorld)getWorld()).getHandle(); EntityArrow snowball = new EntityArrow(world, entity); world.a(snowball); return new CraftArrow(server, snowball); } + + public boolean isInsideVehicle() { + return entity.k != null; + } + + public boolean leaveVehicle() { + if (entity.k == null) { + return false; + } + + entity.setPassengerOf(null); + return true; + } + + public Vehicle getVehicle() { + if (entity.k == null) { + return null; + } + + org.bukkit.Entity vehicle = ((CraftWorld)getWorld()).toCraftEntity(entity.k); + if (vehicle instanceof Vehicle) { + return (Vehicle)vehicle; + } + + return null; + } } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java index 3ffed5014b..ffc93da19b 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftVehicle.java @@ -17,8 +17,22 @@ public abstract class CraftVehicle extends CraftEntity implements Vehicle { public Entity getPassenger() { return ((CraftWorld)getWorld()).toCraftEntity(getHandle().j); } + + public boolean setPassenger(Entity passenger) { + ((CraftEntity)passenger).getHandle().setPassengerOf(getHandle()); + return true; + } public boolean isEmpty() { return getHandle().j == null; } + + public boolean eject() { + if (getHandle().j == null) { + return false; + } + + getHandle().j.setPassengerOf(null); + return true; + } }