Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored the BaseActionSource #3063

Merged
merged 8 commits into from Sep 12, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/api/java/appeng/api/networking/crafting/ICraftingCPU.java
Expand Up @@ -24,7 +24,7 @@
package appeng.api.networking.crafting;


import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.data.IAEItemStack;

Expand All @@ -40,7 +40,7 @@ public interface ICraftingCPU extends IBaseMonitor<IAEItemStack>
/**
* @return the action source for the CPU.
*/
BaseActionSource getActionSource();
IActionSource getActionSource();

/**
* @return the available storage in bytes
Expand Down
Expand Up @@ -33,7 +33,7 @@

import appeng.api.networking.IGrid;
import appeng.api.networking.IGridCache;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEItemStack;


Expand Down Expand Up @@ -63,7 +63,7 @@ public interface ICraftingGrid extends IGridCache
* @return a future which will at an undetermined point in the future get you the {@link ICraftingJob} do not wait
* on this, your be waiting forever.
*/
Future<ICraftingJob> beginCraftingJob( World world, IGrid grid, BaseActionSource actionSrc, IAEItemStack craftWhat, ICraftingCallback callback );
Future<ICraftingJob> beginCraftingJob( World world, IGrid grid, IActionSource actionSrc, IAEItemStack craftWhat, ICraftingCallback callback );

/**
* Submit the job to the Crafting system for processing.
Expand All @@ -82,7 +82,7 @@ public interface ICraftingGrid extends IGridCache
* {@link ICraftingRequester} methods. if you send null, this object should be discarded after verifying the
* return state.
*/
ICraftingLink submitJob( ICraftingJob job, ICraftingRequester requestingMachine, ICraftingCPU target, boolean prioritizePower, BaseActionSource src );
ICraftingLink submitJob( ICraftingJob job, ICraftingRequester requestingMachine, ICraftingCPU target, boolean prioritizePower, IActionSource src );

/**
* @return list of all the crafting cpus on the grid
Expand Down
41 changes: 0 additions & 41 deletions src/api/java/appeng/api/networking/security/BaseActionSource.java

This file was deleted.

3 changes: 1 addition & 2 deletions src/api/java/appeng/api/networking/security/IActionHost.java
Expand Up @@ -24,11 +24,10 @@
package appeng.api.networking.security;


import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;


public interface IActionHost extends IGridHost
public interface IActionHost
{

/**
Expand Down
Expand Up @@ -24,26 +24,50 @@
package appeng.api.networking.security;


import java.util.Optional;

import net.minecraft.entity.player.EntityPlayer;


/**
* TODO: Consider refactoring.
* The source of any action.
*
* This can either be a {@link EntityPlayer} or an {@link IActionHost}.
*
* In most cases this is used for security checks, but can be used to validate the source itself.
*
*/
public class PlayerSource extends BaseActionSource
public interface IActionSource
{

public final EntityPlayer player;
public final IActionHost via;

public PlayerSource( final EntityPlayer p, final IActionHost v )
{
this.player = p;
this.via = v;
}

@Override
public boolean isPlayer()
{
return true;
}
}
/**
* If present, AE will consider the player being the source for the action.
*
* This will take precedence over {@link IActionSource#machine()} in any case.
*
* @return An optional player issuing the action.
*/
Optional<EntityPlayer> player();

/**
* If present, it indicates the {@link IActionHost} of the source.
*
* Should {@link IActionSource#player()} be absent, it will consider a machine as source.
*
* It is recommended to include the machine even when a player is present.
*
* @return An optional machine issuing the action or acting as proxy for a player.
*/
Optional<IActionHost> machine();

/**
* An optional priority.
*
* This is usually only valid in the context of a similar {@link IActionHost}.
*
* An applicable use case is to prevent ME interfaces stealing items from other ME interfaces with the same or a
* higher priority.
*/
Optional<Integer> priority();

}
44 changes: 0 additions & 44 deletions src/api/java/appeng/api/networking/security/MachineSource.java

This file was deleted.

Expand Up @@ -24,7 +24,7 @@
package appeng.api.networking.storage;


import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.StorageChannel;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
Expand All @@ -50,5 +50,5 @@ public interface IStackWatcherHost
* @param src action source
* @param chan storage channel
*/
void onStackChange( IItemList o, IAEStack fullStack, IAEStack diffStack, BaseActionSource src, StorageChannel chan );
void onStackChange( IItemList o, IAEStack fullStack, IAEStack diffStack, IActionSource src, StorageChannel chan );
}
4 changes: 2 additions & 2 deletions src/api/java/appeng/api/networking/storage/IStorageGrid.java
Expand Up @@ -26,7 +26,7 @@

import appeng.api.networking.IGridCache;
import appeng.api.networking.IGridHost;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.ICellContainer;
import appeng.api.storage.ICellProvider;
import appeng.api.storage.IStorageMonitorable;
Expand All @@ -50,7 +50,7 @@ public interface IStorageGrid extends IGridCache, IStorageMonitorable
*
* @param input injected items
*/
void postAlterationOfStoredItems( StorageChannel chan, Iterable<? extends IAEStack> input, BaseActionSource src );
void postAlterationOfStoredItems( StorageChannel chan, Iterable<? extends IAEStack> input, IActionSource src );

