@Override public Relation compare(final EntityData e, final ItemType i) { if (e instanceof Item) return Relation.get(i.isOfType(((Item) e).getItemStack())); if (e instanceof ThrownPotion) return Relation.get(i.isOfType(Material.POTION.getId(), PotionEffectUtils.guessData((ThrownPotion) e))); if (Skript.classExists("org.bukkit.entity.WitherSkull") && e instanceof WitherSkull) return Relation.get(i.isOfType(Material.SKULL_ITEM.getId(), (short) 1)); if (entityMaterials.containsKey(e.getType())) return Relation.get(i.isOfType(entityMaterials.get(e.getType()).getId(), (short) 0)); for (final Entry<Class<? extends Entity>, Material> m : entityMaterials.entrySet()) { if (m.getKey().isAssignableFrom(e.getType())) return Relation.get(i.isOfType(m.getValue().getId(), (short) 0)); } return Relation.NOT_EQUAL; }
@EventHandler public void onEntityDamageByEntityEvent(EntityDamageByEntityEvent e){ if(e.getEntity() instanceof WitherSkull) { if(e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) { if (e.getDamager() instanceof WitherSkull) { if (e.getEntity() instanceof Player) { e.setDamage(20.0); } } } } }
@EventHandler public void onChunkProtect(ChunkLoadEvent e) { for(Entity entity : e.getChunk().getEntities()) { if(entity instanceof WitherSkull) { WitherSkull wither = (WitherSkull) entity; if(pl.getConfiguration().getDebugConfig().isEnabled()) { xEssentials.log("removed wither skull at: {" + wither.getWorld().getName() + ", " + wither.getLocation().getBlockX() + ", " + wither.getLocation().getBlockY() + ", " + wither.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO); } wither.remove(); } else if(entity instanceof Fireball) { Fireball fb = (Fireball) entity; if(pl.getConfiguration().getDebugConfig().isEnabled()) { xEssentials.log("removed fireball at: {" + fb.getWorld().getName() + ", " + fb.getLocation().getBlockX() + ", " + fb.getLocation().getBlockY() + ", " + fb.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO); } fb.remove(); } } }
@EventHandler public void onChunkProtect(ChunkUnloadEvent e) { for(Entity entity : e.getChunk().getEntities()) { if(entity instanceof WitherSkull) { WitherSkull wither = (WitherSkull) entity; if(pl.getConfiguration().getDebugConfig().isEnabled()) { xEssentials.log("removed wither skull at: {" + wither.getWorld().getName() + ", " + wither.getLocation().getBlockX() + ", " + wither.getLocation().getBlockY() + ", " + wither.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO); } wither.remove(); } else if(entity instanceof Fireball) { Fireball fb = (Fireball) entity; if(pl.getConfiguration().getDebugConfig().isEnabled()) { xEssentials.log("removed fireball at: {" + fb.getWorld().getName() + ", " + fb.getLocation().getBlockX() + ", " + fb.getLocation().getBlockY() + ", " + fb.getLocation().getBlockZ() + "} to prevent lag", LogType.INFO); } fb.remove(); } } }
@EventHandler public void onWitherSkullExplosion(EntityDamageByEntityEvent e) { if (!witherEnabled || e == null || !(e.getEntity() instanceof WitherSkull) || !plugin.isSkyAssociatedWorld(e.getEntity().getWorld())) { return; } // Find owner ProjectileSource shooter = ((WitherSkull) e.getEntity()).getShooter(); if (shooter instanceof Wither) { handleWitherRampage(e, (Wither) shooter, e.getDamager().getLocation()); } }
@Override public CastResult onCast(User user, int power, String[] args) { Player player = user.getPlayer(); player.launchProjectile(WitherSkull.class); player.getWorld().playSound(player.getLocation(), Sound.WITHER_SHOOT, 1.0F, 0F); return CastResult.SUCCESS; }
@EventHandler public void onInteract(PlayerInteractEvent e) { Location loc = e.getPlayer().getLocation(); if(e.getAction() == Action.RIGHT_CLICK_AIR) { if(e.getPlayer().getItemInHand().getType() == Material.WOOD_HOE) { WitherSkull bullet = (WitherSkull) e.getPlayer().getWorld().spawnEntity(e.getPlayer().getLocation(), EntityType.WITHER_SKULL); bullet.setVelocity(e.getPlayer().getLocation().getDirection().multiply(1.5)); bullet.getWorld().playEffect(loc, Effect.SMOKE, 0, 50); e.getPlayer().playSound(loc, Sound.GHAST_FIREBALL, 100, 0); } } }
@Override public void doOnRightClick(Racer racer, Action action) { racer.getPlayer().sendMessage(getMessage()); Location loc = racer.getPlayer().getEyeLocation(); WitherSkull skull = (WitherSkull) loc.getWorld().spawnEntity(loc, EntityType.WITHER_SKULL); skull.setShooter(racer.getPlayer()); skull.setVelocity(loc.getDirection().multiply(EquestrianDash.plugin.getConfig().getDouble("Powerups.Wither.SpeedMultiplier"))); racer.getPlayer().getInventory().clear(); }
@EventHandler public void onExplode(final EntityExplodeEvent event) { final Entity e = event.getEntity(); //e.getServer().broadcastMessage("Exploded me!"); event.blockList().clear(); try { ItemBox ib = plugin.getItemBoxRegistry().getByLocation(e.getLocation()); if (ib != null) { ib.respawn(); event.setCancelled(true); } else if (event.getEntity() instanceof WitherSkull) { WitherSkull w = (WitherSkull) event.getEntity(); if (w.isCharged()) { w.getWorld().strikeLightning(w.getLocation()); } } } catch(Exception ex) { // PLEASE DON'T KILL ME, JAVA GODS, I CAN'T FIGURE OUT WHY IT'S CRASHING. :( } }
@EventHandler public void disableExplosionWithers(EntityExplodeEvent e) { if(e.getEntity() instanceof WitherSkull) { e.setCancelled(true); } else if(e.getEntity() instanceof Wither) { e.setCancelled(true); } }
@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(); }
@Override public boolean run(Player player, String[] args, int power) { if (blockBreak(player)) { return false; } player.launchProjectile(WitherSkull.class); Effects.playEffect(Sound.WITHER_SHOOT, player.getLocation()); return true; }
@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(); }
@Override public WitherSkull getBukkitEntity() { return getCraftBukkitEntity(); }
@EventHandler public void disableExplosionWithers(EntityExplodeEvent e) { if(e.getEntity() instanceof WitherSkull) { e.setCancelled(true); } }
@Override public void onShootBow(EntityShootBowEvent event, DelayedPlayerDetails details) { Entity skull = event.getEntity().launchProjectile(WitherSkull.class); skull.setVelocity(event.getProjectile().getVelocity()); event.setProjectile(skull); }
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(); } }
/** * Gets the underlying entity as Bukkit entity. May be null if not spawned yet by {@link #spawn(Location)}. * * @return The Bukkit entity */ public WitherSkull getBukkitEntity() { return nativeHander.getBukkitEntity(); }
public abstract WitherSkull getBukkitEntity();