Skip to content

Commit

Permalink
misc: 重新在每个世界中寻找玩家
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Oct 24, 2024
1 parent 9f9c3d2 commit d20e3d6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
import xyz.nifeather.morph.backends.server.renderer.network.PacketFactory;
import xyz.nifeather.morph.config.ConfigOption;
import xyz.nifeather.morph.config.MorphConfigManager;
import xyz.nifeather.morph.misc.NmsRecord;
import xyz.nifeather.morph.misc.PlayerTracker;
import xyz.nifeather.morph.utilities.NmsUtils;
import xyz.nifeather.morph.utilities.ReflectionUtils;

Expand Down Expand Up @@ -90,15 +88,24 @@ protected Player getNmsPlayerFrom(int id)
//if (!TickThread.isTickThread())
// logger.warn("Not on a tick thread! Caution for exceptions!");

var bukkitPlayer = PlayerTracker.instance().getPlayers()
.stream()
.filter(p -> p.getEntityId() == id)
.findFirst()
.orElse(null);
// Bukkit.getOnlinePlayers() 会将正前往不同维度的玩家从列表里移除
// 因此我们需要在每个世界都手动查询一遍
for (var world : Bukkit.getWorlds())
{
// For performance, we use NMS instead of CraftWorld
var nmsWorld = NmsUtils.getNmsLevel(world);
var worldPlayers = nmsWorld.players();

var match = worldPlayers.stream()
.filter(p -> p.getId() == id)
.findFirst()
.orElse(null);

if (bukkitPlayer == null) return null;
if (match != null)
return match;
}

return NmsRecord.ofPlayer(bukkitPlayer);
return null;
}

@Nullable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import xyz.nifeather.morph.messages.vanilla.VanillaMessageStore;
import xyz.nifeather.morph.misc.DisguiseTypes;
import xyz.nifeather.morph.misc.OfflineDisguiseResult;
import xyz.nifeather.morph.misc.PlayerTracker;
import xyz.nifeather.morph.misc.gui.AnimSelectScreenWrapper;
import xyz.nifeather.morph.misc.gui.DisguiseSelectScreenWrapper;
import xyz.nifeather.morph.misc.permissions.CommonPermissions;
Expand Down Expand Up @@ -362,8 +361,6 @@ public void onPlayerJoin(PlayerJoinEvent e)
var player = e.getPlayer();
var state = morphs.getDisguiseStateFor(player);

PlayerTracker.instance().addPlayer(player);

clientHandler.markPlayerReady(player);

//如果玩家是第一次用客户端连接,那么等待3秒向其发送提示
Expand Down Expand Up @@ -432,8 +429,6 @@ else if (result == OfflineDisguiseResult.LIMITED)
@EventHandler
public void onPlayerExit(PlayerQuitEvent e)
{
PlayerTracker.instance().removePlayer(e.getPlayer());

clientHandler.unInitializePlayer(e.getPlayer());
skillHandler.removeUnusedList(e.getPlayer());

Expand Down
43 changes: 0 additions & 43 deletions src/main/java/xyz/nifeather/morph/misc/PlayerTracker.java

This file was deleted.

0 comments on commit d20e3d6

Please sign in to comment.