org.bukkit.event.entity.EntityTeleportEvent Java Examples

The following examples show how to use org.bukkit.event.entity.EntityTeleportEvent. 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: ItemChorusFruit.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean attemptEnderTeleport(EntityHuman entity, final double x, final double y, final double z) {
    final double prevX = entity.locX;
    final double prevY = entity.locY;
    final double prevZ = entity.locZ;
    entity.locX = x;
    entity.locY = y;
    entity.locZ = z;
    boolean success = false;
    BlockPosition blockposition = new BlockPosition(entity.locX, entity.locY, entity.locZ);
    if (entity.world.isLoaded(blockposition)) {
        boolean foundPos = false;
        while (!foundPos && (blockposition.getY() > 0)) {
            final BlockPosition blockposition2 = blockposition.down();
            final Block block = entity.world.getType(blockposition2).getBlock();
            if (block.getMaterial().isSolid()) {
                foundPos = true;
            } else {
                --entity.locY;
                blockposition = blockposition2;
            }
        }
        if (foundPos) {
            final EntityTeleportEvent teleport = new EntityTeleportEvent(entity.getBukkitEntity(), new Location(entity.world.getWorld(), prevX, prevY, prevZ), new Location(entity.world.getWorld(), entity.locX, entity.locY, entity.locZ));
            entity.world.getServer().getPluginManager().callEvent(teleport);
            if (teleport.isCancelled()) {
                return false;
            }
            final Location to = teleport.getTo();
            entity.enderTeleportTo(to.getX(), to.getY(), to.getZ());
            if (entity.world.getCubes(entity, entity.getBoundingBox()).isEmpty() && !entity.world.containsLiquid(entity.getBoundingBox())) {
                success = true;
            }
        }
    }
    if (!success) {
        entity.setPosition(prevX, prevY, prevZ);
        return false;
    }
    final short count = 128;
    for (int i = 0; i < count; ++i) {
        final double d6 = i / (count - 1.0);
        final float spreadX = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final float spreadY = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final float spreadZ = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final double pX = prevX + ((entity.locX - prevX) * d6) + ((entity.bc().nextDouble() - 0.5) * entity.width * 2.0);
        final double pY = prevY + ((entity.locY - prevY) * d6) + (entity.bc().nextDouble() * entity.length);
        final double pZ = prevZ + ((entity.locZ - prevZ) * d6) + ((entity.bc().nextDouble() - 0.5) * entity.width * 2.0);
        entity.world.addParticle(EnumParticle.PORTAL, pX, pY, pZ, spreadX, spreadY, spreadZ);
    }
    entity.world.makeSound(prevX, prevY, prevZ, "mob.endermen.portal", 1.0f, 1.0f);
    entity.makeSound("mob.endermen.portal", 1.0f, 1.0f);
    return true;
}
 
Example #2
Source File: ItemChorusFruit.java    From Carbon-2 with GNU Lesser General Public License v3.0 4 votes vote down vote up
private boolean attemptEnderTeleport(EntityHuman entity, final double x, final double y, final double z) {
    final double prevX = entity.locX;
    final double prevY = entity.locY;
    final double prevZ = entity.locZ;
    entity.locX = x;
    entity.locY = y;
    entity.locZ = z;
    boolean success = false;
    BlockPosition blockposition = new BlockPosition(entity.locX, entity.locY, entity.locZ);
    if (entity.world.isLoaded(blockposition)) {
        boolean foundPos = false;
        while (!foundPos && (blockposition.getY() > 0)) {
            final BlockPosition blockposition2 = blockposition.down();
            final Block block = entity.world.getType(blockposition2).getBlock();
            if (block.getMaterial().isSolid()) {
                foundPos = true;
            } else {
                --entity.locY;
                blockposition = blockposition2;
            }
        }
        if (foundPos) {
            final EntityTeleportEvent teleport = new EntityTeleportEvent(entity.getBukkitEntity(), new Location(entity.world.getWorld(), prevX, prevY, prevZ), new Location(entity.world.getWorld(), entity.locX, entity.locY, entity.locZ));
            entity.world.getServer().getPluginManager().callEvent(teleport);
            if (teleport.isCancelled()) {
                return false;
            }
            final Location to = teleport.getTo();
            entity.enderTeleportTo(to.getX(), to.getY(), to.getZ());
            if (entity.world.getCubes(entity, entity.getBoundingBox()).isEmpty() && !entity.world.containsLiquid(entity.getBoundingBox())) {
                success = true;
            }
        }
    }
    if (!success) {
        entity.setPosition(prevX, prevY, prevZ);
        return false;
    }
    final short count = 128;
    for (int i = 0; i < count; ++i) {
        final double d6 = i / (count - 1.0);
        final float spreadX = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final float spreadY = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final float spreadZ = (entity.bc().nextFloat() - 0.5f) * 0.2f;
        final double pX = prevX + ((entity.locX - prevX) * d6) + ((entity.bc().nextDouble() - 0.5) * entity.width * 2.0);
        final double pY = prevY + ((entity.locY - prevY) * d6) + (entity.bc().nextDouble() * entity.length);
        final double pZ = prevZ + ((entity.locZ - prevZ) * d6) + ((entity.bc().nextDouble() - 0.5) * entity.width * 2.0);
        entity.world.addParticle(EnumParticle.PORTAL, pX, pY, pZ, spreadX, spreadY, spreadZ);
    }
    entity.world.makeSound(prevX, prevY, prevZ, "mob.endermen.portal", 1.0f, 1.0f);
    entity.makeSound("mob.endermen.portal", 1.0f, 1.0f);
    return true;
}
 
Example #3
Source File: LivingEntityShopListener.java    From Shopkeepers with GNU General Public License v3.0 4 votes vote down vote up
@EventHandler(ignoreCancelled = true)
void onEntityTeleport(EntityTeleportEvent event) {
	if (plugin.isShopkeeper(event.getEntity())) {
		event.setCancelled(true);
	}
}