use of net.minecraft.client.network.NetworkPlayerInfo in project Almura by AlmuraDev.
the class ClientboundNucleusNameChangeMappingPacketHandler method handleMessage.
@Override
public void handleMessage(final ClientboundNucleusNameChangeMappingPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isClient()) {
final Minecraft client = Minecraft.getMinecraft();
if (PacketUtil.checkThreadAndEnqueue(client, message, this, connection, side)) {
client.addScheduledTask(() -> {
final UUID entityUniqueId = message.uuid;
final Text nickname = message.text;
this.nickManager.put(entityUniqueId, nickname);
final World world = client.world;
if (world != null) {
final EntityPlayer player = world.getPlayerEntityByUUID(entityUniqueId);
if (player != null) {
final String newNick = ForgeEventFactory.getPlayerDisplayName(player, TextSerializers.LEGACY_FORMATTING_CODE.serialize(nickname));
this.nickManager.put(entityUniqueId, TextSerializers.LEGACY_FORMATTING_CODE.deserialize(newNick));
this.nickManager.setForgeNickname(player, newNick);
}
}
final EntityPlayerSP player = client.player;
if (player != null && player.connection != null) {
final NetworkPlayerInfo info = player.connection.getPlayerInfo(entityUniqueId);
if (info != null) {
info.setDisplayName(SpongeTexts.toComponent(nickname));
}
}
});
}
}
}
use of net.minecraft.client.network.NetworkPlayerInfo in project Almura by AlmuraDev.
the class ClientboundNucleusNameMappingsPacketHandler method handleMessage.
@Override
public void handleMessage(final ClientboundNucleusNameMappingsPacket message, final RemoteConnection connection, final Platform.Type side) {
if (side.isClient()) {
final Minecraft client = Minecraft.getMinecraft();
if (PacketUtil.checkThreadAndEnqueue(client, message, this, connection, side)) {
client.addScheduledTask(() -> {
final Map<UUID, Text> nicknames = message.nicknames;
this.nickManager.putAll(nicknames);
final World world = client.world;
if (world != null) {
message.nicknames.forEach((uniqueId, nickname) -> {
final EntityPlayer player = world.getPlayerEntityByUUID(uniqueId);
if (player != null) {
final String newNick = ForgeEventFactory.getPlayerDisplayName(player, TextSerializers.LEGACY_FORMATTING_CODE.serialize(nickname));
this.nickManager.put(player.getUniqueID(), TextSerializers.LEGACY_FORMATTING_CODE.deserialize(newNick));
this.nickManager.setForgeNickname(player, newNick);
}
});
}
final EntityPlayerSP player = client.player;
if (player != null && player.connection != null) {
message.nicknames.forEach((uniqueId, nickname) -> {
final NetworkPlayerInfo info = player.connection.getPlayerInfo(uniqueId);
if (info != null) {
info.setDisplayName(SpongeTexts.toComponent(nickname));
}
});
}
});
}
}
}
use of net.minecraft.client.network.NetworkPlayerInfo in project Almura by AlmuraDev.
the class UIPlayerListPanel method drawBackground.
@SuppressWarnings("unchecked")
@Override
public void drawBackground(final GuiRenderer renderer, final int mouseX, final int mouseY, final float partialTick) {
super.drawBackground(renderer, mouseX, mouseY, partialTick);
final List<NetworkPlayerInfo> entries = ORDERING.sortedCopy(this.client.player.connection.getPlayerInfoMap());
// Get maximum column width
final int maxColumnWidth = this.getMaxColumnWidth(entries);
final List<PlayerListElementData> elementList = new ArrayList<>();
for (int i = 0; i < entries.size(); i += 2) {
final NetworkPlayerInfo player1 = entries.get(i);
final NetworkPlayerInfo player2 = i + 1 < entries.size() ? entries.get(i + 1) : null;
// Add a new element to the list
elementList.add(new PlayerListElementData(this.getGui(), this.playerList, player1, player2, maxColumnWidth));
}
// Set elements
this.playerList.setItems(elementList);
// Auto size our height
this.height = Math.min(this.playerList.getContentHeight() + 5, MAX_HEIGHT);
this.playerList.getScrollBar().setVisible(this.height >= MAX_HEIGHT);
// Auto size our width
this.width = entries.size() == 1 ? maxColumnWidth + 12 : (maxColumnWidth + (!this.playerList.getScrollBar().isVisible() ? 9 : 11)) * 2 + 1;
// Resize list
this.playerList.setSize(this.width - (this.playerList.getScrollBar().isVisible() ? 7 : 5), this.height - 6);
}
use of net.minecraft.client.network.NetworkPlayerInfo in project Random-Things by lumien231.
the class ClientProxy method isPlayerOnline.
@Override
public boolean isPlayerOnline(String username) {
NetHandlerPlayClient netclienthandler = Minecraft.getMinecraft().player.connection;
Collection collection = netclienthandler.getPlayerInfoMap();
Iterator<NetworkPlayerInfo> iterator = collection.iterator();
while (iterator.hasNext()) {
NetworkPlayerInfo info = iterator.next();
if (info.getGameProfile().getName().toLowerCase().equals(username.toLowerCase())) {
return true;
}
}
return false;
}
Aggregations