Search in sources :

Example 1 with ColonyVisitorViewDataMessage

use of com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage in project minecolonies by Minecolonies.

the class VisitorManager method sendPackets.

@Override
public void sendPackets(@NotNull final Set<ServerPlayerEntity> closeSubscribers, @NotNull final Set<ServerPlayerEntity> newSubscribers) {
    Set<ServerPlayerEntity> players = new HashSet<>(newSubscribers);
    players.addAll(closeSubscribers);
    Set<IVisitorData> toSend = new HashSet<>();
    boolean refresh = !newSubscribers.isEmpty() || this.isDirty;
    if (refresh) {
        toSend = new HashSet<>(visitorMap.values());
        for (final IVisitorData data : visitorMap.values()) {
            data.clearDirty();
        }
        this.clearDirty();
    } else {
        for (final IVisitorData data : visitorMap.values()) {
            if (data.isDirty()) {
                toSend.add(data);
            }
            data.clearDirty();
        }
    }
    if (toSend.isEmpty()) {
        return;
    }
    final ColonyVisitorViewDataMessage message = new ColonyVisitorViewDataMessage(colony, toSend, refresh);
    for (final ServerPlayerEntity player : players) {
        Network.getNetwork().sendToPlayer(message, player);
    }
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyVisitorViewDataMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage)

Example 2 with ColonyVisitorViewDataMessage

use of com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage in project minecolonies by ldtteam.

the class VisitorManager method sendPackets.

@Override
public void sendPackets(@NotNull final Set<ServerPlayerEntity> closeSubscribers, @NotNull final Set<ServerPlayerEntity> newSubscribers) {
    Set<ServerPlayerEntity> players = new HashSet<>(newSubscribers);
    players.addAll(closeSubscribers);
    Set<IVisitorData> toSend = new HashSet<>();
    boolean refresh = !newSubscribers.isEmpty() || this.isDirty;
    if (refresh) {
        toSend = new HashSet<>(visitorMap.values());
        for (final IVisitorData data : visitorMap.values()) {
            data.clearDirty();
        }
        this.clearDirty();
    } else {
        for (final IVisitorData data : visitorMap.values()) {
            if (data.isDirty()) {
                toSend.add(data);
            }
            data.clearDirty();
        }
    }
    if (toSend.isEmpty()) {
        return;
    }
    final ColonyVisitorViewDataMessage message = new ColonyVisitorViewDataMessage(colony, toSend, refresh);
    for (final ServerPlayerEntity player : players) {
        Network.getNetwork().sendToPlayer(message, player);
    }
}
Also used : IVisitorData(com.minecolonies.api.colony.IVisitorData) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ColonyVisitorViewDataMessage(com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage)

Aggregations

IVisitorData (com.minecolonies.api.colony.IVisitorData)2 ColonyVisitorViewDataMessage (com.minecolonies.coremod.network.messages.client.colony.ColonyVisitorViewDataMessage)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2