Basic reformat, hit once, hope never again
This commit is contained in:
@@ -77,35 +77,47 @@ import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEAppEngInventory, ILocatable, IConfigManagerHost, ISecurityProvider, IColorableTile
|
||||
{
|
||||
|
||||
private static int difference = 0;
|
||||
public final AppEngInternalInventory configSlot = new AppEngInternalInventory( this, 1 );
|
||||
private final IConfigManager cm = new ConfigManager( this );
|
||||
|
||||
private final SecurityInventory inventory = new SecurityInventory( this );
|
||||
private final MEMonitorHandler<IAEItemStack> securityMonitor = new MEMonitorHandler<IAEItemStack>( this.inventory );
|
||||
|
||||
public long securityKey;
|
||||
AEColor paintedColor = AEColor.Transparent;
|
||||
private boolean isActive = false;
|
||||
|
||||
AEColor paintedColor = AEColor.Transparent;
|
||||
public long securityKey;
|
||||
public TileSecurity()
|
||||
{
|
||||
this.gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.gridProxy.setIdlePowerUsage( 2.0 );
|
||||
difference++;
|
||||
|
||||
public final AppEngInternalInventory configSlot = new AppEngInternalInventory( this, 1 );
|
||||
this.securityKey = System.currentTimeMillis() * 10 + difference;
|
||||
if( difference > 10 )
|
||||
difference = 0;
|
||||
|
||||
this.cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
this.cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
this.cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
public void getDrops( World w, int x, int y, int z, ArrayList<ItemStack> drops )
|
||||
{
|
||||
if ( !this.configSlot.isEmpty() )
|
||||
if( !this.configSlot.isEmpty() )
|
||||
drops.add( this.configSlot.getStackInSlot( 0 ) );
|
||||
|
||||
for (IAEItemStack ais : this.inventory.storedItems)
|
||||
for( IAEItemStack ais : this.inventory.storedItems )
|
||||
drops.add( ais.getItemStack() );
|
||||
}
|
||||
|
||||
@@ -114,35 +126,8 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
return this.inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
super.onReady();
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
this.isActive = true;
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Register ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
super.onChunkUnload();
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) );
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
super.invalidate();
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) );
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileSecurity(ByteBuf data)
|
||||
@TileEvent( TileEventType.NETWORK_READ )
|
||||
public boolean readFromStream_TileSecurity( ByteBuf data )
|
||||
{
|
||||
boolean wasActive = this.isActive;
|
||||
this.isActive = data.readBoolean();
|
||||
@@ -153,15 +138,15 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
return oldPaintedColor != this.paintedColor || wasActive != this.isActive;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileSecurity(ByteBuf data)
|
||||
@TileEvent( TileEventType.NETWORK_WRITE )
|
||||
public void writeToStream_TileSecurity( ByteBuf data )
|
||||
{
|
||||
data.writeBoolean( this.gridProxy.isActive() );
|
||||
data.writeByte( this.paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileSecurity(NBTTagCompound data)
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_TileSecurity( NBTTagCompound data )
|
||||
{
|
||||
this.cm.writeToNBT( data );
|
||||
data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() );
|
||||
@@ -172,7 +157,7 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
NBTTagCompound storedItems = new NBTTagCompound();
|
||||
|
||||
int offset = 0;
|
||||
for (IAEItemStack ais : this.inventory.storedItems)
|
||||
for( IAEItemStack ais : this.inventory.storedItems )
|
||||
{
|
||||
NBTTagCompound it = new NBTTagCompound();
|
||||
ais.getItemStack().writeToNBT( it );
|
||||
@@ -183,21 +168,21 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
data.setTag( "storedItems", storedItems );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileSecurity(NBTTagCompound data)
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_TileSecurity( NBTTagCompound data )
|
||||
{
|
||||
this.cm.readFromNBT( data );
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
if( data.hasKey( "paintedColor" ) )
|
||||
this.paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
|
||||
this.securityKey = data.getLong( "securityKey" );
|
||||
this.configSlot.readFromNBT( data, "config" );
|
||||
|
||||
NBTTagCompound storedItems = data.getCompoundTag( "storedItems" );
|
||||
for (Object key : storedItems.func_150296_c())
|
||||
for( Object key : storedItems.func_150296_c() )
|
||||
{
|
||||
NBTBase obj = storedItems.getTag( (String) key );
|
||||
if ( obj instanceof NBTTagCompound )
|
||||
if( obj instanceof NBTTagCompound )
|
||||
{
|
||||
this.inventory.storedItems.add( AEItemStack.create( ItemStack.loadItemStackFromNBT( (NBTTagCompound) obj ) ) );
|
||||
}
|
||||
@@ -211,77 +196,57 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
this.saveChanges();
|
||||
this.gridProxy.getGrid().postEvent( new MENetworkSecurityChange() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPermissions(HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms)
|
||||
{
|
||||
IPlayerRegistry pr = AEApi.instance().registries().players();
|
||||
|
||||
// read permissions
|
||||
for (IAEItemStack ais : this.inventory.storedItems)
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
Item i = is.getItem();
|
||||
if ( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
bc.registerPermissions( new PlayerSecurityWrapper( playerPerms ), pr, is );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure thea admin is Boss.
|
||||
playerPerms.put( this.gridProxy.getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void bootUpdate(MENetworkChannelsChanged changed)
|
||||
public void bootUpdate( MENetworkChannelsChanged changed )
|
||||
{
|
||||
this.markForUpdate();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void powerUpdate(MENetworkPowerStatusChange changed)
|
||||
public void powerUpdate( MENetworkPowerStatusChange changed )
|
||||
{
|
||||
this.markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecurityEnabled()
|
||||
{
|
||||
return this.isActive && this.gridProxy.isActive();
|
||||
}
|
||||
|
||||
public TileSecurity() {
|
||||
this.gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.gridProxy.setIdlePowerUsage( 2.0 );
|
||||
difference++;
|
||||
|
||||
this.securityKey = System.currentTimeMillis() * 10 + difference;
|
||||
if ( difference > 10 )
|
||||
difference = 0;
|
||||
|
||||
this.cm.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
||||
this.cm.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
||||
this.cm.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwner()
|
||||
{
|
||||
return this.gridProxy.getNode().getPlayerID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
public AECableType getCableConnectionType( ForgeDirection dir )
|
||||
{
|
||||
return AECableType.SMART;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
super.onChunkUnload();
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) );
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
super.onReady();
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
this.isActive = true;
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Register ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
super.invalidate();
|
||||
MinecraftForge.EVENT_BUS.post( new LocatableEventAnnounce( this, LocatableEvent.Unregister ) );
|
||||
this.isActive = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
@@ -323,7 +288,7 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -334,6 +299,39 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
return this.securityKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readPermissions( HashMap<Integer, EnumSet<SecurityPermissions>> playerPerms )
|
||||
{
|
||||
IPlayerRegistry pr = AEApi.instance().registries().players();
|
||||
|
||||
// read permissions
|
||||
for( IAEItemStack ais : this.inventory.storedItems )
|
||||
{
|
||||
ItemStack is = ais.getItemStack();
|
||||
Item i = is.getItem();
|
||||
if( i instanceof IBiometricCard )
|
||||
{
|
||||
IBiometricCard bc = (IBiometricCard) i;
|
||||
bc.registerPermissions( new PlayerSecurityWrapper( playerPerms ), pr, is );
|
||||
}
|
||||
}
|
||||
|
||||
// make sure thea admin is Boss.
|
||||
playerPerms.put( this.gridProxy.getNode().getPlayerID(), EnumSet.allOf( SecurityPermissions.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSecurityEnabled()
|
||||
{
|
||||
return this.isActive && this.gridProxy.isActive();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOwner()
|
||||
{
|
||||
return this.gridProxy.getNode().getPlayerID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AEColor getColor()
|
||||
{
|
||||
@@ -341,9 +339,9 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who)
|
||||
public boolean recolourBlock( ForgeDirection side, AEColor newPaintedColor, EntityPlayer who )
|
||||
{
|
||||
if ( this.paintedColor == newPaintedColor )
|
||||
if( this.paintedColor == newPaintedColor )
|
||||
return false;
|
||||
|
||||
this.paintedColor = newPaintedColor;
|
||||
@@ -351,5 +349,4 @@ public class TileSecurity extends AENetworkTile implements ITerminalHost, IAEApp
|
||||
this.markForUpdate();
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user