Newer
Older
ultramine_hawkeye / src / main / java / org / ultramine / mods / hawkeye / ContainerAccessManager.java
@zaxar163 zaxar163 on 5 Jul 2018 2 KB Inital.
package org.ultramine.mods.hawkeye;

import gnu.trove.map.TIntObjectMap;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import org.ultramine.mods.hawkeye.database.DataManager;
import org.ultramine.mods.hawkeye.entry.ContainerEntry;
import org.ultramine.mods.hawkeye.util.HawkInventoryUtil;

public class ContainerAccessManager {
   private final Map accessList = new HashMap();

   public void checkInventoryClose(EntityPlayer player) {
      ContainerAccessManager.ContainerAccess access = (ContainerAccessManager.ContainerAccess)this.accessList.remove(player.getGameProfile());
      if (access != null) {
         TIntObjectMap after = HawkInventoryUtil.compressInventory(access.container);
         boolean subdata = HawkEye.instance.config.general.logBlocksSubData;
         NBTTagCompound diff = !subdata ? null : HawkInventoryUtil.createDifferenceNBT(access.beforeInv, after);
         if (diff != null || !subdata) {
            String diffStr = HawkInventoryUtil.createDifferenceString(access.beforeInv, after);
            if (diffStr.length() > 1 || subdata) {
               ContainerEntry ent = new ContainerEntry(player, access.world, access.x, access.y, access.z, diffStr);
               if (subdata) {
                  try {
                     ent.setSubData(CompressedStreamTools.compress(diff));
                  } catch (IOException var9) {
                     ;
                  }
               }

               DataManager.addEntry(ent);
            }
         }

      }
   }

   public void checkInventoryOpen(EntityPlayer player, IInventory container, World world, double x, double y, double z) {
      this.accessList.put(player.getGameProfile(), new ContainerAccessManager.ContainerAccess(container, player, HawkInventoryUtil.compressInventory(container), world, x, y, z));
   }

   public class ContainerAccess {
      public IInventory container;
      public EntityPlayer player;
      public TIntObjectMap beforeInv;
      public World world;
      public double x;
      public double y;
      public double z;

      public ContainerAccess(IInventory container, EntityPlayer player, TIntObjectMap beforeInv, World world, double x, double y, double z) {
         this.container = container;
         this.player = player;
         this.beforeInv = beforeInv;
         this.world = world;
         this.x = x;
         this.y = y;
         this.z = z;
      }
   }
}