From d2e1a754b182033f3b1f99721ae54e9c03c47ae5 Mon Sep 17 00:00:00 2001 From: Peaches_MLG Date: Fri, 23 Feb 2024 20:31:10 +0000 Subject: [PATCH] Fixed Teleports --- .../iridiumfactions/configs/Messages.java | 3 +- .../managers/FactionManager.java | 9 +- .../iridiumfactions/utils/LocationUtils.java | 90 ------------------- 3 files changed, 4 insertions(+), 98 deletions(-) delete mode 100644 src/main/java/com/iridium/iridiumfactions/utils/LocationUtils.java diff --git a/src/main/java/com/iridium/iridiumfactions/configs/Messages.java b/src/main/java/com/iridium/iridiumfactions/configs/Messages.java index 160b5e9..077fbb6 100644 --- a/src/main/java/com/iridium/iridiumfactions/configs/Messages.java +++ b/src/main/java/com/iridium/iridiumfactions/configs/Messages.java @@ -16,8 +16,7 @@ public Messages() { public String factionLandNotClaimed = "%prefix% &7This land has not been claimed."; public String factionUnClaimedLand = "%prefix% &7%player% has un-claimed land at (%x%,%z%)."; public String factionUnClaimedAllLand = "%prefix% &7%player% has un-claimed all land for %faction%."; - public String factionDescriptionChanged = "%prefix% &7%player% has changed your faction description to %description%."; - public String factionNameChanged = "%prefix% &7%player% has changed your faction name to %name%."; public String notEnoughPowerToClaim = "%prefix% &7You do not have enough power to claim this land."; public String cannotClaimLand = "%prefix% &7You cannot claim land in this Faction."; + public String teleportNotInFactionLand = "%prefix% &7That teleport is not in your faction land."; } diff --git a/src/main/java/com/iridium/iridiumfactions/managers/FactionManager.java b/src/main/java/com/iridium/iridiumfactions/managers/FactionManager.java index fc49ef6..9d64fce 100644 --- a/src/main/java/com/iridium/iridiumfactions/managers/FactionManager.java +++ b/src/main/java/com/iridium/iridiumfactions/managers/FactionManager.java @@ -15,7 +15,6 @@ import com.iridium.iridiumfactions.database.Faction; import com.iridium.iridiumfactions.database.FactionClaim; import com.iridium.iridiumfactions.database.User; -import com.iridium.iridiumfactions.utils.LocationUtils; import com.iridium.iridiumteams.PermissionType; import com.iridium.iridiumteams.Rank; import com.iridium.iridiumteams.Setting; @@ -469,15 +468,13 @@ public int getFactionCrystals(ItemStack itemStack) { @Override public boolean teleport(Player player, Location location, Faction team) { - Location safeLocation = LocationUtils.getSafeLocation(location, team); - if (safeLocation == null) { - player.sendMessage(StringUtils.color(IridiumFactions.getInstance().getMessages().noSafeLocation + if(getFactionViaLocation(location).getId() != team.getId()){ + player.sendMessage(StringUtils.color(IridiumFactions.getInstance().getMessages().teleportNotInFactionLand .replace("%prefix%", IridiumFactions.getInstance().getConfiguration().prefix) )); - return false; } player.setFallDistance(0.0F); - PaperLib.teleportAsync(player, safeLocation); + PaperLib.teleportAsync(player, location); return true; } diff --git a/src/main/java/com/iridium/iridiumfactions/utils/LocationUtils.java b/src/main/java/com/iridium/iridiumfactions/utils/LocationUtils.java deleted file mode 100644 index 0c45178..0000000 --- a/src/main/java/com/iridium/iridiumfactions/utils/LocationUtils.java +++ /dev/null @@ -1,90 +0,0 @@ -package com.iridium.iridiumfactions.utils; - -import com.iridium.iridiumcore.dependencies.xseries.XMaterial; -import com.iridium.iridiumcore.multiversion.MultiVersion; -import com.iridium.iridiumfactions.IridiumFactions; -import com.iridium.iridiumfactions.database.Faction; -import org.bukkit.Location; -import org.bukkit.Material; -import org.bukkit.World; -import org.bukkit.block.Block; - -import javax.annotation.Nullable; -import java.util.List; -import java.util.stream.Collectors; -import java.util.stream.Stream; - -public class LocationUtils { - - private static final List unsafeBlocks = Stream.of( - XMaterial.END_PORTAL, - XMaterial.WATER, - XMaterial.LAVA - ).map(XMaterial::parseMaterial).collect(Collectors.toList()); - - public static boolean isSafe(Location location) { - if (IridiumFactions.getInstance().isTesting()) return true; - Block block = location.getBlock(); - Block above = location.clone().add(0, 1, 0).getBlock(); - Block below = location.clone().subtract(0, 1, 0).getBlock(); - MultiVersion multiVersion = IridiumFactions.getInstance().getMultiVersion(); - return multiVersion.isPassable(block) && multiVersion.isPassable(above) && !multiVersion.isPassable(below) && !unsafeBlocks.contains(below.getType()) && !unsafeBlocks.contains(block.getType()) && !unsafeBlocks.contains(above.getType()); - } - - /** - * Gets a safe location on the Faction - * - * @param location The location we want to teleport - * @param faction The faction we are inside - * @return A safe Location, if none found return null - */ - @Nullable - public static Location getSafeLocation(Location location, Faction faction) { - //TODO -// World world = location.getWorld(); -// if (world == null) return location; -// if (faction == null) return location; -// if (isSafe(location)) return location; -// -// Location highest = getHighestLocation(location.getBlockX(), location.getBlockZ(), world); -// if (isSafe(highest)) return highest; -// -// Location pos1 = faction.getPosition1(world); -// Location pos2 = faction.getPosition2(world); -// for (int x = pos1.getBlockX(); x <= pos2.getBlockX(); x++) { -// for (int z = pos1.getBlockZ(); z <= pos2.getBlockZ(); z++) { -// Location newLocation = getHighestLocation(x, z, world); -// if (isSafe(newLocation)) return newLocation; -// } -// } - return null; - } - - /** - * Gets the highest Location in a world - * Mojang was dum and changed how this worked - * - * @param x the x coord - * @param z the z coord - * @param world The world - * @return The highest AIR location - */ - private static Location getHighestLocation(int x, int z, World world) { - Block block = world.getHighestBlockAt(x, z); - while (!IridiumFactions.getInstance().getMultiVersion().isPassable(block)) { - block = block.getLocation().add(0, 1, 0).getBlock(); - } - return block.getLocation().add(0.5, 0, 0.5); - } - - /** - * With the data pack, you can modify the height limits and in the Spigot API. - * It exists since 1.17 on Spigot and 1.16 at PaperMC. - * - * @param world The world - * @return The lowest AIR location. - */ - public static int getMinHeight(World world) { - return XMaterial.getVersion() >= 17 ? world.getMinHeight() : 0; // World#getMinHeight() -> Available only in 1.17 Spigot and 1.16.5 PaperMC - } -}