@EventHandler public void on(ProjectileLaunchEvent event) { Entity entity = event.getEntity(); if (!(entity instanceof Egg)) return; Egg egg = (Egg) entity; // skip our own eggs if (((CraftEgg) entity).getHandle() instanceof CustomChickenEgg) return; // cancel the launch event.setCancelled(true); EntityEgg original = ((CraftEgg) egg).getHandle(); // create our own egg from the original and spawn that CustomChickenEgg newEgg = new CustomChickenEgg(original.getWorld(), original.getShooter()); original.getWorld().addEntity(newEgg, CreatureSpawnEvent.SpawnReason.EGG); }
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onProjectileLaunch(ProjectileLaunchEvent event) { if (!(event.getEntity().getShooter() instanceof Player)) { return; } Player player = (Player) event.getEntity().getShooter(); NormalAchievements category; if (event.getEntity() instanceof Snowball) { category = NormalAchievements.SNOWBALLS; } else if (event.getEntity() instanceof Egg) { category = NormalAchievements.EGGS; } else { return; } if (plugin.getDisabledCategorySet().contains(category.toString())) { return; } if (!shouldIncreaseBeTakenIntoAccount(player, category)) { return; } updateStatisticAndAwardAchievementsIfAvailable(player, category, 1); }
@EventHandler public void eggBreak(final ProjectileHitEvent e) { if (e.getEntity() instanceof Egg && eggs.contains(e.getEntity())) { final Location l = e.getEntity().getLocation(); int radius = 3; final int[][] newLocs = { { radius, 0 }, { -radius, 0 }, { 0, radius }, { 0, -radius } }; for (int i = 0; i < 4; i++) { final int count = i; Bukkit.getScheduler().scheduleSyncDelayedTask(instance, new Runnable() { public void run() { e.getEntity().getWorld().createExplosion(l.getX() + newLocs[count][0], l.getY(), l.getZ() + newLocs[count][1], 2.3F, false, true); } }, 4 * i); } eggs.remove(e.getEntity()); } }
@EventHandler public void onPlayerInteract(PlayerInteractEvent event) { Player player = event.getPlayer(); if ((player.hasPermission("tse.use")) && ((event.getAction().equals(Action.RIGHT_CLICK_AIR)) || (event.getAction().equals(Action.RIGHT_CLICK_BLOCK)))) { if (event.getItem() == null) return; ItemStack item = event.getItem(); if ((!(item.getData() instanceof SpawnEgg)) || (item == null)) return; SpawnEgg segg = (SpawnEgg) item.getData(); Egg egg = (Egg) event.getPlayer().launchProjectile(Egg.class); this.eggs.put(egg, segg.getSpawnedType()); if (item.getAmount() > 1) item.setAmount(item.getAmount() - 1); else { player.getInventory().remove(item); } event.setCancelled(true); } }
public static String getTranslationKey(Entity entity) { if(entity instanceof TNTPrimed) { return "tile.tnt.name"; } else if(entity instanceof Egg) { return "item.egg.name"; } else { final String id = EntityTypes.b(((CraftEntity) entity).getHandle()); return "entity." + (id != null ? id : "generic") + ".name"; } }
@EventHandler public void projectileLaunch(ProjectileLaunchEvent e) { Projectile projectile = e.getEntity(); if (projectile instanceof Snowball || projectile instanceof Egg || projectile instanceof Arrow) { if (projectile.getShooter() instanceof Player) { GamePlayer shooter = SkyWarsReloaded.getPC().getPlayer(((Player) projectile.getShooter()).getUniqueId()); String effect = shooter.getProjEffect(); if (effect != null) { if (!effect.equalsIgnoreCase("normal") && shooter.inGame()) { SkyWarsReloaded.getProjC().addProjectile(projectile, shooter.getProjEffect()); } } } } }
public PlayerEggThrowEvent(final Player player, final Egg egg, final boolean hatching, final byte numHatches, final EntityType hatchingType) { super(player); this.egg = egg; this.hatching = hatching; this.numHatches = numHatches; this.hatchType = hatchingType; }
/** * Find the EggTrackerEntry from an Egg. * @param egg - The Egg to look for. * @return The EggTrackerEntry matching the given Egg, or null if one is not found. */ public EggTrackerEntry getEntry(Egg egg) { for (EggTrackerEntry entry : this.entries) { if (entry.getEgg() == egg) { return entry; } } return null; }
@EventHandler public void throwEgg(PlayerEggThrowEvent event) { Egg egg = event.getEgg(); if (this.eggs.containsKey(egg)) { EntityType entityType = (EntityType) this.eggs.get(egg); Entity entity = egg.getWorld().spawnEntity(egg.getLocation(), entityType); if (entityType == EntityType.SHEEP) { ((Sheep) entity).setColor(org.bukkit.DyeColor.values()[((int) (java.lang.Math.random() * org.bukkit.DyeColor.values().length))]); event.setHatching(false); } } }
@SuppressWarnings("deprecation") @Override public Egg throwEgg() { if (getHandle() instanceof ProjectileSource) { return PoreEgg.of( ((ProjectileSource) getHandle()).launchProjectile( org.spongepowered.api.entity.projectile.Egg.class ).orElse(null) ); } // CB never returns null here so we shouldn't either // this will prevent ambiguity if something breaks (as opposed to if we let a plugin throw an NPE) throw new UnsupportedOperationException("Not a ProjectileSource"); }
@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(); }
@Deprecated public Egg throwEgg() { return launchProjectile(Egg.class); }
@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(); }
@EventHandler(priority = EventPriority.HIGH) public void onEntityDamage(EntityDamageEvent event) { //cancel if on periscope if( event.getEntity() instanceof Player ) { Player player = (Player)event.getEntity(); for( Periscope p: NavyCraft.allPeriscopes ) { if( p.user == player ) { event.setCancelled(true); return; } } if( event.getCause() == DamageCause.SUFFOCATION ) { Craft c = Craft.getCraft(player.getLocation().getBlockX(),player.getLocation().getBlockY(), player.getLocation().getBlockZ()); if( c != null ) { event.setCancelled(true); return; } } } if ( event instanceof EntityDamageByEntityEvent ) { Entity attacker = ((EntityDamageByEntityEvent) event).getDamager(); if( attacker instanceof Egg ) { if( NavyCraft.explosiveEggsList.contains((Egg)attacker) ) { event.setDamage(5); } } } }
@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); } } }
@Deprecated public PlayerEggThrowEvent(Player player, Egg egg, boolean hatching, byte numHatches, CreatureType hatchingType) { this(player, egg, hatching, numHatches, hatchingType.toEntityType()); }
public Egg throwEgg() { throw new NotImplementedException("throwEgg()"); }