本文整理汇总了Java中org.spongepowered.api.item.inventory.transaction.SlotTransaction类的典型用法代码示例。如果您正苦于以下问题:Java SlotTransaction类的具体用法?Java SlotTransaction怎么用?Java SlotTransaction使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SlotTransaction类属于org.spongepowered.api.item.inventory.transaction包,在下文中一共展示了SlotTransaction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onClickInventory
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onClickInventory(final ClickInventoryEvent event, @First Player player) {
//Make sure we have a transaction to validate
if (event.getTransactions().size() <= 0) {
return;
}
//Get the first transaction of this event
final SlotTransaction slotTransaction = event.getTransactions().get(0);
final Slot slot = slotTransaction.getSlot();
//If the player is interacting with a TileEntityCarrier
if (slot.parent() instanceof TileEntityCarrier) {
//If the final item is NONE (or amount is less) person is trying to withdraw (so we care about it)
if (slotTransaction.getFinal().getType() == ItemTypes.NONE || slotTransaction.getFinal().getCount() < slotTransaction.getOriginal().getCount()) {
//Then check to see if there's a lock
final Optional<Lock> lock = Latch.getLockManager().getLock(((TileEntityCarrier) slot.parent()).getLocation());
//If there's a donation lock the player CANNOT access
if (lock.isPresent() && lock.get().getLockType() == LockType.DONATION && !lock.get().canAccess(player.getUniqueId())) {
event.setCancelled(true);
}
}
}
}
示例2: handleOutputClick
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private void handleOutputClick(SlotTransaction slotTransaction, Transaction<ItemStackSnapshot> cursorTransaction) {
// Trying to put item in slot
if (slotTransaction.getFinal() != ItemStackSnapshot.NONE) {
if (slotTransaction.getOriginal() != cursorTransaction.getFinal()) {
System.out.println("false positive");
// False positive
return;
}
System.out.println("put item in output");
slotTransaction.setValid(false);
// TODO because Sponge is broken - set custom to original
cursorTransaction.setCustom(cursorTransaction.getOriginal());
return;
}
if (!canTakeOutput()) {
System.out.println("take output before ready");
slotTransaction.setValid(false);
cursorTransaction.setCustom(cursorTransaction.getOriginal());
return;
}
System.out.println("take output");
takeOutput();
}
示例3: pickupItem
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener(order = Order.POST)
@Exclude({ChangeInventoryEvent.Pickup.Pre.class})
public void pickupItem(ChangeInventoryEvent.Pickup event, @Root Player player) {
List<SlotTransaction> transactions = event.getTransactions();
if (transactions.isEmpty()) {
return;
}
int itemQuantity = transactions.get(0).getFinal().getQuantity() - transactions.get(0).getOriginal().getQuantity();
// Sometimes it's 0 for some odd reason
if (itemQuantity == 0) {
return;
}
processEvent(event, player, itemQuantity);
}
示例4: tryInteract
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.requireContext(ContextKeys.PLAYER);
final ItemStack itemStack = context.requireContext(ContextKeys.USED_ITEM_STACK);
final PeekedOfferTransactionResult peekResult = player.getInventory().getEquipment().peekOffer(itemStack.copy());
if (peekResult.isSuccess()) {
final List<SlotTransaction> transactions = new ArrayList<>(peekResult.getTransactions());
final AbstractSlot slot = (AbstractSlot) context.getContext(ContextKeys.USED_SLOT).orElse(null);
if (slot != null) {
transactions.add(new SlotTransaction(
slot, itemStack.createSnapshot(), LanternItemStack.toSnapshot(peekResult.getRejectedItem().orElse(null))));
}
final ChangeInventoryEvent.Equipment event = SpongeEventFactory.createChangeInventoryEventEquipment(
context.getCurrentCause(), player.getInventory(), transactions);
if (event.isCancelled()) {
return BehaviorResult.CONTINUE;
}
event.getTransactions().stream().filter(Transaction::isValid).forEach(slotTransaction ->
slotTransaction.getSlot().set(slotTransaction.getFinal().createStack()));
return BehaviorResult.SUCCESS;
}
return BehaviorResult.CONTINUE;
}
示例5: peekPoll
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Override
public Optional<PeekedPollTransactionResult> peekPoll(int limit, Predicate<ItemStack> matcher) {
checkNotNull(matcher, "matcher");
checkArgument(limit >= 0, "Limit may not be negative");
ItemStack itemStack = this.itemStack;
// There is no item available
if (limit == 0 || itemStack == null || !matcher.test(itemStack)) {
return Optional.empty();
}
final ItemStackSnapshot oldItem = itemStack.createSnapshot();
itemStack = itemStack.copy();
final int quantity = itemStack.getQuantity();
final ItemStackSnapshot newItem;
if (limit >= quantity) {
newItem = ItemStackSnapshot.NONE;
} else {
itemStack.setQuantity(quantity - limit);
newItem = LanternItemStack.toSnapshot(itemStack);
itemStack.setQuantity(limit);
}
final List<SlotTransaction> transactions = new ArrayList<>();
transactions.add(new SlotTransaction(this, oldItem, newItem));
return Optional.of(new PeekedPollTransactionResult(transactions, itemStack));
}
示例6: finishInventoryEvent
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private void finishInventoryEvent(ChangeInventoryEvent event) {
final List<SlotTransaction> slotTransactions = event.getTransactions();
Sponge.getEventManager().post(event);
if (!event.isCancelled()) {
if (!(event instanceof ClickInventoryEvent.Creative) && event instanceof ClickInventoryEvent) {
final Transaction<ItemStackSnapshot> cursorTransaction = ((ClickInventoryEvent) event).getCursorTransaction();
if (cursorTransaction.isValid()) {
setCursorItem(cursorTransaction.getFinal().createStack());
}
}
slotTransactions.stream().filter(Transaction::isValid).forEach(
transaction -> transaction.getSlot().set(transaction.getFinal().createStack()));
if (event instanceof SpawnEntityEvent) {
LanternWorld.finishSpawnEntityEvent((SpawnEntityEvent) event);
}
}
}
示例7: peekOffer
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private PeekedOfferTransactionResult peekOffer(ItemStack stack, Set<Inventory> processed, boolean add) {
PeekedOfferTransactionResult peekResult = null;
final List<SlotTransaction> transactions = new ArrayList<>();
// Loop through the slots
for (AbstractInventory inventory : getChildren()) {
if (!add && processed.contains(inventory)) {
continue;
}
peekResult = inventory.peekOffer(stack);
if (peekResult.isSuccess()) {
final Optional<ItemStack> rejectedItem = peekResult.getRejectedItem();
transactions.addAll(peekResult.getTransactions());
if (!rejectedItem.isPresent()) {
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, null);
}
stack = rejectedItem.get();
}
if (add) {
processed.add(inventory);
}
}
if (peekResult == null) {
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.FAILURE, ImmutableList.of(), stack);
}
return new PeekedOfferTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, peekResult.getRejectedItem().orElse(null));
}
示例8: onChangeHeldItem
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onChangeHeldItem(ChangeInventoryEvent.Held event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例9: onChangeEquipment
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onChangeEquipment(ChangeInventoryEvent.Equipment event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例10: onPickupItem
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onPickupItem(ChangeInventoryEvent.Pickup event, @Root Player player)
{
if (!player.hasPermission("essentialcmds.blacklist.bypass"))
{
for (SlotTransaction transaction : event.getTransactions())
{
if (Utils.getBlacklistItems().contains(transaction.getFinal().createStack().getItem().getId()))
{
if (Utils.areBlacklistMsgsEnabled())
player.sendMessage(Text.of(TextColors.RED, "The item ", TextColors.GRAY, transaction.getFinal().createStack().getItem().getId(), TextColors.RED, " has been confiscated as it is blacklisted."));
transaction.setCustom(Sponge.getRegistry().createBuilder(ItemStack.Builder.class).itemType(ItemTypes.DIRT).quantity(1).build());
}
}
}
}
示例11: onItemPickup
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onItemPickup(ChangeInventoryEvent.Pickup event, @First(typeFilter = {Player.class}) Player player) {
IActiveCharacter character = characterService.getCharacter(player.getUniqueId());
if (character.isStub()) {
return;
}
if (player.get(Keys.GAME_MODE).get() != GameModes.SURVIVAL)
return;
for (SlotTransaction slotTransaction : event.getTransactions()) {
Slot i = slotTransaction.getSlot();
int index = ((SlotAdapter) i).getOrdinal();
if (Utils.isHotbar(index)) {
ItemStack a = slotTransaction.getFinal().createStack();
if (inventoryService.canUse(a, character) != CannotUseItemReson.OK) {
event.setCancelled(true);
return;
} else {
inventoryService.initializeHotbar(character, index, a);
}
}
}
}
示例12: getConsumedItemStacks
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private Set<ItemStack> getConsumedItemStacks(List<SlotTransaction> transactions) {
Set<ItemStack> consumed = Sets.newHashSet();
for (SlotTransaction transaction : transactions) {
if (transaction.getOriginal().getType() == ItemTypes.NONE) {
continue;
}
int newCount = transaction.getFinal().getType() != ItemTypes.NONE ? transaction.getFinal().getCount() : 0;
if (newCount >= transaction.getOriginal().getCount()) {
continue;
}
int stackSize = transaction.getOriginal().getCount() - newCount;
consumed.add(createStackWithCustomQuantity(transaction.getOriginal().createStack(), stackSize));
}
return consumed;
}
示例13: getResult
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private Entry<ItemStack, Integer> getResult(List<SlotTransaction> transactions) {
ItemStack result = null;
int created = 0;
for (SlotTransaction transaction : transactions) {
if (transaction.getFinal().getType() == ItemTypes.NONE) {
continue;
}
int oldCount = transaction.getOriginal().getType() != ItemTypes.NONE
? transaction.getOriginal().getCount() : 0;
int newCount = transaction.getFinal().getCount();
if (newCount <= oldCount) {
continue;
}
if (result == null) {
result = createStackWithCustomQuantity(transaction.getFinal().createStack(), 1);
}
created += newCount - oldCount;
}
return Maps.immutableEntry(result, created);
}
示例14: fireClickEvent
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
private void fireClickEvent(ClickInventoryEvent e)
{
Optional<Player> optional = Sponge.getServer().getPlayer(playerUniqueId);
if (!optional.isPresent())
{
return;
}
Player player = optional.get();
CompletableFuture<Boolean> future = CompletableFuture.completedFuture(Boolean.TRUE);
for (SlotTransaction slotTransaction : e.getTransactions())
{
Slot slot = slotTransaction.getSlot();
SlotIndex pos = SpongeUnimplemented.getSlotOrdinal(slot);
if (SpongeUnimplemented.isSlotInInventory(slot, e.getTargetInventory()) && slotToListen.matches(pos))
{
e.setCancelled(true);
boolean allowAction = actionIntervalManager.allowAction(player, acceptableActionIntervalTick);
if (allowAction && itemsInSlots.containsKey(pos))
{
future = future.thenApplyAsync(p -> processClickEvent(e, player, pos) && p, executorService);
}
}
}
future.thenAccept(shouldKeepInventoryOpen ->
{
if (!shouldKeepInventoryOpen)
{
SpongeUnimplemented.closeInventory(player, plugin);
}
});
}
示例15: onInventoryClick
import org.spongepowered.api.item.inventory.transaction.SlotTransaction; //导入依赖的package包/类
@Listener
public void onInventoryClick(ClickInventoryEvent e, @Root Player player) {
for (SlotTransaction transaction : e.getTransactions()) {
if (ArmorType.isArmor(transaction.getFinal().getType().getId()) ||
ArmorType.isArmor(e.getCursorTransaction().getFinal().getType().getId())) {
sendDelayedArmorUpdate(player);
break;
}
}
}