Refactored the BaseActionSource (#3063)
* Refactored the BaseActionSource It now uses an interface `IActionSource` instead of a concrete class and further subclasses. Instead of relying on a specific class for a certain action type, it now uses methods with Optional as return values to determine a player or machine issuing an action. Refer to the JavaDocs for the exact behaviour. * `IActionHost` no longer extends `IGridHost` It never used the additional functionality and if needed the `IGridNode` will also provide a reference to the corresponding `IGridHost`. Due to most crafting related GUIs being hardcoded to `IGridHost`, they no longer work when `IActionHost` is not extending it. Actually `IActionHost` is the better solution for it, as it prevents us from looking the grid up via the `IGridHost` and potentially finding a wrong grid. * Interfaces now only lock the currently worked slot. This allows `DualityInterface#onChangeInventory` to update slots of the same interface, should they be the source for a requested item and therefore updating their working set accordingly to queue further crafting requests for unfulfilled stack requirements.
This commit is contained in:
@@ -33,7 +33,7 @@ import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.exceptions.AppEngException;
|
||||
import appeng.api.implementations.items.IStorageCell;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.ICellInventory;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
@@ -202,7 +202,7 @@ public class CellInventory implements ICellInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final BaseActionSource src )
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( input == null )
|
||||
{
|
||||
@@ -299,7 +299,7 @@ public class CellInventory implements ICellInventory
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src )
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( request == null )
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
@@ -58,7 +58,7 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final BaseActionSource src )
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
final IAEItemStack local = this.itemListCache.findPrecise( input );
|
||||
if( local == null )
|
||||
@@ -70,7 +70,7 @@ public class CreativeCellInventory implements IMEInventoryHandler<IAEItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src )
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
final IAEItemStack local = this.itemListCache.findPrecise( request );
|
||||
if( local == null )
|
||||
|
||||
@@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.ICellHandler;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -46,7 +46,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable type, final BaseActionSource src )
|
||||
public T injectItems( final T input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
final long size = input.getStackSize();
|
||||
|
||||
@@ -67,7 +67,7 @@ public class DriveWatcher<T extends IAEStack<T>> extends MEInventoryHandler<T>
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable type, final BaseActionSource src )
|
||||
public T extractItems( final T request, final Actionable type, final IActionSource src )
|
||||
{
|
||||
final T a = super.extractItems( request, type, src );
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
package appeng.me.storage;
|
||||
|
||||
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
|
||||
|
||||
@@ -28,6 +28,6 @@ public interface ITickingMonitor
|
||||
|
||||
TickRateModulation onTick();
|
||||
|
||||
void setActionSource( BaseActionSource actionSource );
|
||||
void setActionSource( IActionSource actionSource );
|
||||
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ package appeng.me.storage;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.IncludeExclude;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
@@ -96,7 +96,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable type, final BaseActionSource src )
|
||||
public T injectItems( final T input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( !this.canAccept( input ) )
|
||||
{
|
||||
@@ -107,7 +107,7 @@ public class MEInventoryHandler<T extends IAEStack<T>> implements IMEInventoryHa
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable type, final BaseActionSource src )
|
||||
public T extractItems( final T request, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( !this.hasReadAccess )
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.StorageFilter;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
||||
@@ -51,7 +51,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
|
||||
private final IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
private final HashMap<IMEMonitorHandlerReceiver<IAEItemStack>, Object> listeners = new HashMap<>();
|
||||
private final NavigableMap<Integer, CachedItemStack> memory;
|
||||
private BaseActionSource mySource;
|
||||
private IActionSource mySource;
|
||||
private StorageFilter mode = StorageFilter.EXTRACTABLE_ONLY;
|
||||
|
||||
public MEMonitorIInventory( final InventoryAdaptor adaptor )
|
||||
@@ -73,7 +73,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final BaseActionSource src )
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
ItemStack out = ItemStack.EMPTY;
|
||||
|
||||
@@ -103,7 +103,7 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable type, final BaseActionSource src )
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable type, final IActionSource src )
|
||||
{
|
||||
ItemStack out = ItemStack.EMPTY;
|
||||
|
||||
@@ -325,13 +325,13 @@ public class MEMonitorIInventory implements IMEMonitor<IAEItemStack>, ITickingMo
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
private BaseActionSource getActionSource()
|
||||
private IActionSource getActionSource()
|
||||
{
|
||||
return this.mySource;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActionSource( final BaseActionSource mySource )
|
||||
public void setActionSource( final IActionSource mySource )
|
||||
{
|
||||
this.mySource = mySource;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.storage.IBaseMonitor;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
@@ -39,7 +39,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
{
|
||||
|
||||
private final HashMap<IMEMonitorHandlerReceiver<T>, Object> listeners = new HashMap<>();
|
||||
private BaseActionSource changeSource;
|
||||
private IActionSource changeSource;
|
||||
private IMEMonitor<T> monitor;
|
||||
|
||||
public MEMonitorPassThrough( final IMEInventory<T> i, final StorageChannel channel )
|
||||
@@ -118,7 +118,7 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final BaseActionSource source )
|
||||
public void postChange( final IBaseMonitor<T> monitor, final Iterable<T> change, final IActionSource source )
|
||||
{
|
||||
final Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = this.listeners.entrySet().iterator();
|
||||
while( i.hasNext() )
|
||||
@@ -155,12 +155,12 @@ public class MEMonitorPassThrough<T extends IAEStack<T>> extends MEPassThrough<T
|
||||
}
|
||||
}
|
||||
|
||||
private BaseActionSource getChangeSource()
|
||||
private IActionSource getChangeSource()
|
||||
{
|
||||
return this.changeSource;
|
||||
}
|
||||
|
||||
public void setChangeSource( final BaseActionSource changeSource )
|
||||
public void setChangeSource( final IActionSource changeSource )
|
||||
{
|
||||
this.changeSource = changeSource;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ package appeng.me.storage;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
@@ -52,13 +52,13 @@ public class MEPassThrough<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable type, final BaseActionSource src )
|
||||
public T injectItems( final T input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
return this.internal.injectItems( input, type, src );
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable type, final BaseActionSource src )
|
||||
public T extractItems( final T request, final Actionable type, final IActionSource src )
|
||||
{
|
||||
return this.internal.extractItems( request, type, src );
|
||||
}
|
||||
|
||||
@@ -32,10 +32,8 @@ import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.networking.security.ISecurityGrid;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -77,7 +75,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public T injectItems( T input, final Actionable type, final BaseActionSource src )
|
||||
public T injectItems( T input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( this.diveList( this, type ) )
|
||||
{
|
||||
@@ -137,20 +135,20 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean testPermission( final BaseActionSource src, final SecurityPermissions permission )
|
||||
private boolean testPermission( final IActionSource src, final SecurityPermissions permission )
|
||||
{
|
||||
if( src.isPlayer() )
|
||||
if( src.player().isPresent() )
|
||||
{
|
||||
if( !this.security.hasPermission( ( (PlayerSource) src ).player, permission ) )
|
||||
if( !this.security.hasPermission( src.player().get(), permission ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if( src.isMachine() )
|
||||
else if( src.machine().isPresent() )
|
||||
{
|
||||
if( this.security.isAvailable() )
|
||||
{
|
||||
final IGridNode n = ( (MachineSource) src ).via.getActionableNode();
|
||||
final IGridNode n = src.machine().get().getActionableNode();
|
||||
if( n == null )
|
||||
{
|
||||
return true;
|
||||
@@ -197,7 +195,7 @@ public class NetworkInventoryHandler<T extends IAEStack<T>> implements IMEInvent
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( T request, final Actionable mode, final BaseActionSource src )
|
||||
public T extractItems( T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( this.diveList( this, mode ) )
|
||||
{
|
||||
|
||||
@@ -21,7 +21,7 @@ package appeng.me.storage;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
@@ -32,13 +32,13 @@ public class NullInventory<T extends IAEStack<T>> implements IMEInventoryHandler
|
||||
{
|
||||
|
||||
@Override
|
||||
public T injectItems( final T input, final Actionable mode, final BaseActionSource src )
|
||||
public T injectItems( final T input, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
return input;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T extractItems( final T request, final Actionable mode, final BaseActionSource src )
|
||||
public T extractItems( final T request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -26,8 +26,7 @@ import appeng.api.config.AccessRestriction;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.implementations.items.IBiometricCard;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.networking.security.PlayerSource;
|
||||
import appeng.api.networking.security.IActionSource;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.StorageChannel;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
@@ -48,7 +47,7 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final BaseActionSource src )
|
||||
public IAEItemStack injectItems( final IAEItemStack input, final Actionable type, final IActionSource src )
|
||||
{
|
||||
if( this.hasPermission( src ) )
|
||||
{
|
||||
@@ -70,13 +69,13 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
||||
return input;
|
||||
}
|
||||
|
||||
private boolean hasPermission( final BaseActionSource src )
|
||||
private boolean hasPermission( final IActionSource src )
|
||||
{
|
||||
if( src.isPlayer() )
|
||||
if( src.player().isPresent() )
|
||||
{
|
||||
try
|
||||
{
|
||||
return this.securityTile.getProxy().getSecurity().hasPermission( ( (PlayerSource) src ).player, SecurityPermissions.SECURITY );
|
||||
return this.securityTile.getProxy().getSecurity().hasPermission( src.player().get(), SecurityPermissions.SECURITY );
|
||||
}
|
||||
catch( final GridAccessException e )
|
||||
{
|
||||
@@ -87,7 +86,7 @@ public class SecurityStationInventory implements IMEInventoryHandler<IAEItemStac
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final BaseActionSource src )
|
||||
public IAEItemStack extractItems( final IAEItemStack request, final Actionable mode, final IActionSource src )
|
||||
{
|
||||
if( this.hasPermission( src ) )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user