/**
* Used to add a cell provider to the storage system
Expand Down
6 changes: 3 additions & 3 deletions src/api/java/appeng/api/storage/IMEInventory.java
Expand Up @@ -25,7 +25,7 @@


import appeng.api.config.Actionable;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;

Expand All @@ -52,7 +52,7 @@ public interface IMEInventory<StackType extends IAEStack>
*
* @return returns the number of items not added.
*/
StackType injectItems( StackType input, Actionable type, BaseActionSource src );
StackType injectItems( StackType input, Actionable type, IActionSource src );

/**
* Extract the specified item from the ME Inventory
Expand All @@ -62,7 +62,7 @@ public interface IMEInventory<StackType extends IAEStack>
*
* @return returns the number of items extracted, null
*/
StackType extractItems( StackType request, Actionable mode, BaseActionSource src );
StackType extractItems( StackType request, Actionable mode, IActionSource src );

/**
* request a full report of all available items, storage.
Expand Down
Expand Up @@ -24,7 +24,7 @@
package appeng.api.storage;


import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.networking.storage.IBaseMonitor;
import appeng.api.storage.data.IAEStack;

Expand All @@ -46,7 +46,7 @@ public interface IMEMonitorHandlerReceiver<StackType extends IAEStack>
*
* @param change done change
*/
void postChange( IBaseMonitor<StackType> monitor, Iterable<StackType> change, BaseActionSource actionSource );
void postChange( IBaseMonitor<StackType> monitor, Iterable<StackType> change, IActionSource actionSource );

/**
* called when the list updates its contents, this is mostly for handling power events.
Expand Down
6 changes: 3 additions & 3 deletions src/api/java/appeng/api/storage/IStorageHelper.java
Expand Up @@ -35,7 +35,7 @@
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingRequester;
import appeng.api.networking.energy.IEnergySource;
import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;
import appeng.api.storage.data.IAEFluidStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
Expand Down Expand Up @@ -109,7 +109,7 @@ public interface IStorageHelper
*
* @return items that successfully extracted.
*/
IAEItemStack poweredExtraction( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack request, BaseActionSource src );
IAEItemStack poweredExtraction( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack request, IActionSource src );

/**
* use energy from energy, to inject input items into cell, at the request of src
Expand All @@ -121,5 +121,5 @@ public interface IStorageHelper
*
* @return items that failed to insert.
*/
IAEItemStack poweredInsert( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack input, BaseActionSource src );
IAEItemStack poweredInsert( IEnergySource energy, IMEInventory<IAEItemStack> cell, IAEItemStack input, IActionSource src );
}
Expand Up @@ -4,7 +4,7 @@

import javax.annotation.Nullable;

import appeng.api.networking.security.BaseActionSource;
import appeng.api.networking.security.IActionSource;


/**
Expand All @@ -22,5 +22,5 @@ public interface IStorageMonitorableAccessor
* @return Null if the network cannot be accessed by the given action source (i.e. security doesn't permit it).
*/
@Nullable
IStorageMonitorable getInventory( BaseActionSource src );
IStorageMonitorable getInventory( IActionSource src );
}
12 changes: 6 additions & 6 deletions src/api/java/appeng/api/storage/MEMonitorHandler.java
Expand Up @@ -32,7 +32,7 @@

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.data.IAEStack;
import appeng.api.storage.data.IItemList;

Expand Down Expand Up @@ -81,7 +81,7 @@ public void removeListener( final IMEMonitorHandlerReceiver<StackType> l )
}

@Override
public StackType injectItems( final StackType input, final Actionable mode, final BaseActionSource src )
public StackType injectItems( final StackType input, final Actionable mode, final IActionSource src )
{
if( mode == Actionable.SIMULATE )
{
Expand All @@ -95,7 +95,7 @@ protected IMEInventoryHandler<StackType> getHandler()
return this.internalHandler;
}

private StackType monitorDifference( final IAEStack original, final StackType leftOvers, final boolean extraction, final BaseActionSource src )
private StackType monitorDifference( final IAEStack original, final StackType leftOvers, final boolean extraction, final IActionSource src )
{
final StackType diff = (StackType) original.copy();

Expand All @@ -116,12 +116,12 @@ else if( leftOvers != null )
return leftOvers;
}

protected void postChangesToListeners( final Iterable<StackType> changes, final BaseActionSource src )
protected void postChangesToListeners( final Iterable<StackType> changes, final IActionSource src )
{
this.notifyListenersOfChange( changes, src );
}

protected void notifyListenersOfChange( final Iterable<StackType> diff, final BaseActionSource src )
protected void notifyListenersOfChange( final Iterable<StackType> diff, final IActionSource src )
{
this.hasChanged = true;// need to update the cache.
final Iterator<Entry<IMEMonitorHandlerReceiver<StackType>, Object>> i = this.getListeners();
Expand All @@ -146,7 +146,7 @@ protected Iterator<Entry<IMEMonitorHandlerReceiver<StackType>, Object>> getListe
}

@Override
public StackType extractItems( final StackType request, final Actionable mode, final BaseActionSource src )
public StackType extractItems( final StackType request, final Actionable mode, final IActionSource src )
{
if( mode == Actionable.SIMULATE )
{
Expand Down