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();
}
}
}
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;
}
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);
}
}
}
}
Aggregations