Started Working on Security Gui. (incomplete)
This commit is contained in:
@@ -6,28 +6,52 @@ import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.features.IPlayerRegistry;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.events.MENetworkSecurityChange;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IStorageMonitorable;
|
||||
import appeng.api.storage.MEMonitorHandler;
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.storage.SecurityInventory;
|
||||
import appeng.tile.events.AETileEventHandler;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileSecurity extends AENetworkTile
|
||||
public class TileSecurity extends AENetworkTile implements IStorageMonitorable
|
||||
{
|
||||
|
||||
private static int diffrence = 0;
|
||||
|
||||
private SecurityInventory inventory = new SecurityInventory( this );
|
||||
private MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<IAEItemStack>( inventory );
|
||||
|
||||
private boolean isActive = false;
|
||||
|
||||
public long securityKey;
|
||||
|
||||
IMEInventoryHandler<IAEItemStack> getSecurityInventory()
|
||||
{
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
@@ -76,17 +100,64 @@ public class TileSecurity extends AENetworkTile
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setLong( "securityKey", securityKey );
|
||||
NBTTagCompound storedItems = new NBTTagCompound();
|
||||
|
||||
int offset = 0;
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
NBTTagCompound it = new NBTTagCompound();
|
||||
ais.getItemStack().writeToNBT( it );
|
||||
storedItems.setCompoundTag( "" + (offset++), it );
|
||||
}
|
||||
|
||||
data.setCompoundTag( "storedItems", storedItems );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
securityKey = data.getLong( "securityKey" );
|
||||
NBTTagCompound storedItems = data.getCompoundTag( "storedItems" );
|
||||
for (Object obj : storedItems.getTags())
|
||||
{
|
||||
if ( obj instanceof NBTTagCompound )
|
||||
{
|
||||
inventory.storedItems.add( AEItemStack.create( ItemStack.loadItemStackFromNBT( (NBTTagCompound) obj ) ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public void inventoryChanged()
|
||||
{
|
||||
try
|
||||
{
|
||||
saveChanges();
|
||||
gridProxy.getGrid().postEvent( new MENetworkSecurityChange() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
public void readPermissions(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms)
|
||||
{
|
||||
IPlayerRegistry pr = AEApi.instance().registries().players();
|
||||
|
||||
// read permissions
|
||||
for (IAEItemStack ais : inventory.storedItems)
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
Item i = is.getItem();
|
||||
if ( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
playerPerms.put( pr.getID( bc.getUserName( is ) ), bc.getPermissions( is ) );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure thea admin is Boss.
|
||||
playerPerms.put( gridProxy.getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
|
||||
}
|
||||
|
||||
@@ -144,4 +215,16 @@ public class TileSecurity extends AENetworkTile
|
||||
return isActive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEItemStack> getItemInventory()
|
||||
{
|
||||
return securityMonitor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user