Skip to content

Commit

Permalink
优化传送检测
Browse files Browse the repository at this point in the history
删除不必要的清理
  • Loading branch information
MineSunshineone committed Jan 15, 2025
1 parent d854659 commit fb1a9ef
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public void onEnable() {

// 添加定期清理任务
getServer().getGlobalRegionScheduler().runAtFixedRate(this, task -> {
landmarkManager.cleanupInactivePlayers(24 * 60 * 60 * 1000); // 24小时
landmarkManager.cleanupCooldowns();
}, 20 * 60 * 60, 20 * 60 * 60); // 每小时执行一次

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -211,8 +210,16 @@ public void teleport(Player player, String landmarkName) {
}

// 执行传送
plugin.getServer().getGlobalRegionScheduler().execute(plugin, () -> {
player.teleportAsync(targetLandmark.getLocation()).thenAccept(result -> {
Location targetLocation = targetLandmark.getLocation();
plugin.getServer().getRegionScheduler().execute(plugin, targetLocation, () -> {
// 移除所有乘客
if (!player.getPassengers().isEmpty()) {
for (Entity passenger : player.getPassengers()) {
player.removePassenger(passenger);
}
}

player.teleportAsync(targetLocation).thenAccept(result -> {
if (result) {
plugin.getConfigManager().sendMessage(player, "teleport-success", "",
"<landmark>", targetLandmark.getName());
Expand Down Expand Up @@ -409,27 +416,6 @@ public void cleanupPlayerData(UUID playerId) {
}
}

public void cleanupInactivePlayers(long inactiveTime) {
long currentTime = System.currentTimeMillis();
int cleanedCount = 0;

for (Iterator<Map.Entry<UUID, Set<String>>> it = unlockedLandmarks.entrySet().iterator(); it.hasNext();) {
Map.Entry<UUID, Set<String>> entry = it.next();
UUID playerId = entry.getKey();

if (Bukkit.getPlayer(playerId) == null
&& currentTime - cooldowns.getOrDefault(playerId, currentTime) > inactiveTime) {
cleanupPlayerData(playerId);
it.remove();
cleanedCount++;
}
}

if (cleanedCount > 0) {
plugin.getSLF4JLogger().info("已清理 {} 个不活跃玩家的数", cleanedCount);
}
}

public boolean isPlayerNearLandmark(Player player, Location landmarkLoc) {
Location playerLoc = player.getLocation();
return playerLoc.getWorld() != null
Expand Down

0 comments on commit fb1a9ef

Please sign in to comment.