Search in sources :

Example 16 with NetworkPlayerInfo

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));
                    }
                }
            });
        }
    }
}
Also used : NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Text(org.spongepowered.api.text.Text) UUID(java.util.UUID) World(net.minecraft.world.World) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Minecraft(net.minecraft.client.Minecraft)

Example 17 with NetworkPlayerInfo

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));
                        }
                    });
                }
            });
        }
    }
}
Also used : NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Text(org.spongepowered.api.text.Text) UUID(java.util.UUID) World(net.minecraft.world.World) EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) Minecraft(net.minecraft.client.Minecraft)

Example 18 with NetworkPlayerInfo

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);
}
Also used : NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) ArrayList(java.util.ArrayList)

Example 19 with NetworkPlayerInfo

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;
}
Also used : NetworkPlayerInfo(net.minecraft.client.network.NetworkPlayerInfo) NetHandlerPlayClient(net.minecraft.client.network.NetHandlerPlayClient) Collection(java.util.Collection)

Aggregations

NetworkPlayerInfo (net.minecraft.client.network.NetworkPlayerInfo)19 NetHandlerPlayClient (net.minecraft.client.network.NetHandlerPlayClient)5 EntityPlayerSP (net.minecraft.client.entity.EntityPlayerSP)4 EntityPlayer (net.minecraft.entity.player.EntityPlayer)4 ResourceLocation (net.minecraft.util.ResourceLocation)4 UUID (java.util.UUID)3 ArrayList (java.util.ArrayList)2 EntitySpaceshipBase (micdoodle8.mods.galacticraft.api.prefab.entity.EntitySpaceshipBase)2 Minecraft (net.minecraft.client.Minecraft)2 AbstractClientPlayer (net.minecraft.client.entity.AbstractClientPlayer)2 World (net.minecraft.world.World)2 Text (org.spongepowered.api.text.Text)2 GuiBigTextField (betterquesting.api.client.gui.controls.GuiBigTextField)1 GuiButtonThemed (betterquesting.api.client.gui.controls.GuiButtonThemed)1 IMixinAbstractClientPlayer (cc.hyperium.mixins.client.entity.IMixinAbstractClientPlayer)1 IMixinGuiPlayerTabOverlay (cc.hyperium.mixins.client.gui.IMixinGuiPlayerTabOverlay)1 IMixinNetworkPlayerInfo (cc.hyperium.mixins.client.network.IMixinNetworkPlayerInfo)1 LevelheadPurchaseStates (cc.hyperium.mods.levelhead.purchases.LevelheadPurchaseStates)1 StaffUtils (cc.hyperium.utils.StaffUtils)1 GameProfile (com.mojang.authlib.GameProfile)1