org.bukkit.entity.Bat Java Examples

The following examples show how to use org.bukkit.entity.Bat. 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: GrapplingHookListener.java    From Slimefun4 with GNU General Public License v3.0 6 votes vote down vote up
public void addGrapplingHook(Player p, Arrow arrow, Bat bat, boolean dropItem, long despawnTicks) {
    GrapplingHookEntity hook = new GrapplingHookEntity(p, arrow, bat, dropItem);
    UUID uuid = p.getUniqueId();

    activeHooks.put(uuid, hook);

    // To fix issue #253
    Slimefun.runSync(() -> {
        GrapplingHookEntity entity = activeHooks.get(uuid);

        if (entity != null) {
            SlimefunPlugin.getBowListener().getProjectileData().remove(uuid);
            entity.remove();

            Slimefun.runSync(() -> {
                activeHooks.remove(uuid);
                invulnerability.remove(uuid);
            }, 20L);
        }
    }, despawnTicks);
}
 
Example #2
Source File: GrapplingHook.java    From Slimefun4 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ItemUseHandler getItemHandler() {
    return e -> {
        Player p = e.getPlayer();
        UUID uuid = p.getUniqueId();

        if (!e.getClickedBlock().isPresent() && !SlimefunPlugin.getGrapplingHookListener().isGrappling(uuid)) {
            e.cancel();

            if (p.getInventory().getItemInOffHand().getType() == Material.BOW) {
                // Cancel, to fix dupe #740
                return;
            }

            ItemStack item = e.getItem();

            if (item.getType() == Material.LEAD) {
                item.setAmount(item.getAmount() - 1);
            }

            Vector direction = p.getEyeLocation().getDirection().multiply(2.0);
            Arrow arrow = p.getWorld().spawn(p.getEyeLocation().add(direction.getX(), direction.getY(), direction.getZ()), Arrow.class);
            arrow.setShooter(p);
            arrow.setVelocity(direction);

            Bat bat = (Bat) p.getWorld().spawnEntity(p.getLocation(), EntityType.BAT);
            bat.setCanPickupItems(false);
            bat.setAI(false);
            bat.setSilent(true);
            bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100000, 100000));
            bat.setLeashHolder(arrow);

            boolean state = item.getType() != Material.SHEARS;
            SlimefunPlugin.getGrapplingHookListener().addGrapplingHook(p, arrow, bat, state, despawnTicks.getValue());
        }
    };
}
 
Example #3
Source File: SpigotListener.java    From ObsidianDestroyer with GNU General Public License v3.0 5 votes vote down vote up
@EventHandler(ignoreCancelled = true)
public void onEntityExplode(BlockExplodeEvent event) {
    if (event == null || ChunkManager.getInstance().getDisabledWorlds().contains(event.getBlock().getLocation().getWorld().getName())) {
        return; // do not do anything in case explosions get cancelled
    }

    final Block detonatorBlock = event.getBlock();

    if (detonatorBlock == null) {
        return;
    }
    if (detonatorBlock.hasMetadata("ObbyEntity")) {
        return;
    }
    if (event.getYield() <= 0) {
        return;
    }

    // feeling batty?! Spawn a bat to tie onto the EntityExplodeEvent.
    try {
        Bat bat = (Bat) Bukkit.getWorld(detonatorBlock.getWorld().getName()).spawnEntity(detonatorBlock.getLocation(), EntityType.BAT);
        if (bat != null) {
            bat.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 100, 1), true);
        }
        // Construct a new event but don't call it.
        EntityExplodeEvent entityExplodeEvent = new EntityExplodeEvent(bat, event.getBlock().getLocation(), event.blockList(), event.getYield());
        ChunkManager.getInstance().handleExplosion(entityExplodeEvent, event.getBlock().getLocation());
        if (bat != null) {
            bat.remove(); // bye
        }
    } catch (Exception e) {
        ObsidianDestroyer.debug(e.toString());
    }
}
 
Example #4
Source File: BatBomb.java    From NBTEditor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onExplode(Item item, Location location) {
	List<Entity> passengers = item.getPassengers();
	if (passengers.size() != 0) {
		Entity bat = passengers.get(0);
		if (bat != null && bat instanceof Bat && !bat.isDead()) {
			bat.remove();
			spawnBatsAt(location, 10, 50);
		}
	}
}
 
Example #5
Source File: EntityBatPet.java    From SonarPet with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Bat getBukkitEntity() {
    return (Bat) super.getBukkitEntity();
}