Java Code Examples for org.bukkit.Location#getY()

The following examples show how to use org.bukkit.Location#getY() . These examples are extracted from open source projects. 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
public static ArmorStand getArmorStand(Location reactor, boolean createIfNoneExists) {
    Location l = new Location(reactor.getWorld(), reactor.getX() + 0.5, reactor.getY() + 0.7, reactor.getZ() + 0.5);

    for (Entity n : l.getChunk().getEntities()) {
        if (n instanceof ArmorStand && l.distanceSquared(n.getLocation()) < 0.4D) {
            return (ArmorStand) n;
        }
    }

    if (!createIfNoneExists) {
        return null;
    }

    ArmorStand hologram = SimpleHologram.create(l);
    hologram.setCustomNameVisible(false);
    hologram.setCustomName(null);
    return hologram;
}
 
Example 2
public static boolean isInArea(Location l, Location p1, Location p2) {
    if (!p1.getWorld().equals(l.getWorld())) {
        return false;
    }

    Location min = new Location(p1.getWorld(), Math.min(p1.getX(), p2.getX()), Math.min(p1.getY(), p2.getY()),
            Math.min(p1.getZ(), p2.getZ()));
    Location max = new Location(p1.getWorld(), Math.max(p1.getX(), p2.getX()), Math.max(p1.getY(), p2.getY()),
            Math.max(p1.getZ(), p2.getZ()));
    return (min.getX() <= l.getX() && min.getY() <= l.getY() && min.getZ() <= l.getZ() && max.getX() >= l.getX()
            && max.getY() >= l.getY() && max.getZ() >= l.getZ());
}
 
Example 3
Source Project: TAB   File: MethodAPI_v1_12_R1.java    License: Apache License 2.0 5 votes vote down vote up
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
	EntityLiving entity = (EntityLiving) entityliving;
	entity.locX = loc.getX();
	entity.locY = loc.getY();
	entity.locZ = loc.getZ();
	entity.yaw = loc.getYaw();
	entity.pitch = loc.getPitch();
	return new PacketPlayOutEntityTeleport(entity);
}
 
Example 4
Source Project: Thermos   File: CraftWorld.java    License: GNU General Public License v3.0 5 votes vote down vote up
public void playSound(Location loc, Sound sound, float volume, float pitch) {
    if (loc == null || sound == null) return;

    double x = loc.getX();
    double y = loc.getY();
    double z = loc.getZ();

    getHandle().playSoundEffect(x, y, z, CraftSound.getSound(sound), volume, pitch);
}
 
Example 5
public static boolean isSafe(Location loc, Island island) {
    if (loc == null) return false;
    if (loc.getY() < 1) return false;
    if (!island.isInIsland(loc)) return false;
    if (!loc.getBlock().getType().name().endsWith("AIR")) return false;
    if (loc.clone().add(0, -1, 0).getBlock().getType().name().endsWith("AIR"))
        return false;
    return !loc.clone().add(0, -1, 0).getBlock().isLiquid();
}
 
Example 6
Source Project: XSeries   File: XParticle.java    License: MIT License 5 votes vote down vote up
/**
 * Display a rendered image repeatedly.
 *
 * @param render   the rendered image map.
 * @param location the dynamic location to display the image at.
 * @param quality  the quality of the image is exactly the number of particles display for each pixel. Recommended value is 1
 * @param speed    the speed is exactly the same value as the speed of particles. Recommended amount is 0
 * @param size     the size of the particle. Recommended amount is 0.8
 * @since 1.0.0
 */
public static void displayRenderedImage(Map<Location, Color> render, Location location, int quality, int speed, float size) {
    for (Map.Entry<Location, Color> pixel : render.entrySet()) {
        Particle.DustOptions data = new Particle.DustOptions(pixel.getValue(), size);
        Location pixelLoc = pixel.getKey();

        Location loc = new Location(location.getWorld(), location.getX() - pixelLoc.getX(),
                location.getY() - pixelLoc.getY(), location.getZ() - pixelLoc.getZ());
        loc.getWorld().spawnParticle(Particle.REDSTONE, loc, quality, 0, 0, 0, speed, data);
    }
}
 
Example 7
private Location getHologramLocationByLocation(Location holoLocation) {
  for (Location loc : this.hologramLocations) {
    if (loc.getX() == holoLocation.getX() && loc.getY() == holoLocation.getY()
        && loc.getZ() == holoLocation.getZ()) {
      return loc;
    }
  }

  return null;
}
 
Example 8
private Hologram getHologramByLocation(List<Hologram> holograms, Location holoLocation) {
    for (Hologram holo : holograms) {
        if (holo.getLocation().getX() == holoLocation.getX() && holo.getLocation().getY() == holoLocation.getY()
                && holo.getLocation().getZ() == holoLocation.getZ()) {
            return holo;
        }
    }

    return null;
}
 
