Search in sources :

Example 1 with ClientboundPlayerInfoPacket

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);
        }
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 2 with ClientboundPlayerInfoPacket

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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_18_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 3 with ClientboundPlayerInfoPacket

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;
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) Component(net.minecraft.network.chat.Component) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 4 with ClientboundPlayerInfoPacket

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);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ClientboundRemoveEntitiesPacket(net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) Player(org.bukkit.entity.Player) ServerPlayer(net.minecraft.server.level.ServerPlayer) ServerPlayer(net.minecraft.server.level.ServerPlayer) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) CraftPlayer(org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer) ClientboundAddPlayerPacket(net.minecraft.network.protocol.game.ClientboundAddPlayerPacket) UUID(java.util.UUID) CraftServer(org.bukkit.craftbukkit.v1_17_R1.CraftServer) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Example 5 with ClientboundPlayerInfoPacket

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;
    }
}
Also used : GameProfile(com.mojang.authlib.GameProfile) Component(net.minecraft.network.chat.Component) ClientboundPlayerInfoPacket(net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)

Aggregations

ClientboundPlayerInfoPacket (net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket)6 GameProfile (com.mojang.authlib.GameProfile)4 UUID (java.util.UUID)2 Component (net.minecraft.network.chat.Component)2 ClientboundAddPlayerPacket (net.minecraft.network.protocol.game.ClientboundAddPlayerPacket)2 ClientboundRemoveEntitiesPacket (net.minecraft.network.protocol.game.ClientboundRemoveEntitiesPacket)2 ServerLevel (net.minecraft.server.level.ServerLevel)2 ServerPlayer (net.minecraft.server.level.ServerPlayer)2 Player (org.bukkit.entity.Player)2 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)2 CraftServer (org.bukkit.craftbukkit.v1_17_R1.CraftServer)1 CraftPlayer (org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer)1 CraftServer (org.bukkit.craftbukkit.v1_18_R1.CraftServer)1 CraftPlayer (org.bukkit.craftbukkit.v1_18_R1.entity.CraftPlayer)1