970630a90d
* 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.
77 lines
2.5 KiB
Java
77 lines
2.5 KiB
Java
/*
|
|
* The MIT License (MIT)
|
|
*
|
|
* Copyright (c) 2013 AlgorithmX2
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
* the Software without restriction, including without limitation the rights to
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
* subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
* copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
*/
|
|
|
|
package appeng.api.networking.security;
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
import javax.annotation.Nonnull;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
|
/**
|
|
* 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 interface IActionSource
|
|
{
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
@Nonnull
|
|
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.
|
|
*/
|
|
@Nonnull
|
|
Optional<IActionHost> machine();
|
|
|
|
/**
|
|
* An {@link IActionSource} can have multiple optional contexts.
|
|
*
|
|
* It is strongly recommended to limit the uses for absolutely necessary cases.
|
|
*
|
|
* Currently there are no public contexts made available by AE.
|
|
* An example would be the context interfaces use internally to avoid looping items between each other.
|
|
*/
|
|
@Nonnull
|
|
<T> Optional<T> context( @Nonnull Class<T> key );
|
|
} |