Skip to content

Commit

Permalink
修复传送死循环问题
Browse files Browse the repository at this point in the history
  • Loading branch information
windy664 authored Aug 9, 2024
1 parent af8dd38 commit f14c613
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main/java/org/windy/teleportoffset/TeleportOffset.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerMoveEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.plugin.java.JavaPlugin;
Expand All @@ -31,6 +32,7 @@ public class TeleportOffset extends JavaPlugin implements Listener {
double offsetZ;
List<String> disabledWorlds;
int times;
boolean isTeleporting = false;
@Override
public void onEnable() {
this.saveDefaultConfig();
Expand Down Expand Up @@ -98,6 +100,10 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
@EventHandler
public void onPlayerTeleport(PlayerTeleportEvent event) {

if (isTeleporting) {
return; // 如果当前正在传送,则跳过事件处理
}
isTeleporting = true;
// 通过 event.getFrom() 获取玩家传送前的位置,并通过 clone() 方法创建一个副本,确保不会对原位置对象进行修改
Location oldLocation = Objects.requireNonNull(event.getFrom()).clone();
// 通过 event.getTo() 获取玩家传送后的位置,并通过 clone() 方法创建一个副本,确保不会对原位置对象进行修改
Expand All @@ -109,7 +115,6 @@ public void onPlayerTeleport(PlayerTeleportEvent event) {
String worldName = Objects.requireNonNull(location.getWorld()).getName();
// 获取玩家的名称
String playerName = player.getName();

// 根据配置判断是否要对玩家的传送目标位置进行偏移
if (disabledWorlds.contains(worldName)) {
// 如果目标世界在配置的列表中,将按照配置中的偏移量对目标位置进行修改
Expand Down Expand Up @@ -204,6 +209,7 @@ public void run() {
}
}
}.runTaskLater(this, 80L);
isTeleporting = false;
}

private Location findHighestNonAirBlockLocation(Location location) {
Expand Down Expand Up @@ -251,6 +257,5 @@ public void onDisable() {
this.getServer().getConsoleSender().sendMessage("已卸载!\n");
this.getServer().getConsoleSender().sendMessage("§6+--------------------------------------+");
}



}

0 comments on commit f14c613

Please sign in to comment.