Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

, #15

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

, #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public void onProjectileHit(ProjectileHitEvent event) {
Location location = projectile.getLocation();
// Get the world of the location
World world = location.getWorld();
// Check if the player and the pearl are in the same world
if (!world.equals(player.getWorld())) {
return;
}
// Get disabled worlds
Collection<String> disabledWorlds = generalConfigHolder.getDisabledWorlds();
// Teleport the player to that location if not disabled
Expand All @@ -72,6 +76,8 @@ public void onProjectileHit(ProjectileHitEvent event) {
double damage = generalConfigHolder.getPearlDamageSelf();
if(damage >= 0) {
player.damage(damage, projectile);
// Reset no damage tick due to player invulnerability in the server side.
player.setNoDamageTicks(0);
}
// Spawn endermite if chance is higher
if (endermiteChance > Math.random()) {
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/com/arkflame/flamepearls/utils/LocationUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ public static boolean isSafe(Material type) {
}

String typeName = type.name();
return
return
type == Material.AIR ||
typeName.equals("REDSTONE") ||
typeName.equals("TRIPWIRE_HOOK") ||
typeName.endsWith("PRESSURE_PLATE") ||
typeName.equals("TALL_GRASS") ||
typeName.equals("LONG_GRASS") ||
typeName.endsWith("CARPET");
typeName.equals("REDSTONE") ||
typeName.equals("TRIPWIRE_HOOK") ||
typeName.endsWith("PRESSURE_PLATE") ||
typeName.equals("TALL_GRASS") ||
typeName.equals("LONG_GRASS") ||
typeName.endsWith("CARPET");
}

// A helper method that finds the nearest safest location from a given location,
Expand Down Expand Up @@ -71,9 +71,30 @@ public static Location findSafeLocation(Location location, Location origin, Worl
// Floor the Y value of the best location
bestLocation.setY(Math.floor(bestLocation.getY()));

return bestLocation;
return findNearestSafeY(bestLocation, origin);
}
// If no safe location is found, return the original location
return location;
return findNearestSafeY(location, origin);
}

// Finds the nearest safe location along the Y-axis (height)
public static Location findNearestSafeY(Location location, Location origin) {
World world = location.getWorld();
int startY = location.getBlockY();

// Check if the current block and the block above are safe
Block aboveBlock = world.getBlockAt(location.getBlockX(), startY + 1, location.getBlockZ());

// Check 1 block below to see if it's safe
Block belowBlock = world.getBlockAt(location.getBlockX(), startY - 1, location.getBlockZ());

// If the block below is safe and the block above it is air (to ensure space above)
if (isSafe(belowBlock.getType()) && aboveBlock.getType() == Material.AIR) {
// Only move down by 1 block if it's safe
return new Location(world, location.getX(), startY - 1 + 0.5, location.getZ(), location.getYaw(), location.getPitch());
}

// If no safe location is found, return the original location (origin)
return origin;
}
}