本文整理匯總了Java中org.bukkit.entity.Projectile類的典型用法代碼示例。如果您正苦於以下問題:Java Projectile類的具體用法?Java Projectile怎麽用?Java Projectile使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Projectile類屬於org.bukkit.entity包,在下文中一共展示了Projectile類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MagicMobDeathEvent
import org.bukkit.entity.Projectile; //導入依賴的package包/類
public MagicMobDeathEvent(MageController controller, EntityData entityData, EntityDeathEvent deathEvent) {
this.controller = controller;
this.entityData = entityData;
this.deathEvent = deathEvent;
LivingEntity killed = deathEvent.getEntity();
EntityDamageEvent damageEvent = killed.getLastDamageCause();
if (damageEvent instanceof EntityDamageByEntityEvent)
{
EntityDamageByEntityEvent damageByEvent = (EntityDamageByEntityEvent)damageEvent;
Entity damagingEntity = damageByEvent.getDamager();
if (damagingEntity instanceof Projectile) {
Projectile projectile = (Projectile)damagingEntity;
damagingEntity = (LivingEntity)projectile.getShooter();
}
if (damagingEntity != null && damagingEntity instanceof Player)
{
player = (Player)damagingEntity;
mage = controller.getRegisteredMage(player.getUniqueId().toString());
}
}
}
示例2: resolve
import org.bukkit.entity.Projectile; //導入依賴的package包/類
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;
if(event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
Double projectileDistance = null;
if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);
if(projectile.getShooter() instanceof LivingEntity) {
return new ProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance);
}
}
}
return null;
}
示例3: resolve
import org.bukkit.entity.Projectile; //導入依賴的package包/類
public @Nullable
DamageInfo resolve(@Nonnull LivingEntity entity, @Nonnull Lifetime lifetime, @Nonnull EntityDamageEvent damageEvent) {
if(damageEvent instanceof EntityDamageByEntityEvent) {
EntityDamageByEntityEvent event = (EntityDamageByEntityEvent) damageEvent;
if(event.getDamager() instanceof Projectile) {
Projectile projectile = (Projectile) event.getDamager();
Location launchLocation = this.projectileDistanceTracker.getLaunchLocation(projectile);
Double projectileDistance = null;
OfflinePlayer dispenserOwner = dispenserTracker.getOwner(projectile);
if(launchLocation != null) projectileDistance = event.getEntity().getLocation().distance(launchLocation);
if(projectile.getShooter() instanceof LivingEntity) {
return new DispensedProjectileDamageInfo(projectile, (LivingEntity) projectile.getShooter(), projectileDistance, dispenserOwner);
}
}
}
return null;
}
示例4: onLingeringPotionSplash
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onLingeringPotionSplash(final LingeringPotionSplashEvent e) {
if (DEBUG) {
plugin.getLogger().info("1.9 " + e.getEventName());
plugin.getLogger().info("1.9 entity = " + e.getEntity());
plugin.getLogger().info("1.9 entity type = " + e.getEntityType());
plugin.getLogger().info("1.9 radius = " + e.getAreaEffectCloud().getRadius());
plugin.getLogger().info("1.9 id = " + e.getAreaEffectCloud().getEntityId());
plugin.getLogger().info("1.9 hit entity = " + e.getHitEntity());
}
if (!Util.inWorld(e.getEntity().getLocation())) {
return;
}
// Try to get the shooter
Projectile projectile = e.getEntity();
plugin.getLogger().info("shooter = " + projectile.getShooter());
if (projectile.getShooter() != null && projectile.getShooter() instanceof Player) {
UUID uuid = ((Player)projectile.getShooter()).getUniqueId();
// Store it and remove it when the effect is gone
thrownPotions.put(e.getAreaEffectCloud().getEntityId(), uuid);
plugin.getServer().getScheduler().runTaskLater(plugin, () -> thrownPotions.remove(e.getAreaEffectCloud().getEntityId()), e.getAreaEffectCloud().getDuration());
}
}
示例5: onItemFrameDamage
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler(priority = EventPriority.LOW, ignoreCancelled = true)
public void onItemFrameDamage(final EntityDamageByEntityEvent e) {
// Check world
if (!Util.inWorld(e.getEntity()) || !(e.getEntity() instanceof ItemFrame)) {
return;
}
if (e.getDamager() instanceof Projectile) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Projectile damage to itemframe");
// Find out who fired the arrow
Projectile p = (Projectile) e.getDamager();
if (DEBUG)
plugin.getLogger().info("DEBUG: Shooter is " + p.getShooter().toString());
if (p.getShooter() instanceof Skeleton || p.getShooter() instanceof Golem) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Shooter is mob");
if (!Settings.allowMobDamageToItemFrames) {
if (DEBUG)
plugin.getLogger().info("DEBUG: Damage not allowed, cancelling");
e.setCancelled(true);
}
}
}
}
示例6: shoot
import org.bukkit.entity.Projectile; //導入依賴的package包/類
/**
* A basic shoot method, it _can_ be overridden but take care.
* Handles passing the bullet to its BulletType for configuration, sets shooter, velocity, etc.
*
* @param begin The location to shoot from
* @param bulletType the Bullet type of this bullet
* @param shooter the entity shooting
* @param velocity the velocity to use as base for this shooting, if any
* @param overrideVelocity if true, use the passed velocity and override anything set up by the bullet type.
* @return the new Projectile that has been unleashed.
*/
public Projectile shoot(Location begin, Bullet bulletType, ProjectileSource shooter, Vector velocity, boolean overrideVelocity) {
World world = begin.getWorld();
begin = begin.clone();
begin.setDirection(velocity);
Projectile newBullet = world.spawn(begin, bulletType.getProjectileType() );
newBullet.setCustomName(this.bulletTag);
newBullet.setBounce(false);
newBullet.setGravity(true);
newBullet.setShooter(shooter);
bulletType.configureBullet(newBullet, world, shooter, velocity);
if (overrideVelocity) {
newBullet.setVelocity(velocity);
}
return newBullet;
}
示例7: tick
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@Repeatable(scope = MatchScope.RUNNING)
public void tick() {
EntityUtils.entities(match.getWorld(), Projectile.class)
.filter(projectile -> projectile.hasMetadata(TRAIL_META))
.forEach(projectile -> {
if(projectile.isDead() || projectile.isOnGround()) {
projectile.removeMetadata(TRAIL_META, PGM.get());
} else {
final Color color = (Color) projectile.getMetadata(TRAIL_META, PGM.get()).value();
// Certain particles can have a specific color if:
// - Count is 0
// - Speed is 1
// - Delta vectors are RGB values from (0,1]
match.getWorld().spawnParticle(
Particle.REDSTONE,
projectile.getLocation(),
0,
rgbToParticle(color.getRed()),
rgbToParticle(color.getGreen()),
rgbToParticle(color.getBlue()),
1
);
}
});
}
示例8: onAttack
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler
public void onAttack(EntityDamageByEntityEvent e) {
if(!(e.getEntity() instanceof Player)) return;
if(e.getDamager() instanceof Player || e.getDamager() instanceof Projectile) {
if(mayPvP) {
if(e.getDamager() instanceof Projectile) {
handleShooting(e);
} else {
handleMelee(e);
}
} else {
e.setCancelled(true);
return;
}
} else {
return;
}
}
示例9: fireGun
import org.bukkit.entity.Projectile; //導入依賴的package包/類
private void fireGun(final Player shooter, final Class<? extends Projectile> projectile, final int count) {
// 槍械射擊
new MoonLakeRunnable() {
private int currentCount = count;
@Override
public void run() {
if(currentCount <= 0) {
cancel();
return;
}
shooter.launchProjectile(projectile, shooter.getLocation().getDirection().normalize().multiply(3d));
shooter.playSound(shooter.getLocation(), Sound.ENTITY_IRONGOLEM_ATTACK, 0.5f, 2f);
shooter.playSound(shooter.getLocation(), Sound.ENTITY_SKELETON_HURT, 0.5f, 2f);
shooter.playSound(shooter.getLocation(), Sound.ENTITY_ZOMBIE_ATTACK_DOOR_WOOD, 0.5f, 2f);
currentCount--;
}
}.runTaskTimer(getMain(), 0L, 2L);
}
示例10: onPvP
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler(ignoreCancelled = true)
public void onPvP(EntityDamageByEntityEvent evt) {
if (Parties.isParty(evt.getDamager()))
return;
Player attacker = evt.getDamager() instanceof Player ? (Player) evt.getDamager() :
(evt.getDamager() instanceof Projectile && ((Projectile) evt.getDamager()).getShooter() instanceof Player
? (Player) ((Projectile) evt.getDamager()).getShooter() : null); // Yuck, maybe we can make a method for this later.
if (attacker == null || !(evt.getEntity() instanceof Player))
return; // One or both of the combatants isn't a player.
boolean outgoingFail = !getToggle(attacker, Toggle.PVP);
boolean incomingFail = !getToggle(evt.getEntity(), Toggle.PVP);
if (outgoingFail || incomingFail) {
attacker.sendMessage(ChatColor.RED + (outgoingFail ? "You have PvP disabled. (/togglepvp)"
: evt.getEntity().getName() + " has PvP disabled."));
evt.setCancelled(true);
evt.getEntity().setFireTicks(-1); // Disable fire damage.
}
}
示例11: onProjectileLaunch
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@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);
}
}
}
}
示例12: notify
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@Override
public void notify(Player player, Object extra) {
Location eye = player.getEyeLocation();
Vector direction = eye.getDirection().multiply(2);
Block source = (Block) extra;
Projectile projectile = player.getWorld().spawn(source.getRelative(BlockFace.UP).getLocation().setDirection(direction), LargeFireball.class);
projectile.setShooter(player);
projectile.setVelocity(direction);
Inventory inv = player.getInventory();
if (inv.contains(Material.TNT)) {
int slot = inv.first(Material.TNT);
ItemStack ammo = inv.getItem(slot);
int amount = ammo.getAmount();
if (amount > 1) {
ammo.setAmount(amount - 1);
inv.setItem(slot, ammo);
} else {
inv.setItem(slot, null);
}
projectile.setCustomName("recreator.structure.turret.tnt");
}
AzureAPI.playSound(player, Sound.ITEM_FIRECHARGE_USE, true);
}
示例13: onHit
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler
public void onHit(ProjectileHitEvent evt) {
Projectile projectile = evt.getEntity();
String customId = projectile.getCustomName();
if (customId == null || !customId.equals("recreator.structure.turret.tnt")) return;
Location loc;
Block block = evt.getHitBlock();
if (block != null) {
loc = block.getLocation();
block.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1.8F, true, true);
return;
}
Entity entity = evt.getEntity();
if (entity != null) {
loc = entity.getLocation();
entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 1.8F, true, true);
}
}
示例14: onHit
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler
public void onHit(ProjectileHitEvent evt) {
Projectile projectile = evt.getEntity();
String customId = projectile.getCustomName();
if (customId == null || !customId.equals("recreator.item.fatman")) return;
Location loc;
Block block = evt.getHitBlock();
if (block != null) {
loc = block.getLocation();
block.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 50F, true, true);
return;
}
Entity entity = evt.getEntity();
if (entity != null) {
loc = entity.getLocation();
entity.getWorld().createExplosion(loc.getX(), loc.getY(), loc.getZ(), 50F, true, true);
}
}
示例15: event
import org.bukkit.entity.Projectile; //導入依賴的package包/類
@EventHandler
public void event(EntityDamageByEntityEvent e) {
if (e.getEntity() instanceof Player) {
OMGPlayer damaged = get((Player) e.getEntity());
if (g.state != GameState.INGAME || damaged.team == g.spectatorTeam || damaged.invulnerable || (Area.registeredAreas.values().stream().anyMatch(a -> a.isInside(e.getEntity().getLocation().getBlock().getLocation()) && (!a.cancelDamage.containsKey(damaged.team) || a.cancelDamage.get(damaged.team).contains(OMGDamageCause.getByBukkit(e.getCause())))))) {
e.setCancelled(true);
return;
}
if (e.getDamager() instanceof Projectile) damaged.lastProjectileShotBy = (Projectile) e.getDamager();
if (e.getDamager() instanceof Player || (e.getDamager() instanceof Projectile && ((Projectile) e.getDamager()).getShooter() instanceof Player)) {
OMGPlayer damager = e.getDamager() instanceof Player ? get((Player) e.getDamager()) : get((Player) ((Projectile) e.getDamager()).getShooter());
if (damaged.team == damager.team && !damaged.team.allowFriendlyFire) {
e.setCancelled(true);
e.setDamage(0);
return;
}
damaged.lastDamager = damager;
}
new OMGDamageEvent(e, get((Player) e.getEntity()), e.getDamager(), OMGDamageCause.getByBukkit(e.getCause()), (float) e.getDamage());
}
}