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