Java Code Examples for org.bukkit.entity.Entity#getPassenger()

The following examples show how to use org.bukkit.entity.Entity#getPassenger() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityUtil.java    From AACAdditionPro with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the passengers of an entity.
 * This method solves the compatibility issues of the newer APIs with server version 1.8.8
 */
public static List<Entity> getPassengers(final Entity entity)
{
    switch (ServerVersion.getActiveServerVersion()) {
        case MC188:
            Entity passenger = entity.getPassenger();
            return passenger == null ?
                   Collections.emptyList() :
                   Collections.singletonList(passenger);
        case MC112:
        case MC113:
        case MC114:
        case MC115:
            return entity.getPassengers();
        default:
            throw new UnknownMinecraftVersion();
    }
}
 
Example 2
Source File: Powergloves.java    From ce with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public boolean effect(Event event, final Player player) {
	if(event instanceof PlayerInteractEntityEvent) {
		PlayerInteractEntityEvent e = (PlayerInteractEntityEvent) event;
		e.setCancelled(true);
		final Entity clicked = e.getRightClicked();
		if(!player.hasMetadata("ce." + getOriginalName()))
			if(!clicked.getType().equals(EntityType.PAINTING) && !clicked.getType().equals(EntityType.ITEM_FRAME) && clicked.getPassenger() != player && player.getPassenger() == null) {
				player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, false));

				player.setPassenger(clicked);

				player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_CHEW_IRON_DOOR, 10);

				new BukkitRunnable() {

					@Override
					public void run() {
						player.getWorld().playEffect(player.getLocation(), Effect.CLICK2, 10);
						player.setMetadata("ce." + getOriginalName(), new FixedMetadataValue(main, true));
						this.cancel();
					}
				}.runTaskLater(main, ThrowDelayAfterGrab);

				new BukkitRunnable() {

					int			GrabTime	= MaxGrabtime;
					ItemStack	current		= player.getItemInHand();

					@Override
					public void run() {
						if(current.equals(player.getItemInHand())) {
							current = player.getItemInHand();
						if(GrabTime > 0) {
							if(!player.hasMetadata("ce." + getOriginalName())) {
								this.cancel();
							}
							GrabTime--;
						} else if(GrabTime <= 0) {
							if(player.hasMetadata("ce." + getOriginalName())) {
								player.getWorld().playEffect(player.getLocation(), Effect.CLICK1, 10);
								player.removeMetadata("ce." + getOriginalName(), main);
								generateCooldown(player, getCooldown());
							}
							clicked.leaveVehicle();
							this.cancel();
						}
					  } else {
						  player.removeMetadata("ce." + getOriginalName(), main);
						  generateCooldown(player, getCooldown());
						  this.cancel();
					  }
					}
				}.runTaskTimer(main, 0l, 10l);
			}
	} else if(event instanceof PlayerInteractEvent) {
		if(player.hasMetadata("ce." + getOriginalName()) && player.getMetadata("ce." + getOriginalName()).get(0).asBoolean())
				if(player.getPassenger() != null) {
					Entity passenger = player.getPassenger();
					player.getPassenger().leaveVehicle();
					passenger.setVelocity(player.getLocation().getDirection().multiply(ThrowSpeedMultiplier));
					player.getWorld().playEffect(player.getLocation(), Effect.ZOMBIE_DESTROY_DOOR, 10);
					player.removeMetadata("ce." + getOriginalName(), main);
					return true;
				}
	}
	return false;
}