HyCodeYourTale
classpublicPriority 3

WeatherPacketGenerator

com.hypixel.hytale.server.core.asset.type.weather.WeatherPacketGenerator

extends SimpleAssetPacketGenerator>

3

Methods

3

Public Methods

0

Fields

1

Constructors

Constructors

public
WeatherPacketGenerator()

Methods

Public Methods (3)

public
Packet generateInitPacket(IndexedLookupTableAssetMap<String, Weather> assetMap, Map<String, Weather> assets)
@Nonnull
public
Packet generateRemovePacket(IndexedLookupTableAssetMap<String, Weather> assetMap, Set<String> removed)
@Nonnull
public
Packet generateUpdatePacket(IndexedLookupTableAssetMap<String, Weather> assetMap, Map<String, Weather> loadedAssets)
@Nonnull

Inheritance

Parent
Current
Interface
Child

Use mouse wheel to zoom, drag to pan. Click nodes to navigate.

Related Classes

Source Code

package com.hypixel.hytale.server.core.asset.type.weather;

import com.hypixel.hytale.assetstore.map.IndexedLookupTableAssetMap;
import com.hypixel.hytale.protocol.Packet;
import com.hypixel.hytale.protocol.UpdateType;
import com.hypixel.hytale.protocol.packets.assets.UpdateWeathers;
import com.hypixel.hytale.server.core.asset.packet.SimpleAssetPacketGenerator;
import com.hypixel.hytale.server.core.asset.type.weather.config.Weather;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import javax.annotation.Nonnull;

public class WeatherPacketGenerator extends SimpleAssetPacketGenerator<String, Weather, IndexedLookupTableAssetMap<String, Weather>> {
   public WeatherPacketGenerator() {
   }

   @Nonnull
   public Packet generateInitPacket(@Nonnull IndexedLookupTableAssetMap<String, Weather> assetMap, @Nonnull Map<String, Weather> assets) {
      UpdateWeathers packet = new UpdateWeathers();
      packet.type = UpdateType.Init;
      packet.weathers = new Int2ObjectOpenHashMap();

      for (Entry<String, Weather> entry : assets.entrySet()) {
         String key = entry.getKey();
         int index = assetMap.getIndex(key);
         if (index == -2147483648) {
            throw new IllegalArgumentException("Unknown key! " + key);
         }

         packet.weathers.put(index, entry.getValue().toPacket());
      }

      packet.maxId = assetMap.getNextIndex();
      return packet;
   }

   @Nonnull
   public Packet generateUpdatePacket(@Nonnull IndexedLookupTableAssetMap<String, Weather> assetMap, @Nonnull Map<String, Weather> loadedAssets) {
      UpdateWeathers packet = new UpdateWeathers();
      packet.type = UpdateType.AddOrUpdate;
      packet.weathers = new Int2ObjectOpenHashMap();

      for (Entry<String, Weather> entry : loadedAssets.entrySet()) {
         String key = entry.getKey();
         int index = assetMap.getIndex(key);
         if (index == -2147483648) {
            throw new IllegalArgumentException("Unknown key! " + key);
         }

         packet.weathers.put(index, entry.getValue().toPacket());
      }

      packet.maxId = assetMap.getNextIndex();
      return packet;
   }

   @Nonnull
   public Packet generateRemovePacket(@Nonnull IndexedLookupTableAssetMap<String, Weather> assetMap, @Nonnull Set<String> removed) {
      UpdateWeathers packet = new UpdateWeathers();
      packet.type = UpdateType.Remove;
      packet.weathers = new Int2ObjectOpenHashMap();

      for (String key : removed) {
         int index = assetMap.getIndex(key);
         if (index == -2147483648) {
            throw new IllegalArgumentException("Unknown key! " + key);
         }

         packet.weathers.put(index, null);
      }

      packet.maxId = assetMap.getNextIndex();
      return packet;
   }
}