Search in sources :

Example 1 with PayloadBuilder

use of com.irtimaled.bbor.common.messages.PayloadBuilder in project BoundingBoxOutlineReloaded by irtimaled.

the class CommonProxy method sendToPlayer.

private void sendToPlayer(int playerId, ServerPlayer player) {
    for (Map.Entry<DimensionId, BoundingBoxCache> entry : dimensionCache.entrySet()) {
        DimensionId dimensionId = entry.getKey();
        BoundingBoxCache boundingBoxCache = entry.getValue();
        if (boundingBoxCache == null)
            return;
        Set<AbstractBoundingBox> playerBoundingBoxes = playerBoundingBoxesCache.computeIfAbsent(playerId, k -> new HashSet<>());
        Map<AbstractBoundingBox, Set<AbstractBoundingBox>> boundingBoxMap = boundingBoxCache.getBoundingBoxes();
        for (AbstractBoundingBox key : boundingBoxMap.keySet()) {
            if (playerBoundingBoxes.contains(key)) {
                continue;
            }
            Set<AbstractBoundingBox> boundingBoxes = boundingBoxMap.get(key);
            PayloadBuilder payload = AddBoundingBox.getPayload(dimensionId, key, boundingBoxes);
            if (payload != null)
                player.sendPacket(payload);
            playerBoundingBoxes.add(key);
        }
    }
}
Also used : PayloadBuilder(com.irtimaled.bbor.common.messages.PayloadBuilder) Set(java.util.Set) HashSet(java.util.HashSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) Map(java.util.Map) DimensionId(com.irtimaled.bbor.common.models.DimensionId) AbstractBoundingBox(com.irtimaled.bbor.common.models.AbstractBoundingBox)

Aggregations

PayloadBuilder (com.irtimaled.bbor.common.messages.PayloadBuilder)1 AbstractBoundingBox (com.irtimaled.bbor.common.models.AbstractBoundingBox)1 DimensionId (com.irtimaled.bbor.common.models.DimensionId)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1