org.bukkit.entity.Fireball Java Examples

The following examples show how to use org.bukkit.entity.Fireball. 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: ThrowableFireballListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFireballThrow(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    if (event.getItem() != null) {
        ItemStack stack = event.getItem();
        String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX);
        if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) {
            String[] properties = unhash.split(":");
            double damage = Double.parseDouble(properties[2]);
            float explosion = (float) Double.parseDouble(properties[2]);

            Fireball fireball = player.launchProjectile(Fireball.class);
            fireball.setIsIncendiary(false);
            fireball.setYield(explosion);
            Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame());

            event.setCancelled(true);

            if (stack.getAmount() > 1) {
                stack.setAmount(stack.getAmount() - 1);
            } else {
                player.getInventory().remove(stack);
            }

            player.updateInventory();
        }
    }
}
 
Example #2
Source File: ThrowableFireballListener.java    From BedWars with GNU Lesser General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onFireballThrow(PlayerInteractEvent event) {
    Player player = event.getPlayer();

    if (!Main.isPlayerInGame(player)) {
        return;
    }

    if (event.getItem() != null) {
        ItemStack stack = event.getItem();
        String unhash = APIUtils.unhashFromInvisibleStringStartsWith(stack, THROWABLE_FIREBALL_PREFIX);
        if (unhash != null && (event.getAction() == Action.RIGHT_CLICK_BLOCK || event.getAction() == Action.RIGHT_CLICK_AIR)) {
            String[] properties = unhash.split(":");
            double damage = Double.parseDouble(properties[2]);
            float explosion = (float) Double.parseDouble(properties[2]);

            Fireball fireball = player.launchProjectile(Fireball.class);
            fireball.setIsIncendiary(false);
            fireball.setYield(explosion);
            Main.registerGameEntity(fireball, Main.getPlayerGameProfile(player).getGame());

            event.setCancelled(true);

            if (stack.getAmount() > 1) {
                stack.setAmount(stack.getAmount() - 1);
            } else {
                player.getInventory().remove(stack);
            }

            player.updateInventory();
        }
    }
}
 
Example #3
Source File: NetherTerraFormEvents.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler
public void onGhastExplode(EntityExplodeEvent event) {
    if (!plugin.getWorldManager().isSkyNether(event.getEntity().getWorld())) {
        return; // Bail out, not our problem
    }
    // TODO: 23/09/2015 - R4zorax: Perhaps enable this when island has a certain level?
    if (event.getEntity() instanceof Fireball) {
        Fireball fireball = (Fireball) event.getEntity();
        fireball.setIsIncendiary(false);
        fireball.setFireTicks(0);
        event.setCancelled(true);
    }
}
 
Example #4
Source File: BlockListener.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
@EventHandler(priority = EventPriority.NORMAL)
public void onProjectileHitEvent(ProjectileHitEvent event) {
	if (event.getEntity() instanceof Arrow) {
		ArrowFiredCache afc = CivCache.arrowsFired.get(event.getEntity().getUniqueId());
		if (afc != null) {
			afc.setHit(true);
		}
	}

	if (event.getEntity() instanceof Fireball) {
		CannonFiredCache cfc = CivCache.cannonBallsFired.get(event.getEntity().getUniqueId());
		if (cfc != null) {

			cfc.setHit(true);

			FireworkEffect fe = FireworkEffect.builder().withColor(Color.RED).withColor(Color.BLACK).flicker(true).with(Type.BURST).build();

			Random rand = new Random();
			int spread = 30;
			for (int i = 0; i < 15; i++) {
				int x = rand.nextInt(spread) - spread/2;
				int y = rand.nextInt(spread) - spread/2;
				int z = rand.nextInt(spread) - spread/2;


				Location loc = event.getEntity().getLocation();
				Location location = new Location(loc.getWorld(), loc.getX(),loc.getY(), loc.getZ());
				location.add(x, y, z);

				TaskMaster.syncTask(new FireWorkTask(fe, loc.getWorld(), loc, 5), rand.nextInt(30));
			}

		}
	}
}
 
Example #5
Source File: CannonFiredCache.java    From civcraft with GNU General Public License v2.0 5 votes vote down vote up
public CannonFiredCache(CannonTower fromTower, Location target, Fireball fireball) {
	this.fromTower = fromTower;
	this.target = target;
	this.fireball = fireball;
	this.uuid = fireball.getUniqueId();
	expired = Calendar.getInstance();
	expired.set(Calendar.SECOND, 30);
}
 
Example #6
Source File: CraftLivingEntity.java    From Thermos with GNU General Public License v3.0 4 votes vote down vote up
@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();
}
 
Example #7
Source File: CannonFiredCache.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public Fireball getFireball() {
	return fireball;
}
 
Example #8
Source File: CannonFiredCache.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
public void setFireball(Fireball fireball) {
	this.fireball = fireball;
}