diff --git a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java index 5a5b8b7..83c583e 100644 --- a/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java +++ b/src/main/java/me/tofaa/entitylib/entity/WrapperEntity.java @@ -99,6 +99,22 @@ public class WrapperEntity implements Tickable { } } + /** + * @param passenger the entity id of the passenger + * @return true if the entity has the passenger, false otherwise + */ + public boolean hasPassenger(int passenger) { + return passengers.contains(passenger); + } + + /** + * @param passenger the passenger wrapper entity + * @return true if the entity has the passenger, false otherwise + */ + public boolean hasPassenger(WrapperEntity passenger) { + return hasPassenger(passenger.getEntityId()); + } + /** * Removes multiple passengers from the entity. The passengers will be removed from the view of all viewers of the entity. * @param passengers the entity ids of the passengers diff --git a/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java b/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java index 4446ee0..9a1be15 100644 --- a/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java +++ b/test-plugin/src/main/java/me/tofaa/entitylib/TestCommand.java @@ -22,21 +22,21 @@ public class TestCommand implements CommandExecutor { Player player = (Player) sender; if (base != null) { - base.removePassenger(passenger); - player.sendMessage("Removed"); - return true; + if (base.hasPassenger(passenger)) { + base.removePassenger(passenger); + player.sendMessage("Removed"); + return true; + } } base = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.SHEEP); passenger = EntityLib.createEntity(UUID.randomUUID(), EntityTypes.SKELETON); Location location = SpigotConversionUtil.fromBukkitLocation(player.getLocation()); - Location pass = location.clone(); - pass.setPosition(location.getPosition().add(1, 0, 1)); + Location pass = new Location(location.getX() + 1, location.getY(), location.getZ(), location.getYaw(), location.getPitch()); + base.spawn(location); passenger.spawn(pass); - base.addPassenger(passenger); - player.sendMessage("Spawned"); return true;