From 7e19325845e2cb8bcd94f46b4cc9de8ce1ad54cc Mon Sep 17 00:00:00 2001 From: md_5 Date: Wed, 4 Jan 2017 10:53:07 +1100 Subject: [PATCH] SPIGOT-2640: API for multiple passengers per entity --- .../craftbukkit/entity/CraftEntity.java | 32 +++++++++++++++++-- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java index 9fac33bd5a..c21e49b95f 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftEntity.java @@ -1,6 +1,8 @@ package org.bukkit.craftbukkit.entity; +import com.google.common.base.Function; import com.google.common.base.Preconditions; +import com.google.common.collect.Lists; import java.util.List; import java.util.Set; import java.util.UUID; @@ -331,13 +333,37 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { Preconditions.checkArgument(!this.equals(passenger), "Entity cannot ride itself."); if (passenger instanceof CraftEntity) { eject(); - ((CraftEntity) passenger).getHandle().startRiding(getHandle()); - return true; + return ((CraftEntity) passenger).getHandle().startRiding(getHandle()); } else { return false; } } + @Override + public List getPassengers() { + return Lists.newArrayList(Lists.transform(getHandle().passengers, new Function() { + @Override + public org.bukkit.entity.Entity apply(Entity input) { + return input.getBukkitEntity(); + } + })); + } + + @Override + public boolean addPassenger(org.bukkit.entity.Entity passenger) { + Preconditions.checkArgument(passenger != null, "passenger == null"); + + return ((CraftEntity) passenger).getHandle().a(getHandle(), true); + } + + @Override + public boolean removePassenger(org.bukkit.entity.Entity passenger) { + Preconditions.checkArgument(passenger != null, "passenger == null"); + + ((CraftEntity) passenger).getHandle().stopRiding(); + return true; + } + public boolean isEmpty() { return !getHandle().isVehicle(); } @@ -347,7 +373,7 @@ public abstract class CraftEntity implements org.bukkit.entity.Entity { return false; } - getPassenger().leaveVehicle(); + getHandle().az(); // PAIL: rename return true; }