Java 类org.bukkit.entity.EnderPearl 实例源码

项目:HCFCore    文件:EnderPearlTimer.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    Projectile projectile = event.getEntity();
    if (projectile instanceof EnderPearl) {
        EnderPearl enderPearl = (EnderPearl) projectile;
        ProjectileSource source = enderPearl.getShooter();
        if (source instanceof Player) {
            Player shooter = (Player) source;
            long remaining = getRemaining(shooter);
            if (remaining > 0L) {
                shooter.sendMessage(ChatColor.RED + "You are still on " + ChatColor.LIGHT_PURPLE + getName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                        + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.');

                event.setCancelled(true);
                return;
            }

            if (setCooldown(shooter, shooter.getUniqueId(), defaultCooldown, true)) {
                startDisplaying(shooter);
            }
        }
    }
}
项目:HCFCore    文件:EnderPearlTimer.java   
@EventHandler(ignoreCancelled = true, priority = EventPriority.MONITOR)
public void onProjectileLaunch(ProjectileLaunchEvent event) {
    Projectile projectile = event.getEntity();
    if (projectile instanceof EnderPearl) {
        EnderPearl enderPearl = (EnderPearl) projectile;
        ProjectileSource source = enderPearl.getShooter();
        if (source instanceof Player) {
            Player shooter = (Player) source;
            long remaining = getRemaining(shooter);
            if (remaining > 0L) {
                shooter.sendMessage(ChatColor.RED + "You are still on " + ChatColor.LIGHT_PURPLE + getName() + ChatColor.RED + " cooldown for another " + ChatColor.BOLD
                        + DurationFormatter.getRemaining(remaining, true, false) + ChatColor.RED + '.');

                event.setCancelled(true);
                return;
            }

            if (setCooldown(shooter, shooter.getUniqueId(), defaultCooldown, true)) {
                startDisplaying(shooter);
            }
        }
    }
}
项目:EnderBow    文件:EnderBowListener.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onEntityShootBowEvent(EntityShootBowEvent event) {
    if ((event.getBow().hasItemMeta() && event.getBow().getItemMeta().getDisplayName().equals("Ender bow")) || event
            .getBow() instanceof EnderBowPlugin.EnderBow) {
        // Create custom event
        EntityShootEnderBowEvent entityShootEnderBowEvent = new EntityShootEnderBowEvent(event);

        // Call the custom event
        EnderBowPlugin.getInstance().getServer().getPluginManager().callEvent(entityShootEnderBowEvent);

        // Do the following, if it wasn't cancelled
        if (!entityShootEnderBowEvent.isCancelled()) {
            // Fire an ender pearl
            event.getEntity().launchProjectile(EnderPearl.class).setVelocity(event.getProjectile().getVelocity());

            // Play the 'ENDERMAN_TELEPORT' sound
            event.getEntity().getWorld().playSound(event.getEntity().getLocation(), Sound.ENDERMAN_TELEPORT, 1, 1);
        }

        // Cancel the original Event, so no arrows are fired
        event.setCancelled(true);
    }
}
项目:ProjectAres    文件:ResetEnderPearlsKit.java   
@Override
public void apply(MatchPlayer player, boolean force, ItemKitApplicator items) {
    Player bukkitPlayer = player.getBukkit();
    for(EnderPearl pearl : bukkitPlayer.getWorld().getEntitiesByClass(EnderPearl.class)) {
        if(pearl.getShooter() == bukkitPlayer) {
            pearl.setShooter(null);
        }
    }
}
项目:ProjectAres    文件:PGMListener.java   
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void clearActiveEnderPearls(final PlayerDeathEvent event) {
    for(Entity entity : event.getEntity().getWorld().getEntitiesByClass(EnderPearl.class)) {
        if(((EnderPearl) entity).getShooter() == event.getEntity()) {
            entity.remove();
        }
    }
}
项目:ExilePearl    文件:ExileListener.java   
/**
 * Prevent exiled players from throwing ender pearls
 * @param e The event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPearlThrow(ProjectileLaunchEvent e) {
    if (e.getEntity() instanceof EnderPearl) {
        checkAndCancelRule(ExileRule.THROW_PEARL, e, (Player)e.getEntity().getShooter());
    }
}
项目:ExilePearl    文件:PlayerListener.java   
/**
 * Prevent pearling with an exile pearl
 * @param e The event
 */
@EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
public void onPearlThrow(ProjectileLaunchEvent e) {
    if (!(e.getEntity() instanceof EnderPearl)) {
        return;
    }

    final Player p = (Player)e.getEntity().getShooter();
    if (p == null) {
        return;
    }

    ExilePearl pearl = pearlApi.getPearlFromItemStack(p.getInventory().getItemInMainHand());
    if (pearl == null) {
        return;
    }

    msg(p, Lang.pearlCantThrow);
    e.setCancelled(true);

    // Need to schedule this or else the re-created pearl doesn't show up
    Bukkit.getScheduler().scheduleSyncDelayedTask(pearlApi, new Runnable() {
        @Override
        public void run() {
            p.getInventory().setItemInMainHand(pearl.createItemStack());
        }
    });
}
项目:OmniWorldMCPlugin    文件:EnderBowListener.java   
@EventHandler
public void onShootBow(EntityShootBowEvent event) {
    if ((event.getEntity() instanceof Player)) {
        Player player = (Player) event.getEntity();
        if ((event.getBow().getEnchantmentLevel(Enchantment.ARROW_INFINITE) == 2) || (event.getBow().getEnchantmentLevel(Enchantment.ARROW_INFINITE) == 3)) {
            if (player.hasPermission(PermLib.USE_ENDERBOW)) {
                if (player.getInventory().contains(Material.ENDER_PEARL)) {
                    if (event.getBow().getEnchantmentLevel(Enchantment.ARROW_INFINITE) == 2) {
                        event.setCancelled(true);
                        player.getInventory().removeItem(new ItemStack[] { new ItemStack(Material.ENDER_PEARL, 1)});
                        ((EnderPearl) player.launchProjectile(EnderPearl.class)).setVelocity(event.getProjectile().getVelocity().multiply(1.1D));
                        player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
                    } else if (event.getBow().getEnchantmentLevel(Enchantment.ARROW_INFINITE) == 3) {
                        event.setCancelled(true);
                        ((EnderPearl) player.launchProjectile(EnderPearl.class)).setVelocity(event.getProjectile().getVelocity().multiply(1.1D));
                        player.playSound(player.getLocation(), Sound.ENDERMAN_TELEPORT, 1.0F, 1.0F);
                        event.getBow().setDurability((short) 384);
                    }
                } else {
                    event.setCancelled(true);
                }
            } else {
                player.sendMessage(ChatLib.NO_PERMS_ENDERBOW);
            }
        } else {}
    }
}
项目:MCPBukkit    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        launch.func_70012_b(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    world.func_72838_d(launch);
    return (T) launch.getBukkitEntity();
}
项目:Uranium    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:SkyWarsReloaded    文件:SpectatorListener.java   
@EventHandler
protected void onEntityDamageEvent(final EntityDamageByEntityEvent e) {     
    if (e.getDamager() instanceof Player && e.getEntity() instanceof Player) {
        if ((!e.getDamager().hasMetadata("NPC") && SkyWarsReloaded.getPC().getPlayer(((Player) e.getDamager()).getUniqueId()).isSpectating()) || (!e.getEntity().hasMetadata("NPC") && SkyWarsReloaded.getPC().getPlayer(((Player) e.getEntity()).getUniqueId()).isSpectating())) {
            e.setCancelled(true);
        }
    } else if (!(e.getEntity() instanceof Player) && e.getDamager() instanceof Player) {
        if (!e.getDamager().hasMetadata("NPC") && SkyWarsReloaded.getPC().getPlayer(((Player) e.getDamager()).getUniqueId()).isSpectating()) {
            e.setCancelled(true);
        }
    } else if (e.getEntity() instanceof Player && !(e.getDamager() instanceof Player)) {
        if (!e.getEntity().hasMetadata("NPC") && SkyWarsReloaded.getPC().getPlayer(((Player) e.getEntity()).getUniqueId()).isSpectating()) {
            e.setCancelled(true);
        }
    }

    if(e.getDamager() instanceof Projectile
            && !(e.getDamager() instanceof ThrownPotion)
            && e.getEntity() instanceof Player
            && !e.getEntity().hasMetadata("NPC")
            && SkyWarsReloaded.getPC().getPlayer(((Player) e.getEntity()).getUniqueId()).isSpectating()) {

        e.setCancelled(true);
        e.getDamager().remove();
        final Player spectatorInvolved = (Player) e.getEntity();
        final boolean wasFlying = spectatorInvolved.isFlying();
        final Location initialSpectatorLocation = spectatorInvolved.getLocation();

        final Vector initialProjectileVelocity = e.getDamager().getVelocity();
        final Location initialProjectileLocation = e.getDamager().getLocation();
        final Projectile proj = (Projectile) e.getDamager(); 



        if (spectatorInvolved != proj.getShooter()) {
            spectatorInvolved.setAllowFlight(true);
            spectatorInvolved.setFlying(true);
            spectatorInvolved.teleport(initialSpectatorLocation.clone().add(0, 6, 0), TeleportCause.PLUGIN);

            Bukkit.getScheduler().runTaskLater(SkyWarsReloaded.get(), new Runnable() {
                @Override
                public void run() {
                    if (proj instanceof Arrow) {
                        Arrow arrow = initialProjectileLocation.getWorld().spawn(initialProjectileLocation, Arrow.class);
                        arrow.setBounce(false);
                        arrow.setVelocity(initialProjectileVelocity);
                        arrow.setShooter(proj.getShooter());
                    } else if (proj instanceof Snowball) {
                        Snowball snowball = initialProjectileLocation.getWorld().spawn(initialProjectileLocation, Snowball.class);
                        snowball.setVelocity(initialProjectileVelocity); 
                        snowball.setShooter(proj.getShooter());
                    } else if (proj instanceof Egg) {
                        Egg egg = initialProjectileLocation.getWorld().spawn(initialProjectileLocation, Egg.class);
                        egg.setVelocity(initialProjectileVelocity); 
                        egg.setShooter(proj.getShooter());
                    } else if (proj instanceof EnderPearl) {
                        Player p = (Player) proj.getShooter();
                        p.launchProjectile(EnderPearl.class, initialProjectileVelocity);
                    }
                }
            }, 1L);

            Bukkit.getScheduler().runTaskLater(SkyWarsReloaded.get(), new Runnable() {
                @Override
                public void run() {
                    spectatorInvolved.teleport(new Location(initialSpectatorLocation.getWorld(), initialSpectatorLocation.getX(), initialSpectatorLocation.getY(), initialSpectatorLocation.getZ(), spectatorInvolved.getLocation().getYaw(), spectatorInvolved.getLocation().getPitch()), TeleportCause.PLUGIN);
                    spectatorInvolved.setAllowFlight(true);
                    spectatorInvolved.setFlying(wasFlying);
                }
            }, 5L);
        }
    }
}
项目:Parties    文件:FightListener.java   
@EventHandler
public void onPlayerHit(EntityDamageByEntityEvent event) {
    if (Variables.friendlyfire_enable && event.getEntity() instanceof Player) {
        Player victim = (Player) event.getEntity();
        Player attacker = null;
        DamageType type = DamageType.UNSUPPORTED; // 0=Basic, 1=Arrow, 2=EnderPearl, 3=Snowball
        if (event.getDamager() instanceof Player)
            type = DamageType.PLAYER;
        else if (event.getDamager() instanceof Arrow)
            type = DamageType.ARROW;
        else if (event.getDamager() instanceof EnderPearl)
            type = DamageType.ENDERPEARL;
        else if (event.getDamager() instanceof Snowball)
            type = DamageType.SNOWBALL;

        if (!type.equals(DamageType.UNSUPPORTED)) {
            ProjectileSource shooterSource;
            switch (type) {
            case PLAYER:
                attacker = (Player) event.getDamager();
                break;
            case ARROW:
                shooterSource = ((Arrow)event.getDamager()).getShooter();
                if (shooterSource instanceof Player)
                    attacker = (Player) shooterSource;
                break;
            case ENDERPEARL:
                shooterSource = ((EnderPearl)event.getDamager()).getShooter();
                if (shooterSource instanceof Player)
                    attacker = (Player) shooterSource;
                break;
            case SNOWBALL:
                shooterSource = ((Snowball)event.getDamager()).getShooter();
                if (shooterSource instanceof Player)
                    attacker = (Player) shooterSource;
                break;
            case UNSUPPORTED:
            }
            if (attacker != null) {
                // Found right attacker
                if (!victim.getUniqueId().equals(attacker.getUniqueId())
                        && (Variables.friendlyfire_listworlds.contains("*")
                                || Variables.friendlyfire_listworlds.contains(victim.getWorld().getName()))) {
                    // Friendly fire not allowed here
                    ThePlayer tpVictim = plugin.getPlayerHandler().getPlayer(victim.getUniqueId());
                    ThePlayer tpAttacker = plugin.getPlayerHandler().getPlayer(attacker.getUniqueId());

                    if (!tpVictim.getPartyName().isEmpty() && tpVictim.getPartyName().equalsIgnoreCase(tpAttacker.getPartyName())) {
                        // Calling API event
                        PartiesFriendlyFireBlockedEvent partiesFriendlyFireEvent = new PartiesFriendlyFireBlockedEvent(victim, attacker, event);
                        Bukkit.getServer().getPluginManager().callEvent(partiesFriendlyFireEvent);
                        if (!partiesFriendlyFireEvent.isCancelled()) {
                            // Friendly fire confirmed
                            Party party = plugin.getPartyHandler().getParty(tpVictim.getPartyName());

                            tpAttacker.sendMessage(Messages.canthitmates);
                            party.sendFriendlyFireWarn(tpVictim, tpAttacker);

                            event.setCancelled(true);
                            LogHandler.log(LogLevel.DEBUG, "Denied PvP friendly fire [type " + type.name() + "] between A:'" + attacker.getName() + "' and V:'" + victim.getName() + "'", true);
                        } else
                            LogHandler.log(LogLevel.DEBUG, "PartiesFriendlyFireBlockedEvent is cancelled, ignoring [type " + type.name() + "] between A:'" + attacker.getName() + "' and V:'" + victim.getName() + "'", true);
                    }
                }
            }
        }
    }
}
项目:ThermosRebased    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:Thermos    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:KCauldron    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:CauldronGit    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:Cauldron-Old    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:Cauldron-Reloaded    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:FFoKC    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:Slimefun4    文件:ArmorListener.java   
@SuppressWarnings("deprecation")
@EventHandler(priority=EventPriority.MONITOR)
public void onDamage(EntityDamageEvent e) {
    if (e.getEntity() instanceof Player && !e.isCancelled()) {
        Player p = (Player) e.getEntity();
        for (ItemStack armor: p.getInventory().getArmorContents()) {
            if (armor != null && SlimefunItem.getByItem(armor) != null) {
                if (SlimefunItem.getByItem(armor).isItem(SlimefunItems.ENDER_BOOTS) && Slimefun.hasUnlocked(p, SlimefunItems.ENDER_BOOTS, true)) {
                    if (e instanceof EntityDamageByEntityEvent) {
                        if (((EntityDamageByEntityEvent) e).getDamager() instanceof EnderPearl) e.setCancelled(true);
                    }
                }
                else if (SlimefunItem.getByItem(armor).isItem(SlimefunItems.SLIME_BOOTS) && Slimefun.hasUnlocked(p, SlimefunItems.SLIME_BOOTS, true)) {
                    if (e.getCause() == DamageCause.FALL) e.setCancelled(true);
                }
                else if (SlimefunItem.getByItem(armor).isItem(SlimefunItems.BOOTS_OF_THE_STOMPER) && Slimefun.hasUnlocked(p, SlimefunItems.BOOTS_OF_THE_STOMPER, true)) {
                    if (e.getCause() == DamageCause.FALL) {
                        e.setCancelled(true);
                        p.getWorld().playSound(p.getLocation(), Sound.ENTITY_ZOMBIE_BREAK_DOOR_WOOD, 2F, 2F);
                        p.setVelocity(new Vector(0.0, 0.7, 0.0));
                        for (Entity n: p.getNearbyEntities(4, 4, 4)) {
                            if (n instanceof LivingEntity && !n.getUniqueId().toString().equalsIgnoreCase(p.getUniqueId().toString())) {
                                n.setVelocity(n.getLocation().toVector().subtract(p.getLocation().toVector()).normalize().multiply(1.4));
                                if (p.getWorld().getPVP()) {
                                    EntityDamageByEntityEvent event = new EntityDamageByEntityEvent(p, n, DamageCause.ENTITY_ATTACK, e.getDamage() / 2);
                                    Bukkit.getPluginManager().callEvent(event);
                                    if (!event.isCancelled()) ((LivingEntity) n).damage(e.getDamage() / 2);
                                }
                            }
                        }
                        for (int i = 0; i < 2; i++) {
                            for (BlockFace face: BlockFace.values()) {
                                p.getWorld().playEffect(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face).getLocation(), Effect.STEP_SOUND, p.getLocation().getBlock().getRelative(BlockFace.DOWN).getRelative(face).getType());
                            }
                        }
                    }
                }
                else if (SlimefunItem.getByItem(armor).isItem(SlimefunItems.SLIME_BOOTS_STEEL) && Slimefun.hasUnlocked(p, SlimefunItems.SLIME_BOOTS_STEEL, true)) {
                    if (e.getCause() == DamageCause.FALL) e.setCancelled(true);
                }
            }
        }
    }
}
项目:Cauldron    文件:CraftLivingEntity.java   
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;

    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntitySnowball(world, getHandle());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityEgg(world, getHandle());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityEnderPearl(world, getHandle());
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityArrow(world, getHandle(), 1);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.projectile.EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.entity.item.EntityExpBottle(world, getHandle());
    } else if (Fish.class.isAssignableFrom(projectile) && getHandle() instanceof net.minecraft.entity.player.EntityPlayer) {
        launch = new net.minecraft.entity.projectile.EntityFishHook(world, (net.minecraft.entity.player.EntityPlayer) getHandle());
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);

        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntitySmallFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.entity.projectile.EntityWitherSkull(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new net.minecraft.entity.projectile.EntityLargeFireball(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }

        ((net.minecraft.entity.projectile.EntityFireball) launch).projectileSource = this;
        launch.setLocationAndAngles(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    }

    Validate.notNull(launch, "Projectile not supported");

    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }

    world.spawnEntityInWorld(launch);
    return (T) launch.getBukkitEntity();
}
项目:RodsTwo    文件:Ender.java   
@Override
public boolean run(Player player, ConfigurationSection config) {
    player.launchProjectile(EnderPearl.class);
    return true; 
}
项目:NBTEditor    文件:EnderBow.java   
@Override
public void onShootBow(EntityShootBowEvent event, DelayedPlayerDetails details) {
    Entity perl = event.getEntity().launchProjectile(EnderPearl.class);
    perl.setVelocity(event.getProjectile().getVelocity());
    event.setProjectile(perl);
}
项目:SwornGuns    文件:Bullet.java   
public Bullet(SwornGuns plugin, GunPlayer shooter, Gun shotFrom, Vector velocity)
{
    this.plugin = plugin;
    this.shotFrom = shotFrom;
    this.shooter = shooter;
    this.velocity = velocity;
    this.active = true;

    if (shotFrom.isThrowable())
    {
        ItemStack thrown = shotFrom.getMaterial().newItemStack(1);

        this.projectile = shooter.getPlayer().getWorld().dropItem(shooter.getPlayer().getEyeLocation(), thrown);
        this.id = projectile.getEntityId();

        ((Item) projectile).setPickupDelay(9999999);
        this.startLocation = projectile.getLocation();
    }
    else
    {
        Class<? extends Projectile> mclass = Snowball.class;

        String check = shotFrom.getProjType().toLowerCase().replaceAll("_", "").replaceAll(" ", "");
        switch (check)
        {
            case "arrow":
                mclass = Arrow.class;
                break;
            case "egg":
                mclass = Egg.class;
                break;
            case "enderpearl":
                mclass = EnderPearl.class;
                break;
            case "fireball":
                mclass = Fireball.class;
                break;
            case "fish":
            case "fishhook":
                mclass = FishHook.class;
                break;
            case "largefireball":
                mclass = LargeFireball.class;
                break;
            case "smallfireball":
                mclass = SmallFireball.class;
                break;
            case "thrownexpbottle":
                mclass = ThrownExpBottle.class;
                break;
            case "thrownpotion":
                mclass = ThrownPotion.class;
                break;
            case "witherskull":
                mclass = WitherSkull.class;
                break;
            default:
                break;
        }

        this.projectile = shooter.getPlayer().launchProjectile(mclass);
        this.id = projectile.getEntityId();

        ((Projectile) projectile).setShooter(shooter.getPlayer());
        this.startLocation = projectile.getLocation();
    }

    if (shotFrom.getReleaseTime() == -1)
    {
        this.releaseTime = 80 + (shotFrom.isThrowable() ? 0 : 1) * 400;
    }
    else
    {
        this.releaseTime = shotFrom.getReleaseTime();
    }
}
项目:BukkitOldCombatMechanics    文件:ModuleDisableEnderpearlCooldown.java   
@EventHandler(priority = EventPriority.HIGHEST)
public void onPlayerShoot(PlayerInteractEvent e) {

    Action action = e.getAction();

    if(action != Action.RIGHT_CLICK_AIR && action != Action.RIGHT_CLICK_BLOCK) return;

    Player player = e.getPlayer();

    if(!isEnabled(player.getWorld())) return;

    if(e.getMaterial() != Material.ENDER_PEARL) return;

    if (e.isCancelled()) return;

    e.setCancelled(true);

    EnderPearl pearl = player.launchProjectile(EnderPearl.class);

    pearl.setVelocity(player.getEyeLocation().getDirection().multiply(2));

    GameMode mode = player.getGameMode();

    if(mode == GameMode.ADVENTURE || mode == GameMode.SURVIVAL) {
        PlayerInventory inv = player.getInventory();

        boolean isInOffhand = true;
        ItemStack hand = inv.getItemInOffHand();

        if(hand.getType() != Material.ENDER_PEARL) {
            hand = inv.getItemInMainHand();
            isInOffhand = false;
        }

        hand.setAmount(hand.getAmount() - 1);

        if(isInOffhand)
            inv.setItemInOffHand(hand);
        else
            inv.setItemInMainHand(hand);
    }
}