我正在尝试更改服务器上玩家的皮肤。我查了一下,发现您需要发送正确的数据包,其中一个是删除,另一个是添加播放器,但在我的版本(使用 Spigot buildtools 安装的 1.21.1 nms --> 使用 Mojang 映射).
我尝试使用其他数据包(例如 ClientboundRespawnPacket),但这也不起作用。这是我当前的代码:
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
String PlayerName = sender.getName();
if (!(sender.hasPermission("northmclobbyutils.duckify")) && sender instanceof Player) {
sender.sendMessage("§cYou do not have permission to use this command!");
return true;
}
if (!(sender instanceof Player)) {
PlayerName = "Console";
}
for (Player p : sender.getServer().getOnlinePlayers()) {
System.out.println(p.getName());
CraftPlayer cp = (CraftPlayer) p;
ServerPlayer sp = cp.getHandle();
sp.setCustomName(Component.literal("§6Duck"));
PropertyMap pm = sp.getGameProfile().getProperties();
pm.removeAll("textures");
System.out.println("Duckifying " + p.getName());
pm.put("textures", new Property("textures", "ewogICJ0aW1lc3RhbXAiIDogMTczMTIxMzc0NTk1NywKICAicHJvZmlsZUlkIiA6ICI1OWJlOTUyY2EyNjc0OWE4OTM1YmQ5MGQxNmMyN2M4OCIsCiAgInByb2ZpbGVOYW1lIiA6ICJUaGVQZW5zcGlubmV1ciIsCiAgInNpZ25hdHVyZVJlcXVpcmVkIiA6IHRydWUsCiAgInRleHR1cmVzIiA6IHsKICAgICJTS0lOIiA6IHsKICAgICAgInVybCIgOiAiaHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS80MTlkNTQ3NTk3YTQ2NmM0MWY1YmI3YjE0Y2MyMTZmMTk2ZDNhZjI0YjJhYWQ3MWZjMjlkNWE4ZTlkY2RiZmY5IgogICAgfQogIH0KfQ==", "D8GnL/k1kpQCuals0OqfQSGIqdUZA3akLfSH2UZpwIDfXGn6A3BQmMzpaMw63JxITiZOWruMkzbUtbLreP421kzvNKikkgmXVDIOpyLLc+WYfT+O2eZLAMKnf4/f/cWlnl05FDXeJqIpRyx9b463Uh9xam2zuqr5rHq9t0+/1DOnfew/sDEkJWjNUkUooaJBV+raAHTYmnWlEXCItmfkNJtfBVYN+OVE9w7aSJpC8rkC3bAtkdKFxMmzTuN93pIZBqUzVMwf68e7jAdGMaWiDKl6wptDm304dl2iwuDJeYWDdmKD01KdHZIva1HI/DiPEUTSoPaR7GF055mOp14/08kAkHJA63hQyH/6RE9J1YOolMjho9qlznZbSmjU1yIM7X8vPNuLDcCh0S1OjbraNFrtruzi1vY8nxViPMRVuulUWDtFftF3esQ52M4CsGmeZ8VP786zFc88c+SrezzALgI9TrFklQKl/oZZud8WfjCUnFal2MYdZSqXaMWoYw9QBss1AJABqaLFglVwRckcRVna48J35uFm9kI4aWZVx6WYOKgxqlSKQ1EbKnvVSSfxbZZeHS3u9+2jsIBFpishaFpOtdOKuGM0X6Dx8e+Q4ur4cmT5UV5Q1rLFJhEzxC+Turo2luu3xc63vGn9hUYjj2pCn5DM9vwHKnz6Ef49o1Q="));
updatePlayerSkin(p);
sp.connection.send(new ClientboundPlayerInfoRemovePacket(new ArrayList<>(List.of(sp.getUUID()))));
sp.connection.send(new ClientboundPlayerInfoUpdatePacket(Action.ADD_PLAYER, sp));
}
sender.sendMessage("§aAll players have been duckified!");
return true;
}
现在发生的情况是,玩家从列表中消失,但他们的皮肤保持不变。
您可以隐藏并再次显示播放器。为此,您需要像这样使用 Player#showPlayer 和 Player#hidePlayer:
for (Player p : Bukkit.getOnlinePlayers()) {
setDuckPlayerSkin(p);
for (Player all : Bukkit.getOnlinePlayers()) {
all.hidePlayer(plugin, p); // hide player
all.showPlayer(plugin, p); // show it again
}
}
这将以更安全的方式完成发送数据包的最后 2 行。