use of net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method updatePlayerProfiles.
public static void updatePlayerProfiles(ClientboundPlayerInfoPacket packet) {
ClientboundPlayerInfoPacket.Action action = packet.getAction();
if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER) {
return;
}
List<ClientboundPlayerInfoPacket.PlayerUpdate> dataList = packet.getEntries();
if (dataList != null) {
try {
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
GameProfile gameProfile = data.getProfile();
if (fakeProfiles.containsKey(gameProfile.getId())) {
playerInfoData_gameProfile_Setter.invoke(data, getGameProfile(fakeProfiles.get(gameProfile.getId())));
}
}
} catch (Throwable e) {
Debug.echoError(e);
}
}
}
use of net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelperImpl.send(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(player, spawnPacket);
} else {
if (isSkinChanging) {
((CraftServer) Bukkit.getServer()).getHandle().respawn(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method handleAlteredProfiles.
public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet, DenizenNetworkManagerImpl manager) {
if (ProfileEditor.mirrorUUIDs.isEmpty() && !RenameCommand.hasAnyDynamicRenames()) {
return true;
}
ClientboundPlayerInfoPacket.Action action = packet.getAction();
if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER && action != ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) {
return true;
}
List<ClientboundPlayerInfoPacket.PlayerUpdate> dataList = packet.getEntries();
if (dataList == null) {
return true;
}
try {
boolean any = false;
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) || RenameCommand.customNames.containsKey(data.getProfile().getId())) {
any = true;
}
}
if (!any) {
return true;
}
GameProfile ownProfile = manager.player.getGameProfile();
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (!ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) && !RenameCommand.customNames.containsKey(data.getProfile().getId())) {
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
newPacketDataList.add(data);
manager.oldManager.send(newPacket);
} else {
String rename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), false);
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
GameProfile patchedProfile = new GameProfile(data.getProfile().getId(), rename != null ? (rename.length() > 16 ? rename.substring(0, 16) : rename) : data.getProfile().getName());
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId())) {
patchedProfile.getProperties().putAll(ownProfile.getProperties());
} else {
patchedProfile.getProperties().putAll(data.getProfile().getProperties());
}
String listRename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), true);
Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : data.getDisplayName();
ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName);
newPacketDataList.add(newData);
manager.oldManager.send(newPacket);
}
}
return false;
} catch (Exception e) {
Debug.echoError(e);
return true;
}
}
use of net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method updatePlayer.
@Override
protected void updatePlayer(Player player, final boolean isSkinChanging) {
final ServerPlayer entityPlayer = ((CraftPlayer) player).getHandle();
final UUID uuid = player.getUniqueId();
ClientboundRemoveEntitiesPacket destroyPacket = new ClientboundRemoveEntitiesPacket(entityPlayer.getId());
for (Player p : Bukkit.getServer().getOnlinePlayers()) {
if (!p.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(p, destroyPacket);
}
}
new BukkitRunnable() {
@Override
public void run() {
ClientboundPlayerInfoPacket playerInfo = new ClientboundPlayerInfoPacket(ClientboundPlayerInfoPacket.Action.ADD_PLAYER, entityPlayer);
ClientboundAddPlayerPacket spawnPacket = new ClientboundAddPlayerPacket(entityPlayer);
for (Player player : Bukkit.getServer().getOnlinePlayers()) {
PacketHelperImpl.send(player, playerInfo);
if (!player.getUniqueId().equals(uuid)) {
PacketHelperImpl.send(player, spawnPacket);
} else {
if (isSkinChanging) {
((CraftServer) Bukkit.getServer()).getHandle().moveToWorld(entityPlayer, (ServerLevel) entityPlayer.level, true, player.getLocation(), false);
}
player.updateInventory();
}
}
}
}.runTaskLater(NMSHandler.getJavaPlugin(), 5);
}
use of net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket in project Denizen-For-Bukkit by DenizenScript.
the class ProfileEditorImpl method handleAlteredProfiles.
public static boolean handleAlteredProfiles(ClientboundPlayerInfoPacket packet, DenizenNetworkManagerImpl manager) {
if (ProfileEditor.mirrorUUIDs.isEmpty() && !RenameCommand.hasAnyDynamicRenames()) {
return true;
}
ClientboundPlayerInfoPacket.Action action = packet.getAction();
if (action != ClientboundPlayerInfoPacket.Action.ADD_PLAYER && action != ClientboundPlayerInfoPacket.Action.UPDATE_DISPLAY_NAME) {
return true;
}
List<ClientboundPlayerInfoPacket.PlayerUpdate> dataList = packet.getEntries();
if (dataList == null) {
return true;
}
try {
boolean any = false;
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) || RenameCommand.customNames.containsKey(data.getProfile().getId())) {
any = true;
}
}
if (!any) {
return true;
}
GameProfile ownProfile = manager.player.getGameProfile();
for (ClientboundPlayerInfoPacket.PlayerUpdate data : dataList) {
if (!ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId()) && !RenameCommand.customNames.containsKey(data.getProfile().getId())) {
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
newPacketDataList.add(data);
manager.oldManager.send(newPacket);
} else {
String rename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), false);
ClientboundPlayerInfoPacket newPacket = new ClientboundPlayerInfoPacket(action);
List<ClientboundPlayerInfoPacket.PlayerUpdate> newPacketDataList = newPacket.getEntries();
GameProfile patchedProfile = new GameProfile(data.getProfile().getId(), rename != null ? (rename.length() > 16 ? rename.substring(0, 16) : rename) : data.getProfile().getName());
if (ProfileEditor.mirrorUUIDs.contains(data.getProfile().getId())) {
patchedProfile.getProperties().putAll(ownProfile.getProperties());
} else {
patchedProfile.getProperties().putAll(data.getProfile().getProperties());
}
String listRename = RenameCommand.getCustomNameFor(data.getProfile().getId(), manager.player.getBukkitEntity(), true);
Component displayName = listRename != null ? Handler.componentToNMS(FormattedTextHelper.parse(listRename, ChatColor.WHITE)) : data.getDisplayName();
ClientboundPlayerInfoPacket.PlayerUpdate newData = new ClientboundPlayerInfoPacket.PlayerUpdate(patchedProfile, data.getLatency(), data.getGameMode(), displayName);
newPacketDataList.add(newData);
manager.oldManager.send(newPacket);
}
}
return false;
} catch (Exception e) {
Debug.echoError(e);
return true;
}
}
Aggregations