Skip to content

Commit fb1a9ef

Browse files
优化传送检测
删除不必要的清理
1 parent d854659 commit fb1a9ef

2 files changed

Lines changed: 10 additions & 25 deletions

File tree

src/main/java/ict/minesunshineone/landmark/LandmarkPlugin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ public void onEnable() {
3939

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

src/main/java/ict/minesunshineone/landmark/manager/LandmarkManager.java

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import java.util.ArrayList;
66
import java.util.HashMap;
77
import java.util.HashSet;
8-
import java.util.Iterator;
98
import java.util.List;
109
import java.util.Map;
1110
import java.util.Set;
@@ -211,8 +210,16 @@ public void teleport(Player player, String landmarkName) {
211210
}
212211

213212
// 执行传送
214-
plugin.getServer().getGlobalRegionScheduler().execute(plugin, () -> {
215-
player.teleportAsync(targetLandmark.getLocation()).thenAccept(result -> {
213+
Location targetLocation = targetLandmark.getLocation();
214+
plugin.getServer().getRegionScheduler().execute(plugin, targetLocation, () -> {
215+
// 移除所有乘客
216+
if (!player.getPassengers().isEmpty()) {
217+
for (Entity passenger : player.getPassengers()) {
218+
player.removePassenger(passenger);
219+
}
220+
}
221+
222+
player.teleportAsync(targetLocation).thenAccept(result -> {
216223
if (result) {
217224
plugin.getConfigManager().sendMessage(player, "teleport-success", "",
218225
"<landmark>", targetLandmark.getName());
@@ -409,27 +416,6 @@ public void cleanupPlayerData(UUID playerId) {
409416
}
410417
}
411418

412-
public void cleanupInactivePlayers(long inactiveTime) {
413-
long currentTime = System.currentTimeMillis();
414-
int cleanedCount = 0;
415-
416-
for (Iterator<Map.Entry<UUID, Set<String>>> it = unlockedLandmarks.entrySet().iterator(); it.hasNext();) {
417-
Map.Entry<UUID, Set<String>> entry = it.next();
418-
UUID playerId = entry.getKey();
419-
420-
if (Bukkit.getPlayer(playerId) == null
421-
&& currentTime - cooldowns.getOrDefault(playerId, currentTime) > inactiveTime) {
422-
cleanupPlayerData(playerId);
423-
it.remove();
424-
cleanedCount++;
425-
}
426-
}
427-
428-
if (cleanedCount > 0) {
429-
plugin.getSLF4JLogger().info("已清理 {} 个不活跃玩家的数", cleanedCount);
430-
}
431-
}
432-
433419
public boolean isPlayerNearLandmark(Player player, Location landmarkLoc) {
434420
Location playerLoc = player.getLocation();
435421
return playerLoc.getWorld() != null

0 commit comments

Comments
 (0)