Skip to content

Commit

Permalink
fix: bruh * 2
Browse files Browse the repository at this point in the history
misc: 对玩家伪装使用随机UUID
  • Loading branch information
MATRIX-feather committed Dec 11, 2023
1 parent 460faa3 commit 49653d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import xiamomc.morph.MorphPlugin;
import xiamomc.morph.MorphPluginObject;
import xiamomc.morph.backends.server.renderer.PlayerSkinProvider;
import xiamomc.morph.misc.MorphGameProfile;
import xiamomc.morph.misc.NmsRecord;
import xiamomc.morph.utilities.EntityTypeUtils;
import xiamomc.pluginbase.Annotations.Resolved;
Expand Down Expand Up @@ -186,8 +187,10 @@ private List<PacketContainer> buildSpawnPackets(Player player, DisplayParameters
{
logger.info("Building player info packet!");

var gameProfile = parameters.gameProfile();
Objects.requireNonNull(gameProfile, "Null game profile!");
//todo: Get random UUID from world, not player
Objects.requireNonNull(parameters.gameProfile(), "Null game profile!");
var gameProfile = new MorphGameProfile(parameters.gameProfile());
gameProfile.setUUID(UUID.randomUUID());

//Minecraft需要在生成玩家实体前先发送PlayerInfoUpdate消息
var uuid = gameProfile.getId();
Expand Down Expand Up @@ -294,13 +297,8 @@ private void onEntityAddPacket(ClientboundAddEntityPacket packet, PacketEvent pa
modifier.write(2, entityType);

var meta = packetContainer.getMeta("fm");
if (meta.isEmpty())
{
packetEvent.setCancelled(true);
packetContainer.removeMeta("fm");
}

refreshStateForPlayer(Bukkit.getPlayer(packet.getUUID()));
if (meta.isPresent()) packetContainer.removeMeta("fm");
else refreshStateForPlayer(Bukkit.getPlayer(packet.getUUID()));
}

@Override
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/xiamomc/morph/misc/MorphGameProfile.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import com.mojang.authlib.properties.Property;
import com.mojang.authlib.properties.PropertyMap;

import java.util.Objects;
import java.util.UUID;

public class MorphGameProfile extends GameProfile
{
/**
Expand All @@ -28,11 +31,13 @@ public MorphGameProfile(PlayerProfile profile)
}

private String name;
private UUID uuid;

public MorphGameProfile(GameProfile profile)
{
super(profile.getId(), profile.getName());

this.uuid = profile.getId();
this.name = profile.getName();

profile.getProperties().forEach((s, p) ->
Expand All @@ -54,6 +59,17 @@ public void setName(String str)
this.name = str;
}

public void setUUID(UUID newuuid)
{
this.uuid = newuuid;
}

@Override
public UUID getId()
{
return uuid;
}

private final PropertyMap map = new PropertyMap();

/**
Expand Down

0 comments on commit 49653d4

Please sign in to comment.