Search in sources :

Example 1 with PlayerListS2CPacket

use of net.minecraft.network.packet.s2c.play.PlayerListS2CPacket in project Essential-Commands by John-Paul-R.

the class PlayerDataManager method tick.

public void tick(MinecraftServer server) {
    if (CONFIG.NICKNAMES_IN_PLAYER_LIST.getValue() && server.getTicks() % (20 * 5) == 0) {
        if (this.changedNicknames.size() + this.changedTeams.size() > 0) {
            PlayerManager serverPlayerManager = server.getPlayerManager();
            Set<ServerPlayerEntity> allChangedNicknamePlayers = Stream.concat(changedNicknames.stream().map(PlayerData::getPlayer), changedTeams.stream().map(serverPlayerManager::getPlayer)).filter(Objects::nonNull).collect(Collectors.toSet());
            server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.UPDATE_DISPLAY_NAME, allChangedNicknamePlayers));
            changedNicknames.forEach(PlayerData::save);
            this.changedNicknames.clear();
            this.changedTeams.clear();
        }
    }
    if (!nextTickTasks.isEmpty()) {
        Iterator<Runnable> tasks = nextTickTasks.listIterator();
        while (tasks.hasNext()) {
            tasks.next().run();
            tasks.remove();
        }
    }
}
Also used : PlayerListS2CPacket(net.minecraft.network.packet.s2c.play.PlayerListS2CPacket) PlayerManager(net.minecraft.server.PlayerManager) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 2 with PlayerListS2CPacket

use of net.minecraft.network.packet.s2c.play.PlayerListS2CPacket in project KahzerxMod by otakucraft.

the class KlonePlayerEntity method createKlone.

public static void createKlone(MinecraftServer server, ServerPlayerEntity player) {
    ServerWorld world = player.getWorld();
    GameProfile profile = player.getGameProfile();
    server.getPlayerManager().remove(player);
    player.networkHandler.disconnect(new LiteralText("A clone has been created.\nThe clone will leave once you rejoin.\nHappy AFK!"));
    KlonePlayerEntity klonedPlayer = new KlonePlayerEntity(server, world, profile);
    klonedPlayer.refreshPositionAndAngles(player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
    server.getPlayerManager().onPlayerConnect(new KloneNetworkManager(NetworkSide.SERVERBOUND), klonedPlayer);
    klonedPlayer.teleport(world, player.getX(), player.getY(), player.getZ(), player.getYaw(), player.getPitch());
    klonedPlayer.setHealth(player.getHealth());
    klonedPlayer.unsetRemoved();
    klonedPlayer.stepHeight = 0.6F;
    klonedPlayer.interactionManager.changeGameMode(player.interactionManager.getGameMode());
    server.getPlayerManager().sendToDimension(new EntitySetHeadYawS2CPacket(klonedPlayer, (byte) (player.headYaw * 256 / 360)), klonedPlayer.world.getRegistryKey());
    server.getPlayerManager().sendToDimension(new EntityPositionS2CPacket(klonedPlayer), klonedPlayer.world.getRegistryKey());
    server.getPlayerManager().sendToAll(new PlayerListS2CPacket(PlayerListS2CPacket.Action.ADD_PLAYER, klonedPlayer));
    player.getWorld().getChunkManager().updatePosition(klonedPlayer);
    klonedPlayer.dataTracker.set(PLAYER_MODEL_PARTS, (byte) 0x7f);
    klonedPlayer.getAbilities().flying = player.getAbilities().flying;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) EntityPositionS2CPacket(net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket) PlayerListS2CPacket(net.minecraft.network.packet.s2c.play.PlayerListS2CPacket) GameProfile(com.mojang.authlib.GameProfile) EntitySetHeadYawS2CPacket(net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket) LiteralText(net.minecraft.text.LiteralText)

Example 3 with PlayerListS2CPacket

use of net.minecraft.network.packet.s2c.play.PlayerListS2CPacket in project BleachHack by BleachDrinker420.

the class LogoutSpot method onReadPacket.

@BleachSubscribe
public void onReadPacket(EventPacket.Read event) {
    if (!(event.getPacket() instanceof PlayerListS2CPacket) || mc.world == null) {
        return;
    }
    PlayerListS2CPacket list = (PlayerListS2CPacket) event.getPacket();
    // Spawns fake player when player leaves
    if (list.getAction() == PlayerListS2CPacket.Action.REMOVE_PLAYER) {
        for (PlayerListS2CPacket.Entry entry : list.getEntries()) {
            PlayerEntity player = mc.world.getPlayerByUuid(entry.getProfile().getId());
            if (player != null && !mc.player.equals(player) && !players.containsKey(player.getUuid())) {
                PlayerCopyEntity copy = new PlayerCopyEntity(player);
                players.put(player.getUuid(), Pair.of(copy, System.currentTimeMillis()));
                BleachQueue.add("logoutspot", copy::spawn);
            }
        }
    }
    // Removes fake player when player joins
    if (list.getAction().equals(PlayerListS2CPacket.Action.ADD_PLAYER)) {
        for (PlayerListS2CPacket.Entry entry : list.getEntries()) {
            Pair<PlayerCopyEntity, Long> fakePlayer = players.remove(entry.getProfile().getId());
            if (fakePlayer != null && mc.world != null) {
                BleachQueue.add("logoutspot", fakePlayer.getLeft()::despawn);
            }
        }
    }
}
Also used : PlayerCopyEntity(org.bleachhack.util.world.PlayerCopyEntity) PlayerListS2CPacket(net.minecraft.network.packet.s2c.play.PlayerListS2CPacket) PlayerEntity(net.minecraft.entity.player.PlayerEntity) BleachSubscribe(org.bleachhack.eventbus.BleachSubscribe)

Aggregations

PlayerListS2CPacket (net.minecraft.network.packet.s2c.play.PlayerListS2CPacket)3 GameProfile (com.mojang.authlib.GameProfile)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 EntityPositionS2CPacket (net.minecraft.network.packet.s2c.play.EntityPositionS2CPacket)1 EntitySetHeadYawS2CPacket (net.minecraft.network.packet.s2c.play.EntitySetHeadYawS2CPacket)1 PlayerManager (net.minecraft.server.PlayerManager)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 LiteralText (net.minecraft.text.LiteralText)1 BleachSubscribe (org.bleachhack.eventbus.BleachSubscribe)1 PlayerCopyEntity (org.bleachhack.util.world.PlayerCopyEntity)1