Example 9
Source Project: WildernessTp   File: ClaimChecks.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
private boolean checkSurroundingFactionsUUID(Location loc) {
    //Board board = co;
    int distance = range / 2;
    Vector top = new Vector(loc.getX() + distance, loc.getY(), loc.getZ() + distance);
    Vector bottom = new Vector(loc.getX() - distance, loc.getY(), loc.getZ() - distance);
    for (int z = bottom.getBlockZ(); z <= top.getBlockZ(); z++) {
        for (int x = bottom.getBlockX(); x <= top.getBlockX(); x++) {
            if (Board.getFactionAt(new FLocation(new Location(loc.getWorld(), loc.getX() + x, loc.getY(), loc.getZ() + z))).isNone())
                return true;
        }
    }
    return false;
}
 
Example 10
Source Project: TAB   File: ArmorStand.java    License: Apache License 2.0 5 votes vote down vote up
public void updateLocation(Location newLocation) {
	double x = newLocation.getX();
	double y = newLocation.getY() + yOffset + 2;
	double z = newLocation.getZ();
	if (player.isSleeping()) {
		y -= 1.76;
	} else {
		if (ProtocolVersion.SERVER_VERSION.getMinorVersion() >= 9) {
			y -= (sneaking ? 0.45 : 0.18);
		} else {
			y -= (sneaking ? 0.30 : 0.18);
		}
	}
	location = new Location(null,x,y,z);
}
 
Example 11
Source Project: TAB   File: MethodAPI_v1_10_R1.java    License: Apache License 2.0 5 votes vote down vote up
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
	EntityLiving entity = (EntityLiving) entityliving;
	entity.locX = loc.getX();
	entity.locY = loc.getY();
	entity.locZ = loc.getZ();
	entity.yaw = loc.getYaw();
	entity.pitch = loc.getPitch();
	return new PacketPlayOutEntityTeleport(entity);
}
 
Example 12
Source Project: TAB   File: MethodAPI_v1_8_R1.java    License: Apache License 2.0 5 votes vote down vote up
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
	EntityLiving entity = (EntityLiving) entityliving;
	entity.locX = loc.getX();
	entity.locY = loc.getY();
	entity.locZ = loc.getZ();
	entity.yaw = loc.getYaw();
	entity.pitch = loc.getPitch();
	return new PacketPlayOutEntityTeleport(entity);
}
 
Example 13
Source Project: WildernessTp   File: ClaimChecks.java    License: MIT License 5 votes vote down vote up
private boolean checkSurroundingKingdoms(Location loc) {
    int distance = range / 2;
    Vector top = new Vector(loc.getX() + distance, loc.getY(), loc.getZ() + distance);
    Vector bottom = new Vector(loc.getX() - distance, loc.getY(), loc.getZ() - distance);
    for (int z = bottom.getBlockZ(); z <= top.getBlockZ(); z++) {
        for (int x = bottom.getBlockX(); x <= top.getBlockX(); x++) {
            if (GameManagement.getLandManager().getOrLoadLand(new SimpleChunkLocation(new Location(loc.getWorld(), loc.getX() + x, loc.getY(), loc.getZ() + z).getChunk())) != null)
                return true;
        }
    }
    return false;

}
 
Example 14
Source Project: TAB   File: MethodAPI_v1_6_R2.java    License: Apache License 2.0 5 votes vote down vote up
public Object newPacketPlayOutEntityTeleport(Object entityliving, Location loc) {
	EntityLiving entity = (EntityLiving) entityliving;
	entity.locX = loc.getX();
	entity.locY = loc.getY();
	entity.locZ = loc.getZ();
	entity.yaw = loc.getYaw();
	entity.pitch = loc.getPitch();
	return new Packet34EntityTeleport(entity);
}
 
Example 15
@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 16
private void handleGrapplingHook(Arrow arrow) {
    if (arrow != null && arrow.isValid() && arrow.getShooter() instanceof Player) {
        Player p = (Player) arrow.getShooter();
        GrapplingHookEntity hook = activeHooks.get(p.getUniqueId());

        if (hook != null) {
            Location target = arrow.getLocation();
            hook.drop(target);

            Vector velocity = new Vector(0.0, 0.2, 0.0);

            if (p.getLocation().distance(target) < 3.0) {
                if (target.getY() <= p.getLocation().getY()) {
                    velocity = target.toVector().subtract(p.getLocation().toVector());
                }
            }
            else {
                Location l = p.getLocation();
                l.setY(l.getY() + 0.5);
                p.teleport(l);

                double g = -0.08;
                double d = target.distance(l);
                double t = d;
                double vX = (1.0 + 0.08 * t) * (target.getX() - l.getX()) / t;
                double vY = (1.0 + 0.04 * t) * (target.getY() - l.getY()) / t - 0.5D * g * t;
                double vZ = (1.0 + 0.08 * t) * (target.getZ() - l.getZ()) / t;

                velocity = p.getVelocity();
                velocity.setX(vX);
                velocity.setY(vY);
                velocity.setZ(vZ);
            }

            p.setVelocity(velocity);

            hook.remove();
            Slimefun.runSync(() -> activeHooks.remove(p.getUniqueId()), 20L);
        }
    }
}
 
