Java Code Examples for cn.nukkit.event.entity.ProjectileLaunchEvent#isCancelled()
The following examples show how to use
cn.nukkit.event.entity.ProjectileLaunchEvent#isCancelled() .
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: ProjectileItem.java From Jupiter with GNU General Public License v3.0 | 5 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); this.count--; if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { projectile.spawnToAll(); player.getLevel().addSound(new LaunchSound(player), player.getViewers().values()); } } else { projectile.spawnToAll(); } } else { return false; } return true; }
Example 2
Source File: Player.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public void startFishing(Item fishingRod) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", x)) .add(new DoubleTag("", y + this.getEyeHeight())) .add(new DoubleTag("", z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(yaw / 180 + Math.PI) * Math.cos(pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(yaw / 180 * Math.PI) * Math.cos(pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) yaw)) .add(new FloatTag("", (float) pitch))); double f = 1; EntityFishingHook fishingHook = new EntityFishingHook(chunk, nbt, this); fishingHook.setMotion(new Vector3(-Math.sin(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * f * f, -Math.sin(Math.toRadians(pitch)) * f * f, Math.cos(Math.toRadians(yaw)) * Math.cos(Math.toRadians(pitch)) * f * f)); ProjectileLaunchEvent ev = new ProjectileLaunchEvent(fishingHook); this.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { fishingHook.kill(); } else { fishingHook.spawnToAll(); this.fishing = fishingHook; fishingHook.rod = fishingRod; } }
Example 3
Source File: ProjectileItem.java From Nukkit with GNU General Public License v3.0 | 5 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); this.count--; if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { projectile.spawnToAll(); player.getLevel().addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values()); } } else { projectile.spawnToAll(); } } else { return false; } return true; }
Example 4
Source File: ItemBow.java From Jupiter with GNU General Public License v3.0 | 4 votes |
public boolean onReleaseUsing(Player player) { Item itemArrow = Item.get(Item.ARROW, 0, 1); if (player.isSurvival() && !player.getInventory().contains(itemArrow)) { player.getInventory().sendContents(player); return false; } double damage = 2; boolean flame = false; if (this.hasEnchantments()) { Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER); if (bowDamage != null && bowDamage.getLevel() > 0) { damage += 0.25 * (bowDamage.getLevel() + 1); } Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME); flame = flameEnchant != null && flameEnchant.getLevel() > 0; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)) .add(new FloatTag("", (float) -player.pitch))) .putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0) .putDouble("damage", damage); int diff = (Server.getInstance().getTick() - player.getStartActionTick()); double p = (double) diff / 20; double f = Math.min((p * p + p * 2) / 3, 1) * 2; EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f); if (f < 0.1 || diff < 5) { entityShootBowEvent.setCancelled(); } Server.getInstance().getPluginManager().callEvent(entityShootBowEvent); if (entityShootBowEvent.isCancelled()) { entityShootBowEvent.getProjectile().kill(); player.getInventory().sendContents(player); } else { entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce())); if (player.isSurvival()) { Enchantment infinity; if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0) player.getInventory().removeItem(itemArrow); if (!this.isUnbreakable()) { Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY); if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) { this.setDamage(this.getDamage() + 1); if (this.getDamage() >= 385) { player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0)); } else { player.getInventory().setItemInHand(this); } } } } if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) { ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile()); Server.getInstance().getPluginManager().callEvent(projectev); if (projectev.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().spawnToAll(); player.level.addSound(new LaunchSound(player), player.getViewers().values()); } } else { entityShootBowEvent.getProjectile().spawnToAll(); } } return true; }
Example 5
Source File: ItemBow.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onRelease(Player player, int ticksUsed) { Item itemArrow = Item.get(Item.ARROW, 0, 1); Inventory inventory = player.getOffhandInventory(); if (!inventory.contains(itemArrow) && !(inventory = player.getInventory()).contains(itemArrow) && player.isSurvival()) { player.getOffhandInventory().sendContents(player); inventory.sendContents(player); return false; } double damage = 2; Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER); if (bowDamage != null && bowDamage.getLevel() > 0) { damage += 0.25 * (bowDamage.getLevel() + 1); } Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME); boolean flame = flameEnchant != null && flameEnchant.getLevel() > 0; CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)) .add(new FloatTag("", (float) -player.pitch))) .putShort("Fire", flame ? 45 * 60 : 0) .putDouble("damage", damage); double p = (double) ticksUsed / 20; double f = Math.min((p * p + p * 2) / 3, 1) * 2; EntityArrow arrow = (EntityArrow) Entity.createEntity("Arrow", player.chunk, nbt, player, f == 2); if (arrow == null) { return false; } EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, arrow, f); if (f < 0.1 || ticksUsed < 3) { entityShootBowEvent.setCancelled(); } Server.getInstance().getPluginManager().callEvent(entityShootBowEvent); if (entityShootBowEvent.isCancelled()) { entityShootBowEvent.getProjectile().kill(); player.getInventory().sendContents(player); player.getOffhandInventory().sendContents(player); } else { entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce())); Enchantment infinityEnchant = this.getEnchantment(Enchantment.ID_BOW_INFINITY); boolean infinity = infinityEnchant != null && infinityEnchant.getLevel() > 0; EntityProjectile projectile; if (infinity && (projectile = entityShootBowEvent.getProjectile()) instanceof EntityArrow) { ((EntityArrow) projectile).setPickupMode(EntityArrow.PICKUP_CREATIVE); } if (player.isSurvival()) { if (!infinity) { inventory.removeItem(itemArrow); } if (!this.isUnbreakable()) { Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY); if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) { this.setDamage(this.getDamage() + 1); if (this.getDamage() >= getMaxDurability()) { this.count--; } player.getInventory().setItemInHand(this); } } } if (entityShootBowEvent.getProjectile() != null) { ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile()); Server.getInstance().getPluginManager().callEvent(projectev); if (projectev.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_BOW); } } } return true; }
Example 6
Source File: ProjectileItem.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onClickAir(Player player, Vector3 directionVector) { CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight() - 0.30000000149011612)) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", directionVector.x)) .add(new DoubleTag("", directionVector.y)) .add(new DoubleTag("", directionVector.z))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (float) player.yaw)) .add(new FloatTag("", (float) player.pitch))); this.correctNBT(nbt); Entity projectile = Entity.createEntity(this.getProjectileEntityType(), player.getLevel().getChunk(player.getFloorX() >> 4, player.getFloorZ() >> 4), nbt, player); if (projectile != null) { if (projectile instanceof EntityEnderPearl) { if (player.getServer().getTick() - player.getLastEnderPearlThrowingTick() < 20) { projectile.kill(); return false; } } projectile.setMotion(projectile.getMotion().multiply(this.getThrowForce())); if (projectile instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent((EntityProjectile) projectile); player.getServer().getPluginManager().callEvent(ev); if (ev.isCancelled()) { projectile.kill(); } else { if (!player.isCreative()) { this.count--; } if (projectile instanceof EntityEnderPearl) { player.onThrowEnderPearl(); } projectile.spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_BOW); } } } else { return false; } return true; }
Example 7
Source File: ItemTrident.java From Nukkit with GNU General Public License v3.0 | 4 votes |
@Override public boolean onRelease(Player player, int ticksUsed) { this.useOn(player); CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)) .add(new FloatTag("", (float) -player.pitch))); double p = (double) ticksUsed / 20; double f = Math.min((p * p + p * 2) / 3, 1) * 2; EntityThrownTrident trident = (EntityThrownTrident) Entity.createEntity("ThrownTrident", player.chunk, nbt, player, f == 2); if (trident == null) { return false; } trident.setItem(this); EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, trident, f); if (f < 0.1 || ticksUsed < 5) { entityShootBowEvent.setCancelled(); } Server.getInstance().getPluginManager().callEvent(entityShootBowEvent); if (entityShootBowEvent.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce())); if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) { ProjectileLaunchEvent ev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile()); Server.getInstance().getPluginManager().callEvent(ev); if (ev.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().spawnToAll(); player.getLevel().addLevelSoundEvent(player, LevelSoundEventPacket.SOUND_ITEM_TRIDENT_THROW); if (!player.isCreative()) { this.count--; player.getInventory().setItemInHand(this); } } } } return true; }
Example 8
Source File: ItemBow.java From Nukkit with GNU General Public License v3.0 | 4 votes |
public boolean onReleaseUsing(Player player) { Item itemArrow = Item.get(Item.ARROW, 0, 1); if (player.isSurvival() && !player.getInventory().contains(itemArrow)) { player.getInventory().sendContents(player); return false; } double damage = 2; boolean flame = false; if (this.hasEnchantments()) { Enchantment bowDamage = this.getEnchantment(Enchantment.ID_BOW_POWER); if (bowDamage != null && bowDamage.getLevel() > 0) { damage += 0.25 * (bowDamage.getLevel() + 1); } Enchantment flameEnchant = this.getEnchantment(Enchantment.ID_BOW_FLAME); flame = flameEnchant != null && flameEnchant.getLevel() > 0; } CompoundTag nbt = new CompoundTag() .putList(new ListTag<DoubleTag>("Pos") .add(new DoubleTag("", player.x)) .add(new DoubleTag("", player.y + player.getEyeHeight())) .add(new DoubleTag("", player.z))) .putList(new ListTag<DoubleTag>("Motion") .add(new DoubleTag("", -Math.sin(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", -Math.sin(player.pitch / 180 * Math.PI))) .add(new DoubleTag("", Math.cos(player.yaw / 180 * Math.PI) * Math.cos(player.pitch / 180 * Math.PI)))) .putList(new ListTag<FloatTag>("Rotation") .add(new FloatTag("", (player.yaw > 180 ? 360 : 0) - (float) player.yaw)) .add(new FloatTag("", (float) -player.pitch))) .putShort("Fire", player.isOnFire() || flame ? 45 * 60 : 0) .putDouble("damage", damage); int diff = (Server.getInstance().getTick() - player.getStartActionTick()); double p = (double) diff / 20; double f = Math.min((p * p + p * 2) / 3, 1) * 2; EntityShootBowEvent entityShootBowEvent = new EntityShootBowEvent(player, this, new EntityArrow(player.chunk, nbt, player, f == 2), f); if (f < 0.1 || diff < 5) { entityShootBowEvent.setCancelled(); } Server.getInstance().getPluginManager().callEvent(entityShootBowEvent); if (entityShootBowEvent.isCancelled()) { entityShootBowEvent.getProjectile().kill(); player.getInventory().sendContents(player); } else { entityShootBowEvent.getProjectile().setMotion(entityShootBowEvent.getProjectile().getMotion().multiply(entityShootBowEvent.getForce())); if (player.isSurvival()) { Enchantment infinity; if (!this.hasEnchantments() || (infinity = this.getEnchantment(Enchantment.ID_BOW_INFINITY)) == null || infinity.getLevel() <= 0) player.getInventory().removeItem(itemArrow); if (!this.isUnbreakable()) { Enchantment durability = this.getEnchantment(Enchantment.ID_DURABILITY); if (!(durability != null && durability.getLevel() > 0 && (100 / (durability.getLevel() + 1)) <= new Random().nextInt(100))) { this.setDamage(this.getDamage() + 1); if (this.getDamage() >= 385) { player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0)); } else { player.getInventory().setItemInHand(this); } } } } if (entityShootBowEvent.getProjectile() instanceof EntityProjectile) { ProjectileLaunchEvent projectev = new ProjectileLaunchEvent(entityShootBowEvent.getProjectile()); Server.getInstance().getPluginManager().callEvent(projectev); if (projectev.isCancelled()) { entityShootBowEvent.getProjectile().kill(); } else { entityShootBowEvent.getProjectile().spawnToAll(); player.level.addSound(player, Sound.RANDOM_BOW, 1, 1, player.getViewers().values()); } } else { entityShootBowEvent.getProjectile().spawnToAll(); } } return true; }