Skip to content

Commit

Permalink
misc: 一些调整
Browse files Browse the repository at this point in the history
  • Loading branch information
MATRIX-feather committed Sep 21, 2024
1 parent ce74026 commit 6ff9dc7
Showing 1 changed file with 6 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import org.bukkit.Bukkit;
import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.entity.CraftPlayer;
import org.jetbrains.annotations.Nullable;
import xiamomc.morph.MorphPlugin;
Expand Down Expand Up @@ -65,13 +66,13 @@ protected Player getNmsPlayerEntityFrom(PacketEvent event, int id)
// 因此我们需要在每个世界都手动查询一遍
for (var world : Bukkit.getWorlds())
{
var worldPlayers = world.getPlayers();
// For performance, we use NMS instead of CraftWorld
var nmsWorld = NmsUtils.getNmsLevel(world);
var worldPlayers = nmsWorld.players();

var match = worldPlayers.stream()
.filter(p -> p.getEntityId() == id)
.map(bukkit -> ((CraftPlayer)bukkit).getHandle())
.map(Optional::ofNullable)
.findFirst().flatMap(Function.identity())
.filter(p -> p.getId() == id)
.findFirst()
.orElse(null);

if (match != null)
Expand Down

0 comments on commit 6ff9dc7

Please sign in to comment.