Example 17
/**
 * Get the cause of the player's imminent death, or null if they are not about to die NOTE: not
 * idempotent, has the side effect of clearing the recentDamage cache
 */
public @Nullable ImminentDeath getImminentDeath(Player player) {
  // If the player is already dead or in creative mode, we don't care
  if (player.isDead() || player.getGameMode() == GameMode.CREATIVE) return null;

  // If the player was on the ground, or is flying, or is able to fly, they are fine
  if (!(player.isOnGround() || player.isFlying() || player.getAllowFlight())) {
    // If the player is falling, detect an imminent falling death
    double fallDistance = player.getFallDistance();
    Block landingBlock = null;
    int waterDepth = 0;
    Location location = player.getLocation();

    if (location.getY() > 256) {
      // If player is above Y 256, assume they fell at least to there
      fallDistance += location.getY() - 256;
      location.setY(256);
    }

    // Search the blocks directly beneath the player until we find what they would have landed on
    Block block = null;
    for (; location.getY() >= 0; location.add(0, -1, 0)) {
      block = location.getBlock();
      if (block != null) {
        landingBlock = block;

        if (Materials.isWater(landingBlock.getType())) {
          // If the player falls through water, reset fall distance and inc the water depth
          fallDistance = -1;
          waterDepth += 1;

          // Break if they have fallen through enough water to stop falling
          if (waterDepth >= BREAK_FALL_WATER_DEPTH) break;
        } else {
          // If the block is not water, reset the water depth
          waterDepth = 0;

          if (Materials.isSolid(landingBlock.getType())
              || Materials.isLava(landingBlock.getType())) {
            // Break if the player hits a solid block or lava
            break;
          } else if (landingBlock.getType() == Material.WEB) {
            // If they hit web, reset their fall distance, but assume they keep falling
            fallDistance = -1;
          }
        }
      }

      fallDistance += 1;
    }

    double resistanceFactor = getResistanceFactor(player);
    boolean fireResistance = hasFireResistance(player);

    // Now decide if the landing would have killed them
    if (location.getBlockY() < 0) {
      // The player would have fallen into the void
      return new ImminentDeath(EntityDamageEvent.DamageCause.VOID, location, null, false);
    } else if (landingBlock != null) {
      if (Materials.isSolid(landingBlock.getType())
          && player.getHealth() <= resistanceFactor * (fallDistance - SAFE_FALL_DISTANCE)) {
        // The player would have landed on a solid block and taken enough fall damage to kill them
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.FALL,
            landingBlock.getLocation().add(0, 0.5, 0),
            null,
            false);
      } else if (Materials.isLava(landingBlock.getType())
          && resistanceFactor > 0
          && !fireResistance) {
        // The player would have landed in lava, and we give the lava the benefit of the doubt
        return new ImminentDeath(
            EntityDamageEvent.DamageCause.LAVA, landingBlock.getLocation(), landingBlock, false);
      }
    }
  }

  // If we didn't predict a falling death, detect combat log due to recent damage
  Damage damage = this.recentDamage.remove(player);
  if (damage != null && damage.time.plus(RECENT_DAMAGE_THRESHOLD).isAfter(Instant.now())) {
    // Player logged out too soon after taking damage
    return new ImminentDeath(damage.event.getCause(), player.getLocation(), null, true);
  }

  return null;
}
 
Example 18
public SerializableLocation(final Location loc) {
    x = loc.getX();
    y = loc.getY();
    z = loc.getZ();
    world = loc.getWorld().getName();
}
 
Example 19
Source Project: ArmorStandTools   File: Utils.java    License: MIT License 4 votes vote down vote up
static Block findAnAirBlock(Location l) {
    while(l.getY() < 255 && l.getBlock().getType() != Material.AIR) {
        l.add(0, 1, 0);
    }
    return l.getY() < 255 && l.getBlock().getType() == Material.AIR ? l.getBlock() : null;
}
 
Example 20
@Override
public WorldVector getPosition() {
    Location loc = player.getLocation();
    return new WorldVector(BukkitUtil.getLocalWorld(loc.getWorld()),
            loc.getX(), loc.getY(), loc.getZ());
}