Java Code Examples for org.bukkit.entity.Player#getPassenger()
The following examples show how to use
org.bukkit.entity.Player#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: PushbackCharger.java From QualityArmory with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("deprecation") @Override public boolean shoot(Gun g, Player p, ItemStack i) { Location start = p.getEyeLocation().clone(); Vector go = p.getLocation().getDirection().normalize(); //go.add(new Vector((Math.random() * 2 * sway) - sway, (Math.random() * 2 * sway) - sway, // (Math.random() * 2 * sway) - sway)); GunUtil.playShoot(g, p); boolean lookup = (go.getY() > go.getX() && go.getY() > go.getZ()); boolean lookdown = (-go.getY() > go.getX() && -go.getY() > go.getZ()); double degreeVector = Math.atan2(go.getX(), go.getZ()); if (degreeVector > Math.PI) degreeVector = 2 * Math.PI - degreeVector; for (Entity e : p.getNearbyEntities(g.getMaxDistance(), g.getMaxDistance(), g.getMaxDistance())) { double dis = e.getLocation().distance(start); if (e instanceof Damageable) if (e != p && e != p.getVehicle() && e != p.getPassenger()) { double degreeEntity = Math.atan2(e.getLocation().getX() - start.getX(), e.getLocation().getZ() - start.getZ()); if (degreeEntity > Math.PI) degreeEntity = 2 * Math.PI - degreeEntity; if ((lookup && e.getLocation().getY() > start.getY()) || (lookdown && e.getLocation().getY() < start.getY()) || (!lookdown&&!lookup&&Math.max(degreeEntity, degreeVector) - Math.min(degreeEntity, degreeVector) < (dis > 10 ? Math.PI / 4 : Math.PI / 2))) { Vector pushback = new Vector(e.getLocation().getX() - start.getX(),e.getLocation().getY() - start.getY(), e.getLocation().getZ() - start.getZ()); pushback.normalize().multiply(g.getMaxDistance()/(dis)); e.setVelocity(pushback); } } } return false; }
Example 2
Source File: Powergloves.java From ce with GNU Lesser General Public License v3.0 | 4 votes |
@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; }