2013-12-27 23:59:59 +01:00
|
|
|
package appeng.me.storage;
|
|
|
|
|
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.IncludeExclude;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.IMEInventoryHandler;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
|
|
|
import appeng.api.storage.StorageChannel;
|
|
|
|
import appeng.api.storage.data.IAEStack;
|
|
|
|
import appeng.api.storage.data.IItemList;
|
|
|
|
import appeng.util.prioitylist.DefaultPriorityList;
|
|
|
|
import appeng.util.prioitylist.IPartitionList;
|
|
|
|
|
|
|
|
public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHandler<T>
|
|
|
|
{
|
2014-06-20 09:10:02 +02:00
|
|
|
|
2014-07-23 21:11:12 +02:00
|
|
|
final StorageChannel channel;
|
2013-12-27 23:59:59 +01:00
|
|
|
final protected IMEMonitor<T> monitor;
|
|
|
|
final protected IMEInventoryHandler<T> internal;
|
|
|
|
|
|
|
|
public int myPriority = 0;
|
|
|
|
public IncludeExclude myWhitelist = IncludeExclude.WHITELIST;
|
|
|
|
public AccessRestriction myAccess = AccessRestriction.READ_WRITE;
|
2014-02-21 21:36:40 +01:00
|
|
|
public IPartitionList<T> myPartitionList = new DefaultPriorityList<T>();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-07-24 06:20:16 +02:00
|
|
|
public MEInventoryHandler(IMEInventory<T> i, StorageChannel channel) {
|
2014-07-23 21:11:12 +02:00
|
|
|
this.channel = channel;
|
2014-06-20 09:10:02 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( i instanceof IMEInventoryHandler )
|
|
|
|
internal = (IMEInventoryHandler<T>) i;
|
|
|
|
else
|
2014-07-24 06:20:16 +02:00
|
|
|
internal = new MEPassthru<T>( i, channel );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
monitor = internal instanceof IMEMonitor ? (IMEMonitor<T>) internal : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public T injectItems(T input, Actionable type, BaseActionSource src)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( !this.canAccept( input ) )
|
|
|
|
return input;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
return internal.injectItems( input, type, src );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public T extractItems(T request, Actionable type, BaseActionSource src)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-26 07:48:09 +01:00
|
|
|
if ( !getAccess().hasPermission( AccessRestriction.READ ) )
|
|
|
|
return null;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
return internal.extractItems( request, type, src );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-21 21:36:40 +01:00
|
|
|
public IItemList<T> getAvailableItems(IItemList<T> out)
|
2014-01-26 07:48:09 +01:00
|
|
|
{
|
|
|
|
if ( !getAccess().hasPermission( AccessRestriction.READ ) )
|
|
|
|
return out;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return internal.getAvailableItems( out );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public StorageChannel getChannel()
|
|
|
|
{
|
|
|
|
return internal.getChannel();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AccessRestriction getAccess()
|
|
|
|
{
|
|
|
|
return myAccess.restrictPermissions( internal.getAccess() );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPrioritized(T input)
|
|
|
|
{
|
|
|
|
if ( myWhitelist == IncludeExclude.WHITELIST )
|
|
|
|
return myPartitionList.isListed( input ) || internal.isPrioritized( input );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAccept(T input)
|
|
|
|
{
|
2014-01-26 07:48:09 +01:00
|
|
|
if ( !getAccess().hasPermission( AccessRestriction.WRITE ) )
|
|
|
|
return false;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( myWhitelist == IncludeExclude.BLACKLIST && myPartitionList.isListed( input ) )
|
|
|
|
return false;
|
|
|
|
if ( myPartitionList.isEmpty() || myWhitelist == IncludeExclude.BLACKLIST )
|
|
|
|
return internal.canAccept( input );
|
|
|
|
return myPartitionList.isListed( input ) && internal.canAccept( input );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
|
|
|
return myPriority;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getSlot()
|
|
|
|
{
|
|
|
|
return internal.getSlot();
|
|
|
|
}
|
|
|
|
|
2014-02-21 21:36:40 +01:00
|
|
|
public IMEInventory<T> getInternal()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
return internal;
|
|
|
|
}
|
|
|
|
|
2014-06-20 09:10:02 +02:00
|
|
|
@Override
|
|
|
|
public boolean validForPass(int i)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|