This commit is contained in:
parent
45d3c8aaa8
commit
2d10ead566
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>cn.lunadeer</groupId>
|
||||
<artifactId>EssentialsD</artifactId>
|
||||
<version>1.18.13</version>
|
||||
<version>1.18.16</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>EssentialsD</name>
|
||||
|
@ -7,7 +7,9 @@ import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
@ -137,10 +139,10 @@ public class TeleportManager {
|
||||
public void rtp(Player player) {
|
||||
int radius = EssentialsD.config.getTpRtpRadius();
|
||||
World world = player.getWorld();
|
||||
int x = (int) (Math.random() * radius * 2) - radius;
|
||||
int z = (int) (Math.random() * radius * 2) - radius;
|
||||
int x = (int) (Math.random() * radius * 2) - radius + (int) player.getLocation().getX();
|
||||
int z = (int) (Math.random() * radius * 2) - radius + (int) player.getLocation().getZ();
|
||||
XLogger.debug("RTP: " + x + " " + z);
|
||||
Location location = new Location(world, x, player.getY(), z);
|
||||
Location location = new Location(world, x + 0.5, player.getY(), z + 0.5);
|
||||
if (EssentialsD.config.getTpDelay() > 0) {
|
||||
Notification.info(player, "将在 " + EssentialsD.config.getTpDelay() + " 秒后传送到随机位置");
|
||||
}
|
||||
@ -159,15 +161,33 @@ public class TeleportManager {
|
||||
public void doTeleportSafely(Player player, Location location) {
|
||||
location.getWorld().getChunkAtAsyncUrgently(location).thenAccept((chunk) -> {
|
||||
updateLastTpLocation(player);
|
||||
for (double y = location.y(); y < 256; y++) {
|
||||
Location up1 = location.getBlock().getRelative(BlockFace.UP).getLocation();
|
||||
Location up2 = up1.getBlock().getRelative(BlockFace.UP).getLocation();
|
||||
if (up1.getBlock().isPassable() && up2.getBlock().isPassable()) {
|
||||
break;
|
||||
} else {
|
||||
location.setY(y + 1);
|
||||
int max_attempts = 512;
|
||||
while (location.getBlock().isPassable()) {
|
||||
location.setY(location.getY() - 1);
|
||||
max_attempts--;
|
||||
if (max_attempts <= 0) {
|
||||
Notification.error(player, "传送目的地不安全,已取消传送");
|
||||
return;
|
||||
}
|
||||
}
|
||||
Block up1 = location.getBlock().getRelative(BlockFace.UP);
|
||||
Block up2 = up1.getRelative(BlockFace.UP);
|
||||
max_attempts = 512;
|
||||
while (!(up1.isPassable() && !up1.isLiquid()) || !(up2.isPassable() && !up2.isLiquid())) {
|
||||
location.setY(location.getY() + 1);
|
||||
up1 = location.getBlock().getRelative(BlockFace.UP);
|
||||
up2 = up1.getRelative(BlockFace.UP);
|
||||
max_attempts--;
|
||||
if (max_attempts <= 0) {
|
||||
Notification.error(player, "传送目的地不安全,已取消传送");
|
||||
return;
|
||||
}
|
||||
}
|
||||
location.setY(location.getY() + 1);
|
||||
if (location.getBlock().getRelative(BlockFace.DOWN).getType() == Material.LAVA) {
|
||||
Notification.error(player, "传送目的地不安全,已取消传送");
|
||||
return;
|
||||
}
|
||||
player.teleportAsync(location, PlayerTeleportEvent.TeleportCause.PLUGIN);
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user