mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-12 02:11:36 +01:00
Rename FillOption to TransactionOption
This commit is contained in:
parent
1100aa98a5
commit
ecb77fc847
@ -53,11 +53,11 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
/**
|
||||
* Adds an {@link ItemStack} to the inventory and sends relevant update to the viewer(s).
|
||||
*
|
||||
* @param itemStack the item to add
|
||||
* @param fillOption the filling option
|
||||
* @param itemStack the item to add
|
||||
* @param transactionOption the transaction option
|
||||
* @return true if the item has been successfully added, false otherwise
|
||||
*/
|
||||
public synchronized <T> @NotNull T addItemStack(@NotNull ItemStack itemStack, @NotNull FillOption<T> fillOption) {
|
||||
public synchronized <T> @NotNull T addItemStack(@NotNull ItemStack itemStack, @NotNull TransactionOption<T> transactionOption) {
|
||||
Int2ObjectMap<ItemStack> itemChangesMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
final StackingRule stackingRule = itemStack.getStackingRule();
|
||||
@ -99,25 +99,25 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
break;
|
||||
}
|
||||
|
||||
return fillOption.fill(this, itemStack, itemChangesMap);
|
||||
return transactionOption.fill(this, itemStack, itemChangesMap);
|
||||
}
|
||||
|
||||
public synchronized boolean addItemStack(@NotNull ItemStack itemStack) {
|
||||
return addItemStack(itemStack, FillOption.ALL_OR_NOTHING);
|
||||
return addItemStack(itemStack, TransactionOption.ALL_OR_NOTHING);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds {@link ItemStack}s to the inventory and sends relevant updates to the viewer(s).
|
||||
*
|
||||
* @param itemStacks items to add
|
||||
* @param fillOption the filling option
|
||||
* @param itemStacks items to add
|
||||
* @param transactionOption the transaction option
|
||||
* @return the operation results
|
||||
*/
|
||||
public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull FillOption<T> fillOption) {
|
||||
public <T> @NotNull List<@NotNull T> addItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull TransactionOption<T> transactionOption) {
|
||||
List<T> result = new ArrayList<>(itemStacks.size());
|
||||
itemStacks.forEach(itemStack -> {
|
||||
T fillResult = addItemStack(itemStack, fillOption);
|
||||
result.add(fillResult);
|
||||
T transactionResult = addItemStack(itemStack, transactionOption);
|
||||
result.add(transactionResult);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
@ -128,7 +128,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
* @param itemStack the item to take
|
||||
* @return true if the item has been successfully fully taken, false otherwise
|
||||
*/
|
||||
public <T> T takeItemStack(@NotNull ItemStack itemStack, @NotNull FillOption<T> fillOption) {
|
||||
public <T> T takeItemStack(@NotNull ItemStack itemStack, @NotNull TransactionOption<T> transactionOption) {
|
||||
Int2ObjectMap<ItemStack> itemChangesMap = new Int2ObjectOpenHashMap<>();
|
||||
final StackingRule stackingRule = itemStack.getStackingRule();
|
||||
for (int i = 0; i < getInnerSize(); i++) {
|
||||
@ -153,7 +153,7 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
}
|
||||
}
|
||||
|
||||
return fillOption.fill(this, itemStack, itemChangesMap);
|
||||
return transactionOption.fill(this, itemStack, itemChangesMap);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,11 +162,11 @@ public abstract class AbstractInventory implements InventoryClickHandler, DataCo
|
||||
* @param itemStacks items to take
|
||||
* @return the operation results
|
||||
*/
|
||||
public <T> @NotNull List<T> takeItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull FillOption<T> fillOption) {
|
||||
public <T> @NotNull List<T> takeItemStacks(@NotNull List<ItemStack> itemStacks, @NotNull TransactionOption<T> transactionOption) {
|
||||
List<T> result = new ArrayList<>(itemStacks.size());
|
||||
itemStacks.forEach(itemStack -> {
|
||||
T fillResult = takeItemStack(itemStack, fillOption);
|
||||
result.add(fillResult);
|
||||
T transactionResult = takeItemStack(itemStack, transactionOption);
|
||||
result.add(transactionResult);
|
||||
});
|
||||
return result;
|
||||
}
|
||||
|
@ -6,14 +6,14 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Map;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface FillOption<T> {
|
||||
public interface TransactionOption<T> {
|
||||
|
||||
/**
|
||||
* Place as much as the item as possible.
|
||||
* <p>
|
||||
* The remaining, can be air.
|
||||
*/
|
||||
FillOption<@NotNull ItemStack> ALL = (inventory, result, itemChangesMap) -> {
|
||||
TransactionOption<@NotNull ItemStack> ALL = (inventory, result, itemChangesMap) -> {
|
||||
itemChangesMap.forEach(inventory::safeItemInsert);
|
||||
return result;
|
||||
};
|
||||
@ -23,7 +23,7 @@ public interface FillOption<T> {
|
||||
* <p>
|
||||
* Returns true if the item has been added, false if nothing changed.
|
||||
*/
|
||||
FillOption<@NotNull Boolean> ALL_OR_NOTHING = (inventory, result, itemChangesMap) -> {
|
||||
TransactionOption<@NotNull Boolean> ALL_OR_NOTHING = (inventory, result, itemChangesMap) -> {
|
||||
if (result.isAir()) {
|
||||
// Item can be fully placed inside the inventory, do so
|
||||
itemChangesMap.forEach(inventory::safeItemInsert);
|
||||
@ -39,7 +39,7 @@ public interface FillOption<T> {
|
||||
* <p>
|
||||
* Returns true if the item can be fully added, false otherwise.
|
||||
*/
|
||||
FillOption<@NotNull Boolean> DRY_RUN = (inventory, result, itemChangesMap) -> result.isAir();
|
||||
TransactionOption<@NotNull Boolean> DRY_RUN = (inventory, result, itemChangesMap) -> result.isAir();
|
||||
|
||||
@NotNull T fill(@NotNull AbstractInventory inventory,
|
||||
@NotNull ItemStack result,
|
@ -4,7 +4,7 @@ import net.kyori.adventure.text.Component;
|
||||
import net.minestom.server.command.builder.Command;
|
||||
import net.minestom.server.entity.Entity;
|
||||
import net.minestom.server.entity.Player;
|
||||
import net.minestom.server.inventory.FillOption;
|
||||
import net.minestom.server.inventory.TransactionOption;
|
||||
import net.minestom.server.item.ItemStack;
|
||||
import net.minestom.server.utils.entity.EntityFinder;
|
||||
|
||||
@ -44,7 +44,7 @@ public class GiveCommand extends Command {
|
||||
for (Entity target : targets) {
|
||||
if (target instanceof Player) {
|
||||
Player player = (Player) target;
|
||||
player.getInventory().addItemStacks(itemStacks, FillOption.ALL);
|
||||
player.getInventory().addItemStacks(itemStacks, TransactionOption.ALL);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user