当前位置: 首页>>代码示例>>Java>>正文


Java SlotTransaction类代码示例

本文整理汇总了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);
            }
        }
    }
}
 
开发者ID:ichorpowered,项目名称:latch,代码行数:26,代码来源:InteractBlockListener.java

示例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();
}
 
开发者ID:simon816,项目名称:Industrialization,代码行数:24,代码来源:TileAutoCrafting.java

示例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);
}
 
开发者ID:BadgeUp,项目名称:badgeup-sponge-client,代码行数:18,代码来源:GeneralEventListener.java

示例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;
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:ArmorQuickEquipInteractionBehavior.java

示例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));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:25,代码来源:AbstractInventorySlot.java

示例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);
        }
    }
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:18,代码来源:VanillaContainerInteractionBehavior.java

示例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));
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:27,代码来源:AbstractChildrenInventory.java

示例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());
			}
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:18,代码来源:BlacklistListener.java

示例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());
			}
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:18,代码来源:BlacklistListener.java

示例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());
			}
		}
	}
}
 
开发者ID:hsyyid,项目名称:EssentialCmds,代码行数:18,代码来源:BlacklistListener.java

示例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);
			}
		}
	}
}
 
开发者ID:NeumimTo,项目名称:NT-RPG,代码行数:25,代码来源:InventoryListener.java

示例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;
}
 
开发者ID:Monospark,项目名称:ActionControl,代码行数:18,代码来源:CraftRule.java

示例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);
}
 
开发者ID:Monospark,项目名称:ActionControl,代码行数:23,代码来源:CraftRule.java

示例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);
        }
    });
}
 
开发者ID:ustc-zzzz,项目名称:VirtualChest,代码行数:32,代码来源:VirtualChestInventory.java

示例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;
        }
    }
}
 
开发者ID:MylesIsCool,项目名称:ViaVersion,代码行数:11,代码来源:Sponge5ArmorListener.java


注:本文中的org.spongepowered.api.item.inventory.transaction.SlotTransaction